-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
124 lines (106 loc) · 4.81 KB
/
main.py
File metadata and controls
124 lines (106 loc) · 4.81 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
import mathTools
protokoll_name = "rawData.txt"
splitter = " "
# Converts the 2022.12.30 08:40:26 date/time format to seconds, to be able to easily do comparisons
def timeToSecondConverter(date: str, time: str):
years = mathTools.leading_zero_remover(date.split(".")[0])
months = mathTools.leading_zero_remover(date.split(".")[1])
days = mathTools.leading_zero_remover(date.split(".")[2])
hours = mathTools.leading_zero_remover(time.split(":")[0])
minutes = mathTools.leading_zero_remover(time.split(":")[1])
seconds = mathTools.leading_zero_remover(time.split(":")[2])
resultDate = (years * 31536000 + months * 2635 + days * 86400)
resultTime = (hours * 3600 + minutes * 60 + seconds)
return resultDate + resultTime
# Takes the string "on" or "off" as an input and returns a boolean. Used for the motion sensors log data
def StringBoolConverter(str_bool: str):
table = {
"on": True,
"off": False
}
return table[str_bool]
# The class, which represents a line in the protokoll. Takes a protokoll line as an input and makes accessing the
# data more easily by converting it into the right format
class ProtokollLine:
def __init__(self, line: str):
line = line.replace("\n", "")
self.rawLine = line
line = line.split(splitter)
self.eventType = line[2]
self.pInRoom = StringBoolConverter(line[3])
self.power = float(line[4])
self.temp1 = float(line[5])
self.temp2 = float(line[6])
self.date = line[0]
self.time = line[1]
self.absoluteTime = timeToSecondConverter(self.date, self.time)
# Here are the cases, which will get checked.
class Case1:
# checks if room temperature is above a specific value(19) while no one is in the room for a given amount of
# minutes (standard 30 minutes)
def __init__(self, wait_time: int = 30, max_temp1: int = 19):
self.waitTimeMinute = wait_time
self.running = False
self.max_temp1 = max_temp1
self.name = "TEMPERATUR ALARM"
self.advice = "Schalte doch mal die Heizung ab, wenn du nicht im Raum bist."
def raise_alarm(self, marked: ProtokollLine, end: ProtokollLine):
print(f"{self.name} | {marked.date} {marked.time} -> {end.date} {end.time} | Time -minutes-: {((end.absoluteTime - marked.absoluteTime) / 60).__int__()} | {self.advice}")
def check(self, line: ProtokollLine):
if line.pInRoom == False and line.temp1 > self.max_temp1:
if self.running == False:
self.marked = line
self.running = True
#print(f"{self.name} - marked - {line.rawLine}")
# print(line.rawLine)
else:
pass
else:
if self.running:
if line.absoluteTime - self.marked.absoluteTime > (self.waitTimeMinute * 60):
# print(line.rawLine)
self.running = False
self.raise_alarm(self.marked, line)
else:
self.running = False
#print(f"{self.name} - Broke - {line.rawLine}")
class Case2:
# Checks if no one is in the room and the value of the Steckdose is over 0.0 power units for the given amount of
# minutes
def __init__(self, wait_time: int = 30):
self.waitTimeMinute = wait_time
self.running = False
self.name = "STECKDOSEN ALARM"
self.advice = "Schalte doch mal das Gerät ab, das an der Steckdose hängt, wenn du aus dem Zimmer gehst."
def raise_alarm(self, marked: ProtokollLine, end: ProtokollLine):
print(f"{self.name} | {marked.date} {marked.time} -> {end.date} {end.time} | Time -minutes-: {((end.absoluteTime - marked.absoluteTime) / 60).__int__()} | {self.advice}")
def check(self, line: ProtokollLine):
if line.pInRoom == False and line.power > 0.1:
if self.running == False:
self.marked = line
self.running = True
#print(f"{self.name} - marked - {line.rawLine}")
# print(line.rawLine)
else:
pass
else:
if self.running:
if line.absoluteTime - self.marked.absoluteTime > (self.waitTimeMinute * 60):
# print(line.rawLine)
self.running = False
self.raise_alarm(self.marked, line)
else:
self.running = False
#print(f"{self.name} - Broke - {line.rawLine}")
# Opens protokoll and goes through lines
with open(protokoll_name) as protokoll:
print("opening protokoll file")
c1 = Case1(30)
c2 = Case2(1)
for line in protokoll:
# print(line)
line = ProtokollLine(line)
c1.check(line)
c2.check(line)
# print(line.rawLine)
print("finish")