forked from mb003/HomeTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
humidity.py
68 lines (55 loc) · 2.07 KB
/
humidity.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
import math
import time
class humiditySimulator:
currentHumidity = 25
destinationHumidity = 50
isSetTemperature = 0
def __init__(self, currentTime):
self.currentTemperature = self.getInDoorTemperature(currentTime)
self.destinationTemperature = self.getInDoorTemperature(currentTime)
def getOutDoorTemperatureUp(self, currentTime):
day = time.strftime("%j", time.localtime(currentTime))
day = int(day)
theta = math.pi * (day - 105) / 180
T = math.sin(theta) * 14.5 + 16.5
return T
def getOutDoorTemperatureDown(self, currentTime):
day = time.strftime("%j", time.localtime(currentTime))
day = int(day)
theta = math.pi * (day - 105) / 180
T = math.sin(theta) * 15.5 + 6.5
return T
def getOutDoorTemperature(self, currentTime):
hour = int(time.strftime("%H", time.localtime(currentTime)))
minute = int(time.strftime("%M", time.localtime(currentTime)))
totalMinute = 60 * hour + minute
theta = math.pi * (totalMinute - 540) / 720
up = self.getOutDoorTemperatureUp(currentTime)
down = self.getOutDoorTemperatureDown(currentTime)
T = math.sin(theta) * (up - down) / 2 + (up + down) / 2
return T
def getInDoorTemperature(self, currentTime):
outDoorT = self.getOutDoorTemperature(currentTime)
# print(outDoorT)
T = 0.6 * 25 + 0.4 * outDoorT
return T
def getCurrentTemperature(self):
return self.currentTemperature
def iterate(self, currentTime, timeSlot):
if(self.isSetTemperature == 0):
deltaT = (self.getInDoorTemperature(currentTime) - self.getCurrentTemperature()) / (1000.0 / timeSlot)
self.currentTemperature = self.currentTemperature + deltaT
else:
deltaT = (self.destinationTemperature - self.currentTemperature) / (1000.0 / timeSlot)
self.currentTemperature = self.currentTemperature + deltaT
return self.currentTemperature
def setTemperatureOn(self, destinationTemperature):
self.isSetTemperature = 1
self.destinationTemperature = destinationTemperature
def setTemperatureOff(self):
self.isSetTemperature = 0
def isTemperatureBeenSet(self):
if(self.isSetTemperature == 0):
return False
else:
return True