initialize_period.py
1.44 KB
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
import csv, re, sqlite3
con = sqlite3.connect("database2.db")
cur = con.cursor()
f3 = open("period_init", "w+")
cur2 = con.cursor()
toWrite = ''
for i in range(0, 1373):
cur.execute("SELECT presc, period FROM hascut where ug like "+str(i)+ " order by presc")
results = cur.fetchall()
toWrite = ''
cur2.execute("SELECT distinct presc FROM action where ug like "+str(i)+" order by presc")
results2 = cur2.fetchall()
if(len(results) > 0):
prescA = []
for k in range(0, len(results2)):
prescA.append(int(str(results2[k])[1:-2]))
ind = 0
currentPresc = results[0][0]
for j in range(0,len(results)):
presc = results[j][0]
if(j == 0):
if(currentPresc != prescA[ind]):
while(currentPresc != prescA[ind]):
toWrite = toWrite + "0/"
ind = ind + 1
else:
toWrite += str(results[j][1])+","
else:
if(int(currentPresc) == int(presc)):
toWrite += str(results[j][1])+","
elif(int(currentPresc) != int(presc)):
ind = ind + 1
while(int(prescA[ind]) != int(presc)):
toWrite = toWrite[:-1]
toWrite = toWrite + "/0/"
currentPresc = results[j][0]
toWrite = toWrite[:-1]
toWrite += "/"+str(results[j][1])+","
ind = ind + 1
toWrite = toWrite[:-1]
point = len(results2)
while(point != ind):
ind = ind + 1
toWrite = toWrite + "/0"
toWrite = toWrite + "\n"
else:
toWrite = "0\n"
f3.write(toWrite)