10
10
- Humidity and Watering should be between 0 and 100, since they are percentages.
11
11
- Light has to be positive or 0.
12
12
'''
13
+
14
+
13
15
def create_packet (temperature : float = None , humidity : float = None , light : float = None , watering : float = None ):
14
16
if not (temperature and humidity and light and watering ):
15
17
return None
16
-
18
+
17
19
if humidity < 0 or humidity > 100 :
18
20
raise Exception (f"Humidity has to be between 0 and 100. Current value: { humidity } " )
19
-
21
+
20
22
if watering < 0 or watering > 100 :
21
23
raise Exception (f"Watering has to be between 0 and 100. Current value: { watering } " )
22
-
24
+
23
25
if light < 0 :
24
26
raise Exception (f"Light has to be positive or 0. Current value: { light } " )
25
-
27
+
26
28
return {
27
29
"temperature" : temperature ,
28
30
"humidity" : humidity ,
@@ -39,15 +41,18 @@ def create_packet(temperature: float = None, humidity: float = None, light: floa
39
41
-
40
42
-
41
43
'''
44
+
45
+
42
46
def generate_data ():
43
- #TODO
47
+ # TODO
44
48
temperature = rnd .randint (- 5 , 30 )
45
49
humidity = rnd .randint (0 , 100 )
46
50
light = rnd .randint (0 , 400 )
47
51
watering = rnd .randint (0 , 100 )
48
52
49
53
return temperature , humidity , light , watering
50
54
55
+
51
56
'''
52
57
Compares the current packet and the last sent packet, based in the deviations.
53
58
@@ -64,10 +69,20 @@ def generate_data():
64
69
- last_sent: {temperature: float, humidity: float, light: float, watering: float}
65
70
- deviations: {temperature: float, humidity: float, light: float, watering: float}
66
71
'''
67
- def current_packet_differs_from_last_sent (current , last_sent , deviations ):
68
- #TODO
69
72
73
+
74
+ def data_has_changed (current , last_sent , deviations ):
70
75
if not last_sent :
71
76
return True
72
77
73
- return True
78
+ if parameter_has_changed (current ["temperature" ], last_sent ["temperature" ], deviations ["temperature" ])\
79
+ or parameter_has_changed (current ["humidity" ], last_sent ["humidity" ], deviations ["humidity" ])\
80
+ or parameter_has_changed (current ["light" ], last_sent ["light" ], deviations ["light" ])\
81
+ or parameter_has_changed (current ["watering" ], last_sent ["watering" ], deviations ["watering" ]):
82
+ return True
83
+
84
+ return False
85
+
86
+
87
+ def parameter_has_changed (current , last , deviation ):
88
+ return abs (current - last ) > deviation
0 commit comments