Blame view

MODFIRE-Prototype/res/initialize_years.py 1.08 KB
a4f37eed   Eduardo Eloy   initizalyzers for...
1
2
3
4
5
6
7
8
9
10
11
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):
d1578c9b   Eduardo Eloy   fixed bugs in dat...
12
	cur.execute("SELECT Presc, Year, V_harv FROM action_internal where Id like "+str(i))
a4f37eed   Eduardo Eloy   initizalyzers for...
13
14
	results = cur.fetchall()
	toWrite = ''
d1578c9b   Eduardo Eloy   fixed bugs in dat...
15
16
	hasCut = False;
	isFirst = True
a4f37eed   Eduardo Eloy   initizalyzers for...
17
18
19
20
21
22
23
	
	if(results == []):
		f3.write(str(i)+"|-1\n")
	else:
	
		currentP = results[0][0]
		for j in range(0, len(results)):
d1578c9b   Eduardo Eloy   fixed bugs in dat...
24
25
26
27
28
29
30
31
			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
a4f37eed   Eduardo Eloy   initizalyzers for...
32
				toWrite = toWrite[:-1]+"/"
d1578c9b   Eduardo Eloy   fixed bugs in dat...
33
34
35
36
37
38
39
40
41
42
				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
				
a4f37eed   Eduardo Eloy   initizalyzers for...
43
				currentP = results[j][0]
d1578c9b   Eduardo Eloy   fixed bugs in dat...
44
45
46
47
48
49

		if(hasCut == False):
			if(isFirst == True):
				toWrite = toWrite[:-1]
			toWrite += str(-1)+"/"

a4f37eed   Eduardo Eloy   initizalyzers for...
50
51
		f3.write(str(i)+"|"+toWrite[:-1] + "\n")
		toWrite = ''