-
Notifications
You must be signed in to change notification settings - Fork 0
/
fake_records.py
90 lines (77 loc) · 2.22 KB
/
fake_records.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
This module is designed to get you started with some fake records/tables
that you can write queries against for testing etc.
"""
import random
import sqlite3
import time
import config
CONN = sqlite3.connect(config.SQLITE_DB_NAME)
def fake_id():
"""
Makes a bs random id out of numbers and letters
"""
letters = [x for x in "abcdefghijklmnop"]
numbers = [x for x in "1234567890"]
id_ = ""
for _ in range(8):
id_ += random.choice(letters)
id_ += random.choice(numbers)
return id_
def fake_an_application():
"""
Creates a fake record in the applications table
"""
application_id = fake_id()
created_date = "2016-02-20"
stage = random.choice(["won", "lost"])
insert_query = """
INSERT INTO applications (application_id, createddate, stage)
VALUES (?, ?, ?)
"""
insert_data = (application_id, created_date, stage)
CONN.cursor().execute(insert_query, insert_data)
CONN.commit()
def fake_an_execution():
"""
Creates a fake record in the executions table
"""
exec_id = fake_id()
exec_ts = int(time.time())
model_name = random.choice(["credit", "industry"])
exec_result = "blahhhhh"
insert_query = """
INSERT INTO model_executions (execution_id, ts, model_name, result)
VALUES (?, ?, ?, ?)
"""
insert_data = (exec_id, exec_ts, model_name, exec_result)
CONN.cursor().execute(insert_query, insert_data)
CONN.commit()
def create_tables():
"""
Creates some fake tables.
"""
applications_creation_query = """
CREATE TABLE applications (
application_id text,
createddate text,
stage text
)
"""
model_executions_creation_query = """
CREATE TABLE model_executions (
execution_id text,
ts integer,
model_name text,
result text
)
"""
CONN.cursor().execute(applications_creation_query, ())
CONN.cursor().execute(model_executions_creation_query, ())
CONN.commit()
if __name__ == "__main__":
while True:
time.sleep(random.uniform(1, 3))
fake_an_application()
time.sleep(random.uniform(1, 3))
fake_an_execution()