Skip to content

Commit

Permalink
small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hahahannes committed May 8, 2024
1 parent 744bdf1 commit 6a47ff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

UNUSUAL_FILENAME = "unusual_drop_detections.pickle"
WINDOW_FILENAME = "window_closing_times.pickle"
FIRST_DATA_FILENAME = "first_data_time.pickle"

from operator_lib.util import Config
class CustomConfig(Config):
Expand Down Expand Up @@ -57,7 +58,7 @@ def init(self, *args, **kwargs):
if not os.path.exists(self.data_path):
os.mkdir(self.data_path)

self.first_data_time = load(self.config.data_path, "first_data_time.pickle")
self.first_data_time = load(self.config.data_path, FIRST_DATA_FILENAME)

self.sliding_window = [] # This contains the data from the last hour. Entries of the list are pairs of the form {"timestamp": ts, "value": humidity}
self.unsusual_drop_detections = load(self.data_path, UNUSUAL_FILENAME, [])
Expand All @@ -71,19 +72,19 @@ def init(self, *args, **kwargs):
"window_open": False,
"timestamp": ""
}
if self.init_phase_handler.first_init_msg_needs_to_send():
init_msg = self.init_phase_handler.generate_first_init_msg(value)
self.produce(init_msg)
self.init_phase_handler.send_first_init_msg(value)

def stop(self):
super().stop()
save(self.data_path, UNUSUAL_FILENAME, self.unsusual_drop_detections)
save(self.data_path, WINDOW_FILENAME, self.window_closing_times)
save(self.data_path, FIRST_DATA_FILENAME, self.first_data_time)

def run(self, data, selector = None, device_id=None):
current_timestamp = todatetime(data['Humidity_Time'])
if not self.first_data_time:
self.first_data_time = current_timestamp
save(self.data_path, FIRST_DATA_FILENAME, self.first_data_time)
self.init_phase_handler = InitPhase(self.config.data_path, self.init_phase_duration, self.first_data_time)

new_value = float(data['Humidity'])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git+https://github.com/SENERGY-Platform/analytics-operator-lib-python@v1.0.18
git+https://github.com/SENERGY-Platform/analytics-operator-lib-python@v1.1.0

confluent_kafka<2
pandas<2
Expand Down

0 comments on commit 6a47ff7

Please sign in to comment.