-
Notifications
You must be signed in to change notification settings - Fork 8
/
humid.py
executable file
·60 lines (52 loc) · 1.4 KB
/
humid.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
#!/usr/bin/python3
import airdata
import os
import time
import sys
import traceback
airdata_inst = airdata.Energy()
extract = float(sys.argv[1])
def get_humidity():
global airdata_inst, extract
day = 60 * 22
templist = []
data = os.popen("tail -n " + str(int(day)) + " ./RAM/data.log")
try:
sunrise = int(os.popen("./forcast2.0.py sun").readlines()[0].split(":")[0])
except:
sunrise = 6
for each in data.readlines():
tmp = each.split(":")
try:
if sunrise - 1 <= time.localtime(float(tmp[0]))[3] <= sunrise + 1 and \
float(tmp[0]) > time.time() - (3 * 3600):
templist.append(float(tmp[5]))
else:
# print time.localtime(float(tmp[0]))[3]
pass
except:
print("error getting sunrise temp ranges")
# print templist
if len(templist) > 0:
inlet_min = sum(templist)/len(templist)
else:
try:
inlet_min = float(open("RAM/latest_static", 'r').read())
except:
traceback.print_exc()
raise IndexError
airdata_inst.sat_vapor_press(extract)
bottom = airdata_inst.pw
airdata_inst.sat_vapor_press(inlet_min)
top = airdata_inst.pw
# adjustmet to closer match RHwmo below zero saturations
if inlet_min < 0:
top = airdata_inst.pw + bottom * (float(inlet_min * -1.05) / 100)
print(top / bottom * 100, inlet_min)
# input : indoor temp
# output: relative humidity as expressed by indoor temp last 24hrs min temp
try:
get_humidity()
except:
print(-60, -1)
traceback.print_exc()