-
Notifications
You must be signed in to change notification settings - Fork 0
/
AeCompar.py
113 lines (65 loc) · 3.63 KB
/
AeCompar.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
# -*- coding: utf-8 -*-
"""
Comparision -- compare the calculated as with real value
@author: gengliang.li
"""
from DbConnection import DbConnection
from Dbinfo import Dbinfo
from contextlib import closing
import sys
import datetime
class AeCompar:
def __init__(self, fileName):
self.fileName = fileName
Dbconnection = DbConnection(self.fileName)
self.connection = Dbconnection.connectDb()
# this function is to select all the tuples in crim_e_ae ( please pay attention to "all the tuples" )
# that has ae name in cc_dict_ae, preparing for grade check
def aeReal(self):
with closing(self.connection.cursor()) as cur:
sqlstring = "select name from cc_dict_ae "
cur.execute(sqlstring)
targettable = cur.fetchall()
aelist = []
for item in targettable:
aelist.append(item[0]) # select all the ae names and store them in a list
Dbinformation = Dbinfo(self.connection)
aliadic = Dbinformation.ctcaeAliaTable() # get alias dictionary in case aeterm appears as its alia form
with closing(self.connection.cursor()) as cur:
sqlstring = "select subj_3d_id, aespid, ae, aeterm, aestdat, aeendat, aetoxgr from crim_e_ae "
cur.execute(sqlstring)
targetraw = cur.fetchall() # get all the potentially useful information from crim_e_ae
targetlist = []
for item in targetraw:
if item[2] in aelist:
newlist = [item[0]]+[item[1]]+[item[2]]+[item[4]]+[item[5]]+[item[6]]
targetlist.append(newlist)
elif item[3] in aelist:
newlist = [item[0]]+[item[1]]+[item[3]]+[item[4]]+[item[5]]+[item[6]]
targetlist.append(newlist)
elif item[2] in aliadic.keys():
newlist = [item[0]]+[item[1]]+[aliadic[item[2]]]+[item[4]]+[item[5]]+[item[6]]
elif item[3] in aliadic.keys():
newlist = [item[0]]+[item[1]]+[aliadic[item[3]]]+[item[4]]+[item[5]]+[item[6]]
# if ae or aeterm in the ae list, then select this tuple and store it in a list
for item in targetlist:
if item[3]:
if item[4]:
startdate = item[3]
enddate = item[4]
delta = datetime.timedelta(days=1)
aelabstdate = startdate - delta
aelabendate = enddate + delta
item.append(aelabstdate)
item.append(aelabendate)
else:
startdate = item[3]
delta = datetime.timedelta(days=1)
aelabstdate = startdate - delta
aelabendate = startdate + delta
item.append(aelabstdate)
item.append(aelabendate)
else:
sys.exit()
return targetlist # the structute of item in this list is
# [[subj_3d_id],[aespid],[aeName],[aestartdate],[aeenddate],[originalgrade],[labcheckstdate],[labcheckenddate]]