Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
328 lines (325 loc) · 11.3 KB
/
Copy pathmain.py
File metadata and controls
328 lines (325 loc) · 11.3 KB
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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import pandas
import csv
import numpy
import psySI as SI
import math
import comodel as como
from os import walk
f = []
for (dirpath, dirnames, filenames) in walk('inputs'):
f.extend(filenames)
break
for input in f:
data = pandas.read_csv('inputs/'+ input)
l = len(data)-2
days = int(l/24)
index = list(data)
post = []
post2 = []
row = []
row.append('Date and Time')
for s in index:
if index.index(s)>0:
#k = index.index(s)
row.append(s + '(max)')
row.append(s + '(maxtime)')
row.append(s+'(min)')
row.append(s+'(mintime)')
row.append( s+'(mean)')
#first row of output.csv
Wl_1Fac = list(data['Wl-1Facing'])
Wl_1Fac = Wl_1Fac[0]
Wl_2Fac = list(data['Wl-2Facing'])
Wl_2Fac = Wl_2Fac[0]
#headers for post2
row2=[]
row2.append('date and time')
row2.append("TPI_wall1")
row2.append("TPI_wall2")
row2.append('TPI_roof')
row2.append('Depreciation_factor')
row2.append('Damping_Percentage')
row2.append('Max_Damping_day')
row2.append('Max_Damping_night')
row2.append('Time_lag_day')
row2.append('Time_lag_night')
post2.append(row2)
post.append(row)
for i in range(days):
j = (i*24) + 1
row = []
row2 =[]
for s in index:
split = data[s][j:j+24]
splitdate = list(data['Date and Time'][j:j+24])
if (s=='Date and Time'):
mdate = data[s][j]
spliter = mdate[2]
mdate = mdate.split(' ')[0]
mdate = mdate.split(spliter)
(mdate[0],mdate[1])=(mdate[1],mdate[0])
mdate = '/'.join(mdate)
row.append(mdate)
else:
k = index.index(s)
split = list(split)
maxi = max(split)
try:
timemax = splitdate[split.index(maxi)].split( )[1]
if splitdate[split.index(maxi)].split( )[-1] == 'PM':
timemax = str(int(timemax.split(':')[0]) + 12 )
else:
timemax = str(timemax.split(':')[0])
except:
timemax = 'nan'
mini = min(split)
try:
timemin = splitdate[split.index(mini)].split( )[1]
if splitdate[split.index(mini)].split( )[-1] == 'PM':
timemin = str (int(timemin.split(':')[0]) + 12 )
else:
timemin= str(timemin.split(':')[0])
except:
timemin = 'nan'
try:
mean = numpy.mean(split)
except:
mean = 'nan'
row.append(maxi)
row.append(timemax)
row.append(mini)
row.append(timemin)
row.append(mean)
if (s== 'TA in'):
TA_in_max = maxi
TA_in_min = mini
TA_in_maxtim = timemax
TA_in_mintim = timemin
print( s + ' defined')
if (s== 'TA out'):
TA_out_max = maxi
TA_out_min = mini
TA_out_maxtim = timemax
TA_out_mintim = timemin
print( s + ' defined')
if (s== 'TWl-1 in'):
TWl_1_in_max = maxi
TWl_1_in_min = mini
TWl_1_in_maxtim = timemax
TWl_1_in_mintim = timemin
print( s + ' defined')
if (s== 'TWl-1 out'):
TWl_1_out_max = maxi
TWl_1_out_min = mini
TWl_1_out_maxtim = timemax
TWl_1_out_mintim = timemin
print( s + ' defined')
if (s== 'TWl-2 in'):
TWl_2_in_max = maxi
TWl_2_in_min = mini
TWl_2_in_maxtim = timemax
TWl_2_in_mintim = timemin
print( s + ' defined')
if (s== 'TWl-2 out'):
TWl_2_out_max = maxi
TWl_2_out_min = mini
TWl_2_out_maxtim = timemax
TWl_2_out_mintim = timemin
print( s + ' defined')
if (s== 'TRf in'):
TRf_in_max = maxi
TRf_in_min = mini
TRf_in_maxtim = timemin
TRf_in_mintim = timemax
print( s + ' defined')
if (s== 'TRf out'):
TRf_out_max = maxi
TRf_out_min = mini
TRf_out_maxtim = timemax
TRf_out_mintim = timemin
print( s + ' defined')
post.append(row)
if (Wl_1Fac == 'W'):
Corr_1= 0.75
if (Wl_1Fac == 'E'):
Corr_1 = 0.63
if (Wl_1Fac == 'S'):
Corr_1 = 0.42
if (Wl_1Fac == 'N'):
Corr_1 = 0.34
if (Wl_2Fac == 'W'):
Corr_2= 0.75
if (Wl_2Fac == 'E'):
Corr_2 = 0.63
if (Wl_2Fac == 'S'):
Corr_2 = 0.42
if (Wl_2Fac == 'N'):
Corr_2 = 0.34
try:
TPI_1 = ((((TWl_1_in_max - 30)*100)/8))
CTPI_1 = ((TPI_1)-50) * Corr_1 + 50
except:
print('Wl-1 not defined')
try:
TPI_2 = ((((TWl_2_in_max - 30)*100)/8))
CTPI_2 = ((TPI_2)-50) * Corr_2 + 50
except:
print('Wl-2 not defined')
try:
TPI_r = ((((TRf_in_max - 30)*100)/8))
CTPI_r = ((TPI_r)-50) * 0.92 + 50
except:
print('roof not defined')
try:
Depreciation_factor = (TA_in_max - TA_in_min) / (TA_out_max - TA_out_min)
Damping_Percentage = (1 - Depreciation_factor) * 100
Max_Damping_day = TA_out_max - TA_in_max
Max_Damping_night = TA_in_min - TA_out_min
Time_lag_day = int(TA_in_maxtim.split(':')[0])- int(TA_out_maxtim.split(':')[0])
Time_lag_night = int(TA_in_mintim.split(':')[0]) - int(TA_in_mintim.split(':')[0])
except:
print('see all the values for TA')
row2=[]
row2.append(mdate)
row2.append(CTPI_1)
row2.append(CTPI_2)
row2.append(CTPI_r)
row2.append(Depreciation_factor)
row2.append(Damping_Percentage)
row2.append(Max_Damping_day)
row2.append(Max_Damping_night)
row2.append(Time_lag_day)
row2.append(Time_lag_night)
post2.append(row2)
with open("result/"+input+"-output.csv", "a", newline='') as fp:
wr = csv.writer(fp, dialect='excel')
for i in post:
wr.writerow(i)
with open("result/"+input+"-performance-daily.csv", "a", newline='') as fp:
wr = csv.writer(fp, dialect='excel')
for i in post2:
wr.writerow(i)
comf = pandas.read_csv('bin/comf.csv')
awarm = pandas.read_csv('bin/accwarm.csv')
comb = pandas.read_csv('bin/combine.csv')
templ = pandas.read_csv('bin/tempcomb.csv')
hum = list(comf)
hum2 = list(awarm)
comf = numpy.array(comf)
awarm = numpy.array(awarm)
comb = numpy.array(comb)
templ = numpy.array(templ)
time = list(data['Date and Time'])
tin = list(data['TA in'])
rhin = list(data['RH in'])
clo = list(data['Clo '])
clo = float(clo[0])
postcomf =[]
row = ['Date','Time','inttime','Comfort m/s','Acceptibly warm m/s','Mixed m/s','Temp','Rh','tw','TSI','PMV','PPD','Standrd Eff Temp','TA adj','Cool effect']
postcomf.append(row)
vco = 0
co = 0
aw = 0
unc = 0
count = 0
for t in time:
if time.index(t)>0:
d = time.index(t)
t = t.split( )
temp = tin[d]
if temp>0:
if (temp - int(temp)) >0.5:
temp2 = int(temp+1)
else:
temp2 = int(temp)
rh = rhin[d]
if rh>0:
if (rh - 10*(int(int(rh)/10))) > 5:
rh2 = 10*(int(int(rh)/10))+10
else:
rh2 = 10*(int(int(rh)/10))
row = []
b = 0
while temp2>comf[b][0] :
b = b+1
c = 1
while rh2>int(hum[c]):
c = c+1
d=0
while temp2>awarm[d][0]:
d=d+1
e=1
while rh2>int(hum2[e]):
e=e+1
if comb[d][e] == 0:
vco = vco+1
if comb[d][e] == 1:
co = co+1
if comb[d][e] == 2:
aw = aw+1
if comb[d][e] == 3:
unc = unc +1
warcom = max (float(comf[b][c]),float(awarm[d][e]))
if (comf[b][c]<=0) & (awarm[d][e]>=0):
warcom = 3
s = SI.state("DBT",(273+temp),"RH",(rh/100),101325)
try:
tw = s[5] - 273
except TypeError:
tw = s[5]
try:
TSI = (0.308*tw) + (0.745*temp) - (2.06*(math.sqrt((0.9*warcom)+0.841)))
except:
TSI = None
tiime = t[1].split(':')
if t[-1] == 'PM':
tiime[0] = str(int(tiime[0])+12)
# if (int(tiime[0])>7 & int(tiime[0])<23):
# Met = 1.7
#else:
# Met =0.7
Met = 1.5
try:
model= como.comfPMVElevatedAirspeed(temp,temp,(0.3),rh/100,Met,clo,0)
except:
model = [0,0,0,0,0,0,0]
templ[d][e] = templ[d][e]+1
count = count +1
mdate = t[0]
mdate = str(mdate)
spliter = mdate[2]
mdate = mdate.split(spliter)
(mdate[0],mdate[1]) = (mdate[1],mdate[0])
mdate = '/'.join(mdate)
row.append(mdate)
row.append(t[1])
row.append(int(tiime[0]))
row.append(comf[b][c])
row.append(awarm[d][e])
row.append(warcom)
row.append(temp)
#row.append(comf[b][0])
#row.append(awarm[d][0])
#row.append(hum[c])
#row.append(hum2[c])
row.append(rh)
row.append(tw)
row.append(TSI)
row.append(model[0])
row.append(model[1])
row.append(model[2])
row.append(model[3])
row.append(model[4])
postcomf.append(row)
postcomf.append([vco,co,aw,unc])
with open("result/"+input+"-comfort.csv", "a", newline='') as fp:
wr = csv.writer(fp, dialect='excel')
for i in postcomf:
wr.writerow(i)
templ = (templ/count)*100
template = [hum2]
for i in templ:
template.append(i)
with open("result/"+input+"-distribution.csv",'w', newline='') as fp:
wr = csv.writer(fp,dialect = 'excel')
wr.writerows (template)