-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_databases.py
91 lines (88 loc) · 2.25 KB
/
generate_databases.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
91
import sqlite3
import os
import json
#Reading columns
"""
y_columns = []
with open("columns.txt",'r') as fh:
for curline in fh:
if not curline.startswith("#"):
y_columns.append(curline.rstrip())
y_columns_string = ", ".join(y_columns)
y_column_names = list(map(lambda x: x.split(" ")[0],y_columns))
with open("children/y_column.json", "w") as f:
json.dump({"y_column_names":y_column_names},f)
with open("main_server/y_column.json", "w") as f:
json.dump({"y_column_names":y_column_names},f)
"""
#Creating children database
children_db_path = "children/database.db"
if os.path.exists(children_db_path):
os.remove(children_db_path)
conn = sqlite3.connect(children_db_path)
conn.execute("""
CREATE TABLE children (id integer primary key autoincrement,
url text not null,
IP text not null,
name text)
""")
conn.execute(f"""
CREATE TABLE bio (id integer,
batch_id integer,
timestamp datetime default current_timestamp,
chromossome_data text,
fitness real,
status integer default 0,
sync integer default 0,
foreign key(id) references children(id))
""")
conn.execute(f"""
CREATE TABLE assignment (id integer,
batch_id integer,
timestamp datetime default current_timestamp,
request_id integer primary key,
chromossome_data text,
fitness real default 0,
status integer default 0,
sync integer default 0,
foreign key(id) references children(id)
)
""")
conn.commit()
conn.close()
#Creating main_server database
children_db_path = "main_server/database.db"
if os.path.exists(children_db_path):
os.remove(children_db_path)
conn = sqlite3.connect(children_db_path)
conn.execute("""
CREATE TABLE children (id integer primary key autoincrement,
url text not null,
IP text not null,
name text)
""")
conn.execute(f"""
CREATE TABLE bio (id integer,
batch_id integer,
timestamp datetime default current_timestamp,
chromossome_data text,
fitness real,
request_id,
status integer default 0,
sync integer default 0,
foreign key(id) references children(id))
""")
conn.execute(f"""
CREATE TABLE assignment (id integer,
batch_id integer,
timestamp datetime default current_timestamp,
request_id integer primary key,
chromossome_data text,
fitness real default 0,
status integer default 0,
sync integer default 0,
foreign key(id) references children(id)
)
""")
conn.commit()
conn.close()