-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearchFilter.py
118 lines (77 loc) · 2.89 KB
/
searchFilter.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# 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 allows search by datetime filtering
# tested with freestyle precisionNeo driver only
#
import matplotlib
import matplotlib.pyplot as plt
from datetime import date, time, datetime
#globals
allReadings = []
dates = []
times = []
bloodSugar = []
def fileClean():
file = input("Enter Filename: ")
edit = open(file, "r")
edit.seek(0,0)
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
def filterList(myList):
# creates new list of lists with 2 indices
# myList[n][0] datetime object
# myList[n][1] blood glucose reading
tempList = []
for i in range(len(myList)):
tempDate = date.fromisoformat(str(myList[i][0]))
tempTime = time.fromisoformat(str(myList[i][1]))
tempDateTime = datetime.combine(tempDate, tempTime)
tempList.append([tempDateTime, myList[i][2]])
#print(tempList[i])
return tempList
def preciseFilter(filterList):
# will filter by datetime
print("Please Select a Filtering Parameter", "\n",
"1: Year", "\n", "2: Month", "\n", "3: Day", "\n")
choice = input(":---> ")
choice = int(choice)
if choice == 1:
myYear = input("Enter a year: ")
for i in range(len(filterList)):
if filterList[i][0].year == int(myYear):
print(filterList[i])
elif choice == 2:
myMonth = input("Enter a month: ")
for i in range(len(filterList)):
if filterList[i][0].month == int(myMonth):
print(filterList[i])
elif choice == 3:
myYear = input("Enter Year: ")
myMonth = input("Enter Month: ")
myDay = input("Enter Day: ")
for i in range(len(filterList)):
if filterList[i][0].year == int(myYear):
if filterList[i][0].month == int(myMonth):
if filterList[i][0].day == int(myDay):
print(filterList[i])
fileClean()
filtered = filterList(allReadings)
preciseFilter(filtered)