-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbehavior_1.py
More file actions
164 lines (134 loc) · 5.19 KB
/
behavior_1.py
File metadata and controls
164 lines (134 loc) · 5.19 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
class AC:
def __init__(self):
self.flow = "na"
self.statusAC = "OFF"
def setFlow(self, flow):
if flow not in ("low","medium","high","na"):
print("Error! Enter valid option from (low/medium/high/na)")
else:
self.flow = flow
def setACStatus(self, statusAC):
if statusAC not in ("ON","OFF"):
print("Error! Enter valid option from (ON/OFF)")
else:
self.statusAC = statusAC
class ventDuct:
def __init__(self):
self.power = "na"
self.statusVD = "OFF"
def setPower(self, power):
if power not in ("low","medium","high","na"):
print("Error! Enter valid option from (low/medium/high/na)")
else:
self.power = power
def setVDStatus(self, statusVD):
if statusVD not in ("ON","OFF"):
print("Error! Enter valid option from (ON/OFF)")
else:
self.statusVD = statusVD
class People:
def __init__(self):
self.number = 0
def setPeople(self, people):
self.number = people
def increasePeople(self):
self.number = self.number + 1
def decreasePeople(self):
if self.number>0:
self.number = self.number - 1
else:
print("Error! number of people already zero, object crossed is not a person")
class autoTempControl(AC, ventDuct, People):
def __init__(self):
AC.__init__(self)
ventDuct.__init__(self)
People.__init__(self)
def printStatus(self):
print("---**STATUS**---\nAC Status: {}\nAC Flow: {}\nVentilation Duct Status: {}\nVentilation Duct Power: {}\nNumber of People: {}\n---**END**---\n".format(self.statusAC, self.flow, self.statusVD, self.power, self.number))
class TimeStamp:
def __init__(self, temp, flow, humidity):
self.temp = temp
self.flow = flow
self.humidity = humidity
def printTimeStamp(self):
print("Temperature: {} | Flow Sensor Output: {} | Humidity: {}".format(self.temp,self.flow,self.humidity))
class GlobalTimeStamp:
def __init__(self,time, temp, flow, humidity, sunSensor, rainSensor, ir, openWindow, closeWindow):
self.time = time
self.temp = temp
self.flow = flow
self.humidity = humidity
self.sunSensor = sunSensor
self.rainSensor = rainSensor
self.ir = ir
self.openWindow = openWindow
self.closeWindow = closeWindow
def checkBehaviour1(cntrlSystem, timestamp):
prevNum, prevFlow, prevPower = cntrlSystem.number, cntrlSystem.flow, cntrlSystem.power
#Hardware Failure
if timestamp.flow == "NA" or timestamp.temp == "NA" or timestamp.humidity == "NA":
print("Sensor Error.... Repair Sensor.....\n")
if timestamp.flow>0:
cntrlSystem.setPeople(cntrlSystem.number+1)
elif timestamp.flow<0:
cntrlSystem.setPeople(cntrlSystem.number-1)
if cntrlSystem.number == 0:
ventDuct.__init__()
AC.__init__()
if cntrlSystem.number>=prevNum:
#change the temp
if cntrlSystem.statusAC != "ON":
cntrlSystem.setACStatus("ON")
if timestamp.temp > 40:
cntrlSystem.setFlow("high")
elif timestamp.temp > 30 and timestamp.temp < 40:
cntrlSystem.setFlow("medium")
else:
cntrlSystem.setFlow("low")
#change the ventilation settings
if cntrlSystem.statusVD != "ON":
cntrlSystem.setVDStatus("ON")
if timestamp.humidity > 60:
cntrlSystem.setPower("high")
elif timestamp.humidity <= 40 and timestamp.humidity > 30:
cntrlSystem.setPower("medium")
else:
cntrlSystem.setPower("low")
else:
if cntrlSystem.statusAC != "ON":
cntrlSystem.setACStatus("ON")
if cntrlSystem.statusVD != "ON":
cntrlSystem.setVDStatus("ON")
#decrease AC flow
if prevFlow == "high":
cntrlSystem.flow = "medium"
elif prevFlow == "medium":
cntrlSystem.flow = "low"
#decrease ventilation power
if prevPower == "high":
cntrlSystem.power = "medium"
elif prevPower == "medium":
cntrlSystem.power = "low"
def main():
globalDataSet = []
globalDataSet.append(GlobalTimeStamp(1,30.00,40.0, 40,0,0.7,0,1,0))
globalDataSet.append(GlobalTimeStamp(2,35.00,33.78,50,100,0.4,1,1,0))
globalDataSet.append(GlobalTimeStamp(3,34.25,-46.2,46,800,0.0,1,0,1))
globalDataSet.append(GlobalTimeStamp(4,37.00,50.4,60,1600,0.0,1,0,0))
globalDataSet.append(GlobalTimeStamp(5,40.00,4.7,63,0,1.5,0,0,1))
globalDataSet.append(GlobalTimeStamp(6,35.50,28.32,40,0,4.5,1,0,1))
globalDataSet.append(GlobalTimeStamp(7,42.00,-15.0,70,400,0.2,0,0,1))
dataSet = []
for t in globalDataSet:
dataSet.append(TimeStamp(t.temp, t.flow, t.humidity))
a = autoTempControl()
contextList = []
for timestamp in dataSet:
timestamp.printTimeStamp()
a.printStatus()
print("Checking Behavior 1")
checkBehaviour1(a,timestamp)
a.printStatus()
contextList.append(a)
if __name__ == "__main__":
main()