initialize_years.py
1.08 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
import csv, re, sqlite3
con = sqlite3.connect("database_modfire.db")
cur = con.cursor()
f3 = open("years_init.txt", "w+")
cur2 = con.cursor()
toWrite = ''
for i in range(0, 1406):
cur.execute("SELECT Presc, Year, V_harv FROM action_internal where Id like "+str(i))
results = cur.fetchall()
toWrite = ''
hasCut = False;
isFirst = True
if(results == []):
f3.write(str(i)+"|-1\n")
else:
currentP = results[0][0]
for j in range(0, len(results)):
if(results[j][0] == currentP): #Staying on a Presc
if(results[j][2] > 0.0):
toWrite += str(results[j][1])+","
hasCut = True
isFirst = False
else: #Changing Presc
isFirst = False
toWrite = toWrite[:-1]+"/"
if(hasCut == False):
toWrite += str(-1)+"/"
hasCut = False
else:
if(results[j][2] > 0.0):
toWrite += str(results[j][1])+","
hasCut = True
else:
hasCut = False
currentP = results[j][0]
if(hasCut == False):
if(isFirst == True):
toWrite = toWrite[:-1]
toWrite += str(-1)+"/"
f3.write(str(i)+"|"+toWrite[:-1] + "\n")
toWrite = ''