-
Notifications
You must be signed in to change notification settings - Fork 0
/
chooseafile.py
236 lines (184 loc) · 7.1 KB
/
chooseafile.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
import pandas
from matplotlib import pyplot as plt
import os
import Reader as read
# The following code takes one day of data of user choice and analyzes it.
def chooseafile():
# If more HMOS are recorded from, add their name below.
HMOlist = ["25_McIntyre", "2_Himbleton", "37_Woodstock", "50_Bleinheim", "8_Bozward"]
# If more data is recorded in the future, add the year, month number below.
yearlist = ["2017", "2018", "2019"]
monthlist = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]
hmocheck = 1
while hmocheck == 1:
print("HMO Names: 25_McIntyre, 2_Himbleton, 37_Woodstock, 50_Bleinheim, 8_Bozward")
print("")
HMO = input("Type name of the HMO you wish to analyze: ")
if HMO in HMOlist:
print("{} is a correct HMO name".format(HMO))
hmocheck = 0
else:
print("The entered HMO name does not exist")
hmocheck = 1
yearcheck = 1
while yearcheck == 1:
year = input("Type the year you wish to analyze in Ex: 2018 format: ")
if year in yearlist:
yearcheck = 0
else:
print("The entered year name is formatted wrong or not a valid year")
yearcheck = 1
monthcheck = 1
while monthcheck == 1:
month = input("Enter the month of the data in number format, EX: 11 = November, 01 = January")
if month in monthlist:
monthcheck = 0
else:
print("The month entered is not a month number or not entered correctly")
monthcheck = 1
daycheck = 1
while daycheck == 1:
day = input("Enter the day of the data in number format")
intday = int(day)
if month == "01" or month == "03" or month == "05" or month == "07" or month == "08" or month == "10" or month == "12":
if intday in range(1, 31):
daycheck = 0
else:
print("Enter a day in the month chosen")
daycheck = 1
if month == "04" or month == "06" or month == "09" or month == "11":
if intday in range(1, 30):
daycheck = 0
else:
print("Enter a day in the month chosen")
daycheck = 1
if month == "04" or month == "06" or month == "09" or month == "11":
if intday in range(1, 30):
daycheck = 0
else:
print("Enter a day in the month chosen")
daycheck = 1
# doubtful that data will be taken in 2020 for this application / project so no need to check for leap year
if month == "02":
if intday in range(1, 28):
daycheck = 0
else:
print("Enter a day in the month chosen")
daycheck = 1
if HMO == "25_McIntyre":
stringstart = "720200236_Data_"
elif HMO == "2_Himbleton":
stringstart = "720200260_Data_"
elif HMO == "37_Woodstock":
stringstart = "720200288_Data_"
elif HMO == "50_Bleinheim":
stringstart = "720200295_Data_"
elif HMO == "8_Bozward":
stringstart = "720200262_Data_"
else:
print("error in code where likely the start of the string part does not have a check for the new HMO added")
finalstring = "./RawWBData/{}/{}{} {} {}.csv".format(HMO, stringstart, year, month, day)
# print(finalstring)
return finalstring
def doesitexist(finalstring, filelist):
print(type(finalstring), type(filelist[0]), finalstring in filelist)
for file in filelist:
# print(file, finalstring)
if file == finalstring:
print("Attempting to plot desired day")
return "y"
print("No file found")
return "n"
def makelist():
rootDir = './RawWBData/'
filenamelist = [] # directories is a 3d array containing all of the days in the collected data
for dirName, subdirList, fileList in os.walk(rootDir):
for fname in sorted(fileList):
# print("{}/{}".format(dirName, fname))
filenamelist.append("{}/{}".format(dirName, fname))
return filenamelist
def onedayplot(day, path):
changeday = day[:8300]
print(len(changeday))
times = []
for time in pandas.date_range('00:00', None, periods=8300, freq='10S'):
times.append(str(time).split(' ')[-1])
if len(day) >= 8300:
plotchosen = "wrong"
while plotchosen == "wrong":
print("actPow | hwTSet | primT | chActive | primTSet | hWActive | hWTOutlet")
plotchoose = input("Which variable do you want to plot? For multiple variables please separate by commas")
plotchoose = plotchoose
plotchosen = appender(plotchoose, changeday)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(times, plotchosen)
plt.setp(ax1.get_xticklabels(), visible=False)
plt.setp(ax1.get_xticklabels()[::700], visible=True)
plt.xticks(fontsize=10, rotation=90)
for tic in ax1.xaxis.get_major_ticks():
if (ax1.xaxis.get_major_ticks().index(tic) % 700 == 0):
continue
else:
tic.tick1On = tic.tick2On = False
tic.label1On = tic.label2On = False
plt.gcf().subplots_adjust(bottom=0.23)
plt.xlabel("Time of Day", labelpad=10)
plt.title(plotchoose + " " + path[39:49])
plt.show()
else:
print("This day exists, but does not have enough data points to be considered for plotting")
#put more plots of interest here!
return
def chooserun():
allfiles = makelist()
requestedpath = chooseafile()
answer = doesitexist(requestedpath, allfiles)
if answer == "y":
onedayplot(read.openFile(requestedpath), requestedpath)
else:
print("file does not exist!")
return
def appender(plotchoose, changeday):
actPow = []
hwTSet = []
primT = []
chActive = []
primTSet = []
hWActive = []
hWTOutlet = []
for item in changeday:
if plotchoose == "actPow":
actPow.append((item[1]))
elif plotchoose == "hwTSet":
hwTSet.append((item[2]))
elif plotchoose == "primT":
primT.append((item[3]))
elif plotchoose == "chActive":
chActive.append((item[4]))
elif plotchoose == "primTSet":
primTSet.append((item[5]))
elif plotchoose == "hWActive":
hWActive.append((item[6]))
elif plotchoose == "hWTOutlet":
hWTOutlet.append((item[7]))
else:
print("that is not a variable!")
plotchosen = "wrong"
if plotchoose == "actPow":
plotchosen = actPow
elif plotchoose == "hwTSet":
plotchosen = hwTSet
elif plotchoose == "primT":
plotchosen = primT
elif plotchoose == "chActive":
plotchosen = chActive
elif plotchoose == "primTSet":
plotchosen = primTSet
elif plotchoose == "hWActive":
plotchosen = hWActive
elif plotchoose == "hWTOutlet":
plotchosen = hWTOutlet
return plotchosen
if __name__ == '__main__':
chooserun()