-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphData.py
90 lines (61 loc) · 2.01 KB
/
graphData.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# A script for my fork of
# glucometerUtils (https://github.com/pat-nel87/glucometerutils/tree/customFeatures)
# Designed to work with output generated by --text argument added to dump
# Cleans up Data in txt file and generates matplotlib graph
# tested with freestyle precisionNeo driver only
#
import matplotlib
import matplotlib.pyplot as plt
from io import StringIO
from datetime import date, time, datetime
def dateConvert(dates, times):
myList = []
for i in range(len(dates)):
myDate = date.fromisoformat(str(dates[i]))
myTime = time.fromisoformat(str(times[i]))
myDatetime = datetime.combine(myDate, myTime)
myList.append(myDatetime)
return myList
def graphList(myList, bloodSugar):
print("\n")
graphFile = input("Please enter a file name for graph: ")
graphFile = graphFile + ".png"
x = matplotlib.dates.date2num(myList)
y = bloodSugar
fig = matplotlib.pyplot.figure()
matplotlib.pyplot.plot_date(x, y, 'r', label="mg/dl")
#imgdata = StringIO()
fig.savefig(graphFile)
plt.show()
#imgdata.seek(0)
#data = open("newreading.svg", "w")
#data.write(imgdata)
#data.close()
file = input("Enter Filename: ")
edit = open(file, "r")
edit.seek(0,0)
allReadings = []
dates = []
times = []
bloodSugar = []
for line in edit:
lin = edit.readline()
try:
reading = [lin[1]]
for i in range(2,11):
reading[0] = reading[0] + lin[i]
dates.append(reading[0])
reading.append(lin[12])
for i in range(13,20):
reading[1] = reading[1] + lin[i]
times.append(reading[1])
reading.append(lin[23])
for i in range(24,28):
reading[2] = reading[2] + lin[i]
bloodSugar.append(reading[2])
allReadings.append(reading)
except IndexError:
print("Processing Completed")
break
datetimeList = dateConvert(dates, times)
graphList(datetimeList, bloodSugar)