-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinit_db.py
317 lines (288 loc) · 12.3 KB
/
init_db.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
import sqlite3 as sql
import random
import datetime
connection = sql.connect('MOA.db')
class Job:
def __init__(self,job_id,mode,status):
self.job_id = job_id
self.mode = mode
self.status = status
def insertJobs(Jobid, n_tasks, mode, n_classes, graph_conv_layers, activation, number_atom_features, residual, batchnorm, dropout, predictor_hidden_feats, predictor_dropout, self_loop, currentstatus, datasetFilename, resultfilename):
print(str(Jobid)+str(n_tasks)+str(mode)+str(n_classes)+str(graph_conv_layers)+str(activation)+str(number_atom_features)+str(residual)+str(batchnorm)+str(dropout)+str(predictor_hidden_feats)+str(predictor_dropout)+str(self_loop)+str(currentstatus)+str(datasetFilename)+str(resultfilename))
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("Insert INTO GCNModel (Jobid, n_tasks, mode, n_classes, graph_conv_layers, activation, number_atom_features, residual, batchnorm, dropout, predictor_hidden_feats, predictor_dropout, self_loop, currentstatus, datasetFilename, resultfilename) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)" , (Jobid, n_tasks, mode, n_classes, graph_conv_layers, activation, number_atom_features, residual, batchnorm, dropout, predictor_hidden_feats, predictor_dropout, self_loop, currentstatus, datasetFilename, resultfilename))
con.commit()
con.close()
return Jobid
def insertJobsGAT(Jobid, n_tasks, mode, n_classes, att_hd,dropo,pred_hd_feat,pred_drp,alpha,self_loop,graphcn,graphat_aggmode,currentstatus, datasetFilename, resultfilename):
# print(str(Jobid)+str(n_tasks)+str(mode)+str(n_classes)+str(graph_conv_layers)+str(activation)+str(number_atom_features)+str(residual)+str(batchnorm)+str(dropout)+str(predictor_hidden_feats)+str(predictor_dropout)+str(self_loop)+str(currentstatus)+str(datasetFilename)+str(resultfilename))
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("Insert INTO GATModel (Jobid, ntask, mode, n_classes, att_hd,dropo,pred_hd_feat,pred_drp,alpha,self_loop,graphcn,graphat_aggmode,currentstatus, datasetFilename, resultfilename) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (Jobid, n_tasks, mode, n_classes, att_hd,dropo,pred_hd_feat,pred_drp,alpha,self_loop,graphcn,graphat_aggmode,currentstatus, datasetFilename, resultfilename))
con.commit()
con.close()
return Jobid
def insertJobsDAG(Jobid,nclass,natom,dropo,pred_hd_feat,pred_drp,self_loop,graphcn,layersize_gather,mode,currentstatus,datasetFilename,resultfilename):
# print(str(Jobid)+str(n_tasks)+str(mode)+str(n_classes)+str(graph_conv_layers)+str(activation)+str(number_atom_features)+str(residual)+str(batchnorm)+str(dropout)+str(predictor_hidden_feats)+str(predictor_dropout)+str(self_loop)+str(currentstatus)+str(datasetFilename)+str(resultfilename))
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("Insert INTO DAGModel (Jobid,nclass,natom,dropo,pred_hd_feat,pred_drp,self_loop,graphcn,layersize_gather,mode,currentstatus,datasetFilename,resultfilename) Values (?,?,?,?,?,?,?,?,?,?,?,?,?)", (Jobid,nclass,natom,dropo,pred_hd_feat,pred_drp,self_loop,graphcn,layersize_gather,mode,currentstatus,datasetFilename,resultfilename))
con.commit()
con.close()
return Jobid
# # job_id,created,email,job_name,status,mode,n_tasks,n_classes,dropout,no_atom_features,max_atoms,n_graph_feat,n_outputs,layer_sizes_gather,layer_sizes,uncertainity,self_loop,learning_rate,epoch,csv_name
# Jobid,ntask,nclass,natom,bond_ft,dropo,pred_hd_feat,num_ts,graph_ft,mode
def insertJobsAttentive(Jobid,ntask,nclass,natom,bond_ft,dropo,pred_hd_feat,pred_drp,self_loop,num_ts,graph_ft,mode,currentstatus,datasetFilename,resultfilename):
# print(str(Jobid)+str(n_tasks)+str(mode)+str(n_classes)+str(graph_conv_layers)+str(activation)+str(number_atom_features)+str(residual)+str(batchnorm)+str(dropout)+str(predictor_hidden_feats)+str(predictor_dropout)+str(self_loop)+str(currentstatus)+str(datasetFilename)+str(resultfilename))
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("Insert INTO AttentiveModel (Jobid,ntask,nclass,natom,bond_ft,dropo,pred_hd_feat,pred_drp,self_loop,num_ts,graph_ft,mode,currentstatus,datasetFilename,resultfilename) Values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", (Jobid,ntask,nclass,natom,bond_ft,dropo,pred_hd_feat,pred_drp,self_loop,num_ts,graph_ft,mode,currentstatus,datasetFilename,resultfilename))
con.commit()
con.close()
return Jobid
def isEmailNotPresentInsert(email,name, password):
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT * FROM users WHERE email=?", (email,))
users = cur.fetchall()
if users == []:
print("not a user...")
# insert and make a new user
cur.execute("Insert into users (Email, Name, Password) Values (?,?,?)", (email, name, password))
con.commit()
con.close()
return True
else:
# users present
return False
def checkUser(email,password):
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT password FROM users WHERE email=?", (email,))
users = cur.fetchall()
if users == []:
print("not a user")
return False
elif password == users[0][0]:
print("enter....")
return True
else:
print("Wrong pwd..")
return False
def retrieveAllJobs(email):
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT * FROM GCNModel where email=?",(email,))
jobs = cur.fetchall()
con.close()
return jobs
def fromGCN(job_id):
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT * FROM GCNModel where Jobid=? ", (job_id,))
row = cur.fetchall()
print(row)
con.close()
return row
def getJobs(email,mode):
if mode == 'gcn':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT Jobid FROM createdjobs where email=? and TypeOfModel='gcn' ", (email,))
jobs = cur.fetchall()
print(jobs)
con.close()
if mode == 'dag':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT Jobid FROM createdjobs where email=? and TypeOfModel='dag' ", (email,))
jobs = cur.fetchall()
print(jobs)
con.close()
if mode == 'gat':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT Jobid FROM createdjobs where email=? and TypeOfModel='gat' ", (email,))
jobs = cur.fetchall()
print(jobs)
con.close()
if mode == 'attentive':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT Jobid FROM createdjobs where email=? and TypeOfModel='attentive' ", (email,))
jobs = cur.fetchall()
print(jobs)
con.close()
return jobs
def getCurrentStatus(jobid,mode):
if mode == 'gcn':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT currentstatus FROM GCNModel where Jobid=? ", (jobid,))
status = cur.fetchall()
print(jobid)
print(status[0][0])
con.close()
return status[0][0]
if mode == 'gat':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT currentstatus FROM GATModel where Jobid=? ", (jobid,))
status = cur.fetchall()
print(status[0][0])
con.close()
return status[0][0]
if mode == 'dag':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT currentstatus FROM DAGModel where Jobid=? ", (jobid,))
status = cur.fetchall()
print(status[0][0])
con.close()
return status[0][0]
if mode == 'attentive':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT currentstatus FROM AttentiveModel where Jobid=? ", (jobid,))
status = cur.fetchall()
print(status[0][0])
con.close()
return status[0][0]
def updateCurrentStatus(jobid,mode,status):
if mode == 'gcn':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("UPDATE GCNModel SET currentstatus =? WHERE Jobid =?", (status, jobid,))
con.commit()
con.close()
if mode == 'gat':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("UPDATE GATModel SET currentstatus =? WHERE Jobid =?", (status, jobid,))
con.commit()
con.close()
if mode == 'attentive':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("UPDATE AttentiveModel SET currentstatus =? WHERE Jobid =?", (status, jobid,))
con.commit()
con.close()
if mode == 'dag':
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("UPDATE DAGModel SET currentstatus =? WHERE Jobid =?", (status, jobid,))
con.commit()
con.close()
def get_all_job(email):
all_jobs = []
modes = ['gcn','dag', 'gat','attentive']
for mode in modes:
jobids = getJobs(email,mode)
for job in jobids:
currentstatus = getCurrentStatus(job[0],mode)
all_jobs.append(Job(job[0],mode,currentstatus[0]))
print(all_jobs)
# for i in all_jobs:
# print(i.job_id)
# print(i.mode)
# print(i.status)
return all_jobs
def insertIntoCreatedJob(Jobid,Email, Mode):
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("Insert into createdjobs (Email, Jobid, TypeOfModel) Values (?,?,?)", (Email, Jobid, Mode))
con.commit()
con.close()
def getMaxId():
con = sql.connect("MOA.db")
cur = con.cursor()
cur.execute("SELECT MAX(Jobid) as max_items FROM createdjobs ")
status = cur.fetchall()
print(status[0][0])
con.close()
return status[0][0]
# (5,"gcn",1)
# insertIntoCreatedJob( 8 , "rahul@gmail.com" , "gcn" )
#
# def insertJobs(email,title):
# con = sql.connect("dtabase.s3db;")
# cur = con.cursor()
# job_id = random.randint(1000,2000)
# cur.execute("SELECT job_id from deep_jobs")
# pre_ids = cur.fetchall()
# print(pre_ids)
# if pre_ids!=[]:
# while job_id in pre_ids[0]:
# job_id = random.randint(1000, 2000)
# created = datetime.datetime.now()
# # created = time.time()
# status="created"
# mode="Classification"
# name = "d1.csv"
# cur.execute("INSERT INTO deep_jobs (job_id,created,email,job_name,status,mode,csv_name) VALUES (?,?,?,?,?,?,?)", (job_id,created, email,title,status,mode,name))
# con.commit()
# con.close()
# return job_id
#
# def retrieveJobs(job_id):
# print(type(job_id))
# con = sql.connect("dtabase.s3db;")
# cur = con.cursor()
#
# cur.execute("SELECT * FROM deep_jobs WHERE job_id=?", (job_id,))
# row = cur.fetchall()
# con.close()
# return row
#
#
#
#
# def insertusers(u_email,u_name,pwd):
# con = sql.connect("dtabase.s3db;")
# cur = con.cursor()
# created = datetime.datetime.now()
# cur.execute("INSERT INTO users (name,email,pwd,created) VALUES (?,?,?,?)", (u_name,u_email,pwd,created))
# con.commit()
# con.close()
# return "Success"
#
# def checkuser(email,pwd):
# # print(type(job_id))
# con = sql.connect("dtabase.s3db;")
# cur = con.cursor()
# cur.execute("SELECT pwd FROM users WHERE email=?", (email,))
# users = cur.fetchall()
# con.close()
# print(users)
# if users==[]:
# print("not a user...")
# return False
# elif pwd == users[0][0]:
# print("enter....")
# return True
# else:
# print("Wrong pwd..")
# return False
# # return users
#
# def hasEmail(email):
# con = sql.connect("dtabase.s3db;")
# cur = con.cursor()
#
# cur.execute("SELECT email FROM users WHERE email=?", (email,))
# users = cur.fetchall()
# con.close()
# print(users)
# if(users == []):
# return False
# else:
# return True
#
# getJobs("rahul20065@iiitd.ac.in","gcn")
# getCurrentStatus( 1 ,'gcn')
# get_all_job("rahul20065@iiitd.ac.in")
# row = fromGCN(1)
# print(type(row))
# print(row[0][2])
# getCurrentStatus(9,"gcn")