create_map_file.py 988 Bytes
import csv, re, sqlite3

con = sqlite3.connect("res/database2.db")
cur = con.cursor()
f = open("outputPairs.csv", "r")
fw = open("Exports/solFile.sol", "w+")

toWrite = ''
Lines = f.readlines()
fw.write("Variable Name                     Solution Value\n")

count = 0
# Strips the newline character
for line in Lines:
	chunks = line.strip().split(',')
	ug = chunks[0]
	presc = chunks[1]
	
	if str(ug).isnumeric() == False:
		ugFixed = "\""+str(ug)+"\""
	else:
		ugFixed = ug
	if str(presc).isnumeric() == False:
		prescFixed = "\""+str(presc)+"\""
	else:
		prescFixed = presc
		
	cur.execute("SELECT V_thin, V_harv, V_wood, Cork, Period, species FROM action_external where Pa like "+str(ugFixed)+ " AND Presc like "+str(prescFixed)+" order by period")
	
	
	results = cur.fetchall()
	if(results != []):
		for i in range(0, len(results)):
			toWrite = "Presc"+str(presc)+"_Pa"+str(ug)+"_"
			toWrite = toWrite + str(results[i][5])+"_"+str(results[i][4])+"  1.000000\n"
			fw.write(toWrite)