seeResult.py
1.91 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
76
77
78
79
80
81
82
83
84
85
import csv, re, sqlite3
con = sqlite3.connect("res/database_modfire.db")
cur = con.cursor()
Filemame = "outputPairsMulti.csv"
f=open(Filemame,"r")
lines=f.readlines()
result=[]
x = []
y = []
i = 1
o = 0
printNext = True
print("Pick solution")
isFirst = True
divisible = 0
for line in lines:
if(isFirst):
isFirst = False
elif(line[0] == "P"):
break
divisible = divisible + 1
for line in lines:
if(printNext):
print(line[:-1])
printNext = False
else:
if(i % divisible == 0):
printNext = True
i+=1
val = input("Pick solution: ")
goTo = int(val)*divisible+1
until = (int(val)+1)*divisible
import itertools
years = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
soilByYear = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
toWrite = ''
f=open("Results/ChosenResultsWoodByYear.csv","w+")
f.write("Wood Obtained by MU/Presc\n")
with open(Filemame, "r") as text_file:
for line in itertools.islice(text_file, goTo, until):
ugpresc = line.split(',')
ug = ugpresc[0]
presc = ugpresc[1]
cur.execute("SELECT V_harv, V_thin, Soilloss FROM action_external where Id like "+str(ug)+" and Presc like " + str(presc))
result = cur.fetchall()
toWrite = toWrite + str(ug) + ", " + str(presc) + "\n"
for i in range(0,len(result)):
years[i] = years[i] + result[i][0]+result[i][1]
soilByYear[i] = soilByYear[i] + result[i][2]
toWrite = toWrite + str(2020+i) + ": "+ str(result[i][0]+result[i][1]) + "\n"
cur.execute("SELECT sum(V_harv+V_thin) FROM action_external where Id like "+str(ug)+" and Presc like " + str(presc))
result = cur.fetchall()
f.write(str(ug)+"/"+ str(presc)+"- "+str(result[0][0]).replace('\n', "")+"\n")
f.close()
print("Wood/Soilloss Obtained by year")
for i in range(0,len(years)):
print(str(2020+i)+": "+ str(years[i])+ ", " + str(soilByYear[i]))