-
Notifications
You must be signed in to change notification settings - Fork 0
/
post_process.py
296 lines (238 loc) · 8.61 KB
/
post_process.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# Post-process building data. String comparisons are modeled from Olin data string names.
import csv
import sys
floor_ = [0] * 9
exposure = [0] * 5
avg_temps_floor = []
sum_boxflows_floor = []
avg_temps_exp = []
sum_boxflows_exp = []
max_min = []
flow_error = []
temp_error = []
# Process each file one at a time; append to one output file
def main(data_file):
# clear arrays for new file
avg_temps_floor.clear()
sum_boxflows_floor.clear()
avg_temps_exp.clear()
sum_boxflows_exp.clear()
max_min.clear()
flow_error.clear()
temp_error.clear()
with open(data_file, 'r') as file:
reader = csv.DictReader(file)
print("Processing %s..." % str(data_file))
# generate floors
count = 0
for row in reader:
floor_data(row, floor_)
exp_data(row, exposure)
flow_error_check(row, max_min, flow_error)
temp_error_check(row, temp_error)
process_floor(row, avg_temps_floor, sum_boxflows_floor)
process_exposure(row, avg_temps_exp, sum_boxflows_exp)
count += 1
print("Processed %d rows." % count)
print("Writing to file...")
write_csv(file, max_min, 'max_min_')
write_csv(file, flow_error, 'flow_error_')
write_csv(file, temp_error, 'temp_error_')
write_csv(file, avg_temps_exp, 'avg_temps_exp_')
write_csv(file, avg_temps_floor, 'avg_temps_floor_')
write_csv(file, sum_boxflows_exp, 'sum_boxflows_exp_')
write_csv(file, sum_boxflows_floor, 'sum_boxflows_floor_')
print("Done.")
def write_csv(datafile, list, name):
filename = name + datafile.name
with open(filename, 'w+') as file:
first = list.pop()
writer = csv.DictWriter(file, first.keys(), delimiter=',', lineterminator='\n')
writer.writeheader()
writer.writerow(first)
for entry in list:
writer = csv.DictWriter(file, entry.keys(), delimiter=',', lineterminator='\n')
writer.writerow(entry)
def temp_error_check(row, output):
tmp = {}
for entry in row.keys():
if 'spacesetpoint' in entry:
add_time(row, tmp)
tmp[entry] = float(row[entry]) - float(row[entry.replace('spacesetpoint', 'spacetemp')])
output.append(tmp)
def flow_error_check(row, max_min_check, error_check):
tmp_mm = {}
tmp_err = {}
bldg_min = 0
bldg_max = 0
bldg_flo = 0
bldg_tot = 0
for entry in row.keys():
if 'flowsetpoint' in entry.lower():
add_time(row, tmp_err)
add_time(row, tmp_mm)
flowset = float(row[entry])
flow = float(row[entry.replace('flowsetpoint', 'boxflow')])
maxflow = float(row[entry.replace('flowsetpoint', 'maxflow')])
minflow = float(row[entry.replace('flowsetpoint', 'minflow')])
bldg_flo += flow
bldg_tot += maxflow
if flowset == maxflow:
tmp_mm[entry] = 100 # max flow
bldg_max += 1
elif (flowset == minflow) or (maxflow == 0):
tmp_mm[entry] = 0
bldg_min += 1
else:
tmp_mm[entry] = ((maxflow - flow)/maxflow)*100
try:
tmp_err[entry] = ((flowset - flow)/flowset)*100
except: # div by 0
try:
tmp_err[entry] = ((flowset - flow) / (flowset + flow)) * 100
except: # still div by 0!?
tmp_err[entry] = 0
try:
tmp_mm["% at max"] = bldg_max/len(tmp_err)
except:
tmp_mm["% at max"] = 0
try:
tmp_mm["% at min"] = bldg_min/len(tmp_err)
except:
tmp_mm["% at min"] = 0
try:
tmp_mm["% overall"] = bldg_flo/bldg_tot
except ZeroDivisionError:
tmp_mm["% overall"] = 0
max_min_check.append(tmp_mm)
error_check.append(tmp_err)
def add_time(row, output):
try:
output.append(row['Time'])
output.append(row['Time Delta']) # Add some error checking here
except:
output['Time'] = row['Time']
output['Time Delta'] = row['Time Delta']
def process_exposure(row, avg_output_exp, sum_output_exp):
# right now assume exposures will be found in exposures.csv in this directory
exp = {}
with open('exposures.csv', 'r') as file:
reader = csv.reader(file)
for row_ in reader:
exp[row_[0]] = row_[1] # Rm : n/s/e/w
avg_exp = {}
sum_exp = {}
temp_dict = {'n_temp' : [], 's_temp' : [], 'e_temp' : [], 'w_temp' : [], 'c_temp' : [], 'b_temp' : []}
flow_dict = {'n_flow': [], 's_flow': [], 'e_flow': [], 'w_flow': [], 'c_flow' : [], 'b_flow' : []}
add_time(row, avg_exp)
add_time(row, sum_exp)
for entry in row:
for key in exp:
if (key in entry) and (len(exp[key]) > 0):
exp_l = str(exp[key])
if ('temp' in entry) or ('temp' in entry and 'rmf' in entry.lower() and 'b' in exp_l):
temp_dict[exp_l + '_temp'].append(float(row[entry]))
if 'boxflow' in entry:
flow_dict[exp_l + '_flow'].append(float(row[entry]))
for entry in temp_dict:
try:
avg_exp[entry] = sum_list(temp_dict[entry])/len(temp_dict[entry])
except ZeroDivisionError:
avg_exp[entry] = 0
for entry in flow_dict:
sum_exp[entry] = sum_list(flow_dict[entry])
avg_output_exp.append(avg_exp)
sum_output_exp.append(sum_exp)
def process_floor(row, avg_output_floor, sum_output_floor):
avg_floor = {}
sum_floor = {}
# Empty dicts for ALL THE FLOORS
temp_dict = {'floor2_temp' : [], 'floor3_temp' : [], 'floor4_temp' : [], 'floor5_temp' : [], 'floor6_temp' : [],
'floor7_temp' : [], 'floor8_temp' : []}
flow_dict = {'floor2_flow': [], 'floor3_flow': [], 'floor4_flow': [], 'floor5_flow': [], 'floor6_flow': [],
'floor7_flow': [], 'floor8_flow': []}
add_time(row, avg_floor)
add_time(row, sum_floor)
for entry in row.keys():
for level in range(2,9):
floor = 'floor' + str(level)
if ('rm' + str(level)) in entry.lower():
if 'temp' in entry.lower():
temp_dict[floor + '_temp'].append(float(row[entry]))
if (('rm' + str(level)) in entry.lower()) or (('rmf' + str(level)) in entry.lower()):
if 'boxflow' in entry.lower():
flow_dict[floor + '_flow'].append(float(row[entry]))
for entry in temp_dict:
try:
avg_floor[entry] = sum_list(temp_dict[entry])/len(temp_dict[entry])
except ZeroDivisionError:
avg_floor[entry] = 0
for entry in flow_dict:
sum_floor[entry] = sum_list(flow_dict[entry])
avg_output_floor.append(avg_floor)
sum_output_floor.append(sum_floor)
def floor_data(row, output):
# Empty dicts for ALL THE FLOORS
floor2 = {}
floor3 = {}
floor4 = {}
floor5 = {}
floor6 = {}
floor7 = {}
floor8 = {}
for entry in row.keys():
if ('Rm2' or 'RmF2') in entry:
floor2[entry] = row[entry]
output[2] = floor2
elif ('Rm3' or 'RmF3') in entry:
floor3[entry] = row[entry]
output[3] = floor3
elif ('Rm4' or 'RmF4') in entry:
floor4[entry] = row[entry]
output[4] = floor4
elif ('Rm5' or 'RmF5') in entry:
floor5[entry] = row[entry]
output[5] = floor5
elif ('Rm6' or 'RmF6') in entry:
floor6[entry] = row[entry]
output[6] = floor6
elif ('Rm7' or 'RmF7') in entry:
floor7[entry] = row[entry]
output[7] = floor7
elif ('Rm8' or 'RmF8') in entry:
floor8[entry] = row[entry]
output[8] = floor8
def exp_data(row, output):
# empty dicts for ALL THE EXPOSURES
north = {}
south = {}
east = {}
west = {}
for entry in row.keys():
if 'NTH' in entry.upper():
north[entry] = row[entry]
output[0] = north
elif 'STH' in entry.upper():
south[entry] = row[entry]
output[1] = south
elif 'EST' in entry.upper():
east[entry] = row[entry]
output[2] = east
elif 'WST' in entry.upper():
west[entry] = row[entry]
output[3] = west
def sum_list(list):
sum = 0
for x in list:
try:
sum += x
except TypeError:
pass
return sum
# Can pass multiple files to script
if __name__ == "__main__":
for file in sys.argv:
if '.py' in file:
pass # skip first argument
else:
main(file)