From 6bb89b0e94b22c5c7e7a42f34ece8d87c53bf7ca Mon Sep 17 00:00:00 2001 From: WorldTeacher <41587052+WorldTeacher@users.noreply.github.com> Date: Mon, 3 Jun 2024 13:57:57 +0200 Subject: [PATCH] add transform documentation --- src/transform.py | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/transform.py b/src/transform.py index 8547667..a9c48f0 100644 --- a/src/transform.py +++ b/src/transform.py @@ -19,11 +19,19 @@ def createDateList(start_date, end_date): class Transform: + """Takes the raw json data and creates a dictionary containing a dictionary per sensor. The inner dictionary contains the date as x and the number of activations as y. + + """ def __init__(self, data_source): self.data_source = data_source self.data = None - def load_data(self): + def load_data(self)->"Transform": + """loads the data from the data source and stores it in the data attribute + + Returns: + self: The instance of the class + """ with open(self.data_source, "r") as file: self.data = json.load(file) return self @@ -59,31 +67,21 @@ class Transform: if addMissing: tmp[name]["x"].append(date) tmp[name]["y"].append(0) - else: on_state = len(sensor_data[date]["on"]) off_state = len(sensor_data[date]["off"]) activations = (on_state + off_state) / 2 - - if on_state != off_state: - # print("Error: On and off states are not equal", name, date) - tmp[name]["x"].append(date) - tmp[name]["y"].append(activations) - else: - - # add the date to the tmp dictionary as x and the number of activations, divided by two as y - tmp[name]["x"].append(date) - tmp[name]["y"].append(activations if activations > 1 else 0) - # print(tmp) - # if split: - # #remove all values that are not in the range of the start and end date - # for i in range(len(tmp[name]["x"])): - # if tmp[name]["x"][i] <= start_date or tmp[name]["x"][i] >= end_date: - # print("Removing value", tmp[name]["x"][i], tmp[name]["y"][i]) - # tmp[name]["x"][i] = None - # tmp[name]["y"][i] = None - # tmp[name]["x"] = [x for x in tmp[name]["x"] if x] - # tmp[name]["y"] = [y for y in tmp[name]["y"] if y] + # add the date to the tmp dictionary as x and the number of activations as y + tmp[name]["x"].append(date) + tmp[name]["y"].append(activations) + # if on_state != off_state: + # tmp[name]["x"].append(date) + # tmp[name]["y"].append(activations) + # else: + # # add the date to the tmp dictionary as x and the number of activations, divided by two as y + # tmp[name]["x"].append(date) + # tmp[name]["y"].append(activations if activations > 1 else 0) + temp.update(tmp) return temp