-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLite_3.py
523 lines (480 loc) · 15.5 KB
/
SQLite_3.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
import sqlite3
import os
class Database():
def __init__(self, filepath):
self.filepath = filepath
self.conn = sqlite3.connect(self.filepath)
self.cur = self.conn.cursor()
def Get_Tables(self):
#returns a tuple list with all the table names from a given db connection
self.cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
return self.cur.fetchall()
def Get_Tables_Dict(self):
#returns a library of category table names as keys and
#category tables names with no "_" as values
tables = self.Get_Tables()
table_lib = {}
for table in tables:
key = "%s" % table
value = key.replace('_',' ')
value = value.replace('and','&')
table_lib[str(key)] = str(value)
return table_lib
def Get_Columns(self, table):
#returns a tuple list with all the column names from a given db connection
column_query = self.conn.execute('SELECT * from %s' % table)
return [description[0] for description in column_query.description]
def Select_Query(self, columns, table, conditions):
return self.conn.execute("SELECT %s FROM %s %s" % (columns, table, conditions))
def Select_Query_Column_Summation(self, column, table, condition, condition_value, date1, date2):
select_query_statement = "SELECT SUM(%s) FROM %s WHERE %s %s AND data_date BETWEEN %s AND \
'%s'" % (column, table, condition, tuple(condition_value), tuple(date1), tuple(date2))
return self.conn.execute(select_query_statement)
def Insert_Query_No_Conditions(self, table, columns, values):
self.conn.execute("INSERT INTO %s %s VALUES %s" % (table, tuple(columns), tuple(values)))
#self.conn.commit()
def Delete_Query_With_Conditions(self, table, conditions):
self.conn.execute("DELETE FROM %s WHERE %s" % (table, conditions))
self.conn.commit()
def Create_Employee_Tables(self):
self.conn.execute('''
CREATE TABLE employee(
clk_no TEXT PRIMARY KEY,
employee_name TEXT,
employee_type TEXT)
''')
self.conn.execute('''
CREATE TABLE upload_dates(
employee_clk_no TEXT,
mondays_date TEXT)
''')
def Update_Employee_Tables(self, department):
table = 'employee'
columns = ['employee_name', 'clk_no', 'employee_type']
if department == "SepSci":
values = [['Jones, Tom', '0743','In-House'],['Leetz, Edward','0791','Field'],['Rowe, Christopher','0227','In-House'],
['Card, Wayne','0767','In-House'],['Clifford, Ray','0798','Field'],['Frazee, Joseph','0196','In-House'],
['Hasty, Matthew','0938','Field'],['Immoos, Chris','1076','In-House'],['Jeka, Angelia','3012','N/A'],
['Kite, Kenneth','0912','N/A'],['Norlock, Samantha','3013','N/A'],['Paulaski, James','0923','Field'],
['Rich, Kiely','0192','In-House'],['Richards, Todd','0889','N/A'],['Toms, Anthony','0888','In-House'],
['Miniard, Brittany','0198','N/A']]
elif department == "GDS":
values = [['Jones, Tom', '0743','In-House'],['Rowe, Christopher','0227','In-House'],
['Bergen, Joseph','0953','Field'],['Johns, Ben','0362','Field']]
for v in values:
self.Insert_Query_No_Conditions(table, columns, v)
def Create_Category_Tables(self):
self.conn.execute('''
CREATE TABLE SS_Installations(
data_date TEXT,
employee_clk_no TEXT,
Installations_day_sum INTEGER,
Installations_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Installations(
data_date TEXT,
employee_clk_no TEXT,
Installations_day_sum INTEGER,
Installations_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_PM_Site_Visits(
data_date TEXT,
employee_clk_no TEXT,
PM_Site_Visits_day_sum INTEGER,
PM_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_PM_Site_Visits(
data_date TEXT,
employee_clk_no TEXT,
PM_Site_Visits_day_sum INTEGER,
PM_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Rpr_Maint_Site_Visits(
data_date TEXT,
employee_clk_no TEXT,
Inst_Repair_or_Maintenance_on_Site_day_sum INTEGER,
Site_Visit_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Rpr_Maint_Site_Visits(
data_date TEXT,
employee_clk_no TEXT,
Inst_Repair_or_Maintenance_on_Site_day_sum INTEGER,
Site_Visit_Prep INTEGER,
Documentation_Admin INTEGER,
Travel INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Training_by_Engineer INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Rmt_Hrdwr_Spt(
data_date TEXT,
employee_clk_no TEXT,
Rmt_Hardware_Support_day_sum INTEGER,
Email INTEGER,
Phone INTEGER,
Rmt_PC_Access INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
International_Support INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Rmt_Hrdwr_Spt(
data_date TEXT,
employee_clk_no TEXT,
Rmt_Hardware_Support_day_sum INTEGER,
Email INTEGER,
Phone INTEGER,
Rmt_PC_Access INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
International_Support INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Rmt_Sftwr_Spt(
data_date TEXT,
employee_clk_no TEXT,
Rmt_Software_Support_day_sum INTEGER,
Email INTEGER,
Phone INTEGER,
Rmt_PC_Access INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
International_Support INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Rmt_Sftwr_Spt(
data_date TEXT,
employee_clk_no TEXT,
Rmt_Software_Support_day_sum INTEGER,
Email INTEGER,
Phone INTEGER,
Rmt_PC_Access INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
International_Support INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Rpr_Mant_RFB_in_House(
data_date TEXT,
employee_clk_no TEXT,
Inst_Repair_Maint_Rfb_In_House_day_sum INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Rpr_Mant_RFB_in_House(
data_date TEXT,
employee_clk_no TEXT,
Inst_Repair_Maint_Rfb_In_House_day_sum INTEGER,
Hands_On_Instrument INTEGER,
Troubleshooting INTEGER,
Documentation_Admin INTEGER,
Other INTEGER)
''')
self.conn.execute('''
CREATE TABLE Miscellaneous(
data_date TEXT,
employee_clk_no TEXT,
Miscellaneous_day_sum INTEGER,
Meetings_Internal_Communication INTEGER,
PTO_Sick_Dr_Apts INTEGER,
SAP INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Doc_Gen(
data_date TEXT,
employee_clk_no TEXT,
Document_Generation_day_sum INTEGER,
Pegasus_HT_4D_Hardware INTEGER,
Pegasus_HT_4D_Software INTEGER,
Pegasus_BT_Hardware INTEGER,
Pegasus_BT_Software INTEGER,
Pegasus_HRT_Hardware INTEGER,
Pegasus_HRT_Software INTEGER,
Other_Hardware INTEGER,
Other_Software INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Doc_Gen(
data_date TEXT,
employee_clk_no TEXT,
Document_Generation_day_sum INTEGER,
GDS500A_Hardware INTEGER,
GDS500A_Software INTEGER,
GDS850A_Hardware INTEGER,
GDS850A_Software INTEGER,
GDS900_Hardware INTEGER,
GDS900_Software INTEGER,
GDS950_Hardware INTEGER,
GDS950_Software INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Inter_Dep_Spt(
data_date TEXT,
employee_clk_no TEXT,
Inter_Dep_Spt_day_sum INTEGER,
R_and_D INTEGER,
Applications INTEGER,
Validation INTEGER,
Marketing INTEGER,
Test INTEGER,
Shipping INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Inter_Dep_Spt(
data_date TEXT,
employee_clk_no TEXT,
Inter_Dep_Spt_day_sum INTEGER,
R_and_D INTEGER,
Applications INTEGER,
Validation INTEGER,
Marketing INTEGER,
Test INTEGER,
Shipping INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Online_Training(
data_date TEXT,
employee_clk_no TEXT,
Online_Training_day_sum INTEGER,
Scheduling INTEGER,
Peg_HT_New_Customer INTEGER,
Peg_4D_New_Customer INTEGER,
Peg_BT_New_Customer INTEGER,
Peg_HRT_New_Customer INTEGER,
Peg_HT_Paid INTEGER,
Peg_4D_Paid INTEGER,
Peg_BT_Paid INTEGER,
Peg_HRT_Paid INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Online_Training(
data_date TEXT,
employee_clk_no TEXT,
Online_Training_day_sum INTEGER,
Scheduling INTEGER,
GDS900_New_Customer INTEGER,
GDS950_New_Customer INTEGER,
GDS900_Paid INTEGER,
GDS950_Paid INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_Onsite_Training(
data_date TEXT,
employee_clk_no TEXT,
Onsite_Training_day_sum INTEGER,
Scheduling INTEGER,
Travel INTEGER,
Documentation_Admin INTEGER,
Customer_Entertainment INTEGER,
Peg_HT_4D_New_Customer INTEGER,
Peg_BT_New_Customer INTEGER,
Peg_HRT_New_Customer INTEGER,
GCxGC_FID_New_Customer INTEGER,
TruTOF_Paid INTEGER,
Peg_HT_4D_Paid INTEGER,
Peg_BT_Paid INTEGER,
Peg_HRT_Paid INTEGER,
GCxGC_FID_Paid INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_Onsite_Training(
data_date TEXT,
employee_clk_no TEXT,
Onsite_Training_day_sum INTEGER,
Scheduling INTEGER,
Travel INTEGER,
Documentation_Admin INTEGER,
Customer_Entertainment INTEGER,
GDS500A_New_Customer INTEGER,
GDS850A_New_Customer INTEGER,
GDS900_New_Customer INTEGER,
GDS950_New_Customer INTEGER,
GDS500A_Paid INTEGER,
GDS850A_Paid INTEGER,
GDS900_Paid INTEGER,
GDS950_FID_Paid INTEGER)
''')
self.conn.execute('''
CREATE TABLE SS_In_House_Training(
data_date TEXT,
employee_clk_no TEXT,
In_House_Training_day_sum INTEGER,
Classroom_Setup INTEGER,
System_Checkout INTEGER,
Customer_Entertainment INTEGER,
Peg_HT_4D_New_Customer INTEGER,
Peg_BT_New_Customer INTEGER,
Peg_HRT_New_Customer INTEGER,
GCxGC_FID_New_Customer INTEGER,
TruTOF_Paid INTEGER,
Peg_HT_4D_Paid INTEGER,
Peg_BT_Paid INTEGER,
Peg_HRT_Paid INTEGER,
GCxGC_FID_Paid INTEGER,
Internal_Domestic INTEGER,
Internal_International INTEGER)
''')
self.conn.execute('''
CREATE TABLE GDS_In_House_Training(
data_date TEXT,
employee_clk_no TEXT,
In_House_Training_day_sum INTEGER,
Classroom_Setup INTEGER,
System_Checkout INTEGER,
Customer_Entertainment INTEGER,
GDS500A_New_Customer INTEGER,
GDS850A_New_Customer INTEGER,
GDS900_New_Customer INTEGER,
GDS950_New_Customer INTEGER,
GDS500A_Paid INTEGER,
GDS850A_Paid INTEGER,
GDS900_Paid INTEGER,
GDS950_Paid INTEGER,
Internal_Domestic INTEGER,
Internal_International INTEGER)
''')
self.conn.execute('''
CREATE TABLE Validation_Duties(
data_date TEXT,
employee_clk_no TEXT,
Validation_Duties_day_sum INTEGER,
Data_Collection INTEGER,
Data_Handling INTEGER,
Report_Generation INTEGER,
Instrument_Troubleshooting INTEGER,
Instrument_Maintenance INTEGER,
Experiment_Planning_and_Method_Development INTEGER,
Sample_Prep INTEGER,
Remote_Instrument_Interface INTEGER,
Administrative INTEGER)
''')
def Get_Query_Category_Table_List(self):
return [
'SS_Installations',
'GDS_Installations',
'SS_PM_Site_Visits',
'GDS_PM_Site_Visits',
'SS_Rpr_Maint_Site_Visits',
'GDS_Rpr_Maint_Site_Visits',
'SS_Rmt_Hrdwr_Spt',
'GDS_Rmt_Hrdwr_Spt',
'SS_Rmt_Sftwr_Spt',
'GDS_Rmt_Sftwr_Spt',
'SS_Rpr_Mant_RFB_in_House',
'GDS_Rpr_Mant_RFB_in_House',
'Miscellaneous',
'SS_Doc_Gen',
'GDS_Doc_Gen',
'SS_Inter_Dep_Spt',
'GDS_Inter_Dep_Spt',
'SS_Online_Training',
'GDS_Online_Training',
'SS_Onsite_Training',
'GDS_Onsite_Training',
'SS_In_House_Training',
'GDS_In_House_Training',
'Validation_Duties'
]
def Get_SS_Query_Category_Table_List(self):
return [
'SS_Installations',
'SS_PM_Site_Visits',
'SS_Rpr_Maint_Site_Visits',
'SS_Rmt_Hrdwr_Spt',
'SS_Rmt_Sftwr_Spt',
'SS_Rpr_Mant_RFB_in_House',
'Miscellaneous',
'SS_Doc_Gen',
'SS_Inter_Dep_Spt',
'SS_Online_Training',
'SS_Onsite_Training',
'SS_In_House_Training',
'Validation_Duties'
]
def Get_GDS_Query_Category_Table_List(self):
return [
'GDS_Installations',
'GDS_PM_Site_Visits',
'GDS_Rpr_Maint_Site_Visits',
'GDS_Rmt_Hrdwr_Spt',
'GDS_Rmt_Sftwr_Spt',
'GDS_Rpr_Mant_RFB_in_House',
'Miscellaneous',
'GDS_Doc_Gen',
'GDS_Inter_Dep_Spt',
'GDS_Online_Training',
'GDS_Onsite_Training',
'GDS_In_House_Training',
]
def Get_Diplay_Category_Table_Dict(self):
return {
'SS_Installations': 'Installations',
'GDS_Installations': 'Installations',
'SS_PM_Site_Visits': 'PM Site Visits',
'GDS_PM_Site_Visits': 'PM Site Visits',
'SS_Rpr_Maint_Site_Visits' :'Site Visits',
'GDS_Rpr_Maint_Site_Visits' :'Site Visits',
'SS_Rmt_Hrdwr_Spt': 'Remote Hardware Support',
'GDS_Rmt_Hrdwr_Spt': 'Remote Hardware Support',
'SS_Rmt_Sftwr_Spt' : 'Remote Software Support',
'GDS_Rmt_Sftwr_Spt': 'Remote Software Support',
'SS_Rpr_Mant_RFB_in_House': 'In House Maintenance',
'GDS_Rpr_Mant_RFB_in_House': 'In House Maintenance',
'Miscellaneous' : 'Miscellaneous',
'SS_Doc_Gen': 'Document Creation',
'GDS_Doc_Gen': 'Document Creation',
'SS_Inter_Dep_Spt': 'Inter Departmental Spt.',
'GDS_Inter_Dep_Spt': 'Inter Departmental Spt.',
'SS_Online_Training': 'Online Training',
'GDS_Online_Training': 'Online Training',
'SS_Onsite_Training': 'Onsite Training',
'GDS_Onsite_Training': 'Onsite Training',
'SS_In_House_Training': 'In House Training',
'GDS_In_House_Training': 'In House Training',
'Validation_Duties': 'Validation Duties'
}
def Get_Category_Indexes(self, type):
if type == "AllSepSci":
return [0,2,4,6,8,10,12,13,15,17,19,21,23]
elif type == "AllGDS":
return [1,3,5,7,9,11,12,14,16,18,20,22]