-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTempCurveXMLGenerator.py
73 lines (48 loc) · 1.88 KB
/
TempCurveXMLGenerator.py
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
import csv
import os
filename = '10K Type 2 - AIC.csv'
def getFarenheitCurve(filename):
farenheitList = []
with open(filename) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
farenheitList.append(row[2])
return farenheitList
def getResistanceCurve(filename):
resistanceList = []
with open(filename) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
resistanceList.append(row[0])
return resistanceList
def getCelciusCurve(filename):
celciusList = []
with open(filename) as csvfile:
reader = csv.reader(csvfile, dialect='excel')
for row in reader:
celciusList.append(row[1])
return celciusList
farenheitList = getFarenheitCurve(filename)
celciusList = getCelciusCurve(filename)
resistanceList = getResistanceCurve(filename)
def generateXmlTempCurve(resistanceCurve, temperatureCurve, tempCurveFilename):
header = """<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<thermistor>\n<description>""" + tempCurveFilename + """</description>\n<table>\n"""
body = ""
point = ""
for index in range(len(resistanceCurve)):
point += "<point ohms=\"" + resistanceCurve[index] + "\""
point += " farenheight=\"" + temperatureCurve[index] + "\"/>"
body += point + "\n"
point = ""
footer = """</table>\n</thermistor>"""
fileContents = header + body + footer
xmlFileName = tempCurveFilename + ".xml"
if os.path.exists(xmlFileName):
os.remove(xmlFileName)
with open(xmlFileName, "x") as newFile:
newFile.write(fileContents)
else:
with open(xmlFileName, "x") as newFile:
newFile.write(fileContents)
#print(resistanceList)
generateXmlTempCurve(resistanceList, farenheitList, "testCurve")