Skip to content

Commit b234ea6

Browse files
committed
Fixes temperature and humidity formula according to affections and environmental properties
1 parent 29b6c94 commit b234ea6

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

stream_simulator/controllers/env_devices/controller_humidity_sensor.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#!/usr/bin/python
66
# -*- coding: utf-8 -*-
77

8-
import statistics
98
import random
109

1110
from stream_simulator.base_classes import BasicSensor
@@ -89,14 +88,9 @@ def get_simulation_value(self):
8988
for a in affections:
9089
vs.append((1 - affections[a]['distance'] / affections[a]['range']) * \
9190
affections[a]['info']['humidity'])
92-
affections = statistics.mean(vs)
91+
affections = max(vs)
9392

94-
if ambient > affections:
95-
ambient += affections * 0.1
96-
else:
97-
ambient = affections - (affections - ambient) * 0.1
98-
99-
final_value = ambient
93+
final_value = ambient if affections < ambient else affections
10094
if self.dynamic_value is None:
10195
self.dynamic_value = final_value
10296
else:

stream_simulator/controllers/env_devices/controller_temperature_sensor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#!/usr/bin/python
66
# -*- coding: utf-8 -*-
77

8-
import statistics
98
import random
109
from stream_simulator.base_classes import BasicSensor
1110

@@ -98,17 +97,18 @@ def get_simulation_value(self):
9897
if affections is None:
9998
return amb
10099

100+
print(affections)
101101
for a in affections:
102102
r = (1 - affections[a]['distance'] / affections[a]['range']) * \
103103
affections[a]['info']['temperature']
104104
temps.append(r)
105105

106106
mms = 0
107-
temps.append(amb)
107+
print(temps)
108108
if len(temps) > 0:
109-
mms = statistics.mean(temps)
109+
mms = max(temps)
110110

111-
final_value = mms
111+
final_value = mms if mms > amb else amb
112112
if self.dynamic_value is None:
113113
self.dynamic_value = final_value
114114
else:

stream_simulator/controllers/sensors/controller_env.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import logging
1010
import threading
1111
import random
12-
import statistics
1312

1413
from stream_simulator.base_classes import BaseThing
1514

@@ -176,10 +175,10 @@ def sensor_read(self):
176175
r = (1 - tem_aff[a]['distance'] / tem_aff[a]['range']) * \
177176
tem_aff[a]['info']['temperature']
178177
temps.append(r)
179-
temps.append(amb)
180-
final_temp = amb
178+
181179
if len(temps) != 0:
182-
final_temp = statistics.mean(temps)
180+
final_temp = max(temps)
181+
final_temp = amb if amb > final_temp else final_temp
183182
if self.dynamic_value['temperature'] is None:
184183
self.dynamic_value['temperature'] = final_temp
185184
else:
@@ -192,17 +191,14 @@ def sensor_read(self):
192191
if len(hum_aff) == 0:
193192
val["humidity"] = ambient + random.uniform(-0.5, 0.5)
194193
vs = []
194+
affections = 0
195195
for a in hum_aff:
196196
vs.append((1 - hum_aff[a]['distance'] / hum_aff[a]['range']) * \
197197
hum_aff[a]['info']['humidity'])
198198
if len(vs) > 0:
199-
affections = statistics.mean(vs)
200-
if ambient > affections:
201-
ambient += affections * 0.1
202-
else:
203-
ambient = affections - (affections - ambient) * 0.1
199+
affections = max(vs)
204200

205-
final_hum = ambient
201+
final_hum = ambient if ambient > affections else affections
206202
if self.dynamic_value['humidity'] is None:
207203
self.dynamic_value['humidity'] = final_hum
208204
else:

0 commit comments

Comments
 (0)