add transform documentation
This commit is contained in:
@@ -19,11 +19,19 @@ def createDateList(start_date, end_date):
|
|||||||
|
|
||||||
|
|
||||||
class Transform:
|
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):
|
def __init__(self, data_source):
|
||||||
self.data_source = data_source
|
self.data_source = data_source
|
||||||
self.data = None
|
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:
|
with open(self.data_source, "r") as file:
|
||||||
self.data = json.load(file)
|
self.data = json.load(file)
|
||||||
return self
|
return self
|
||||||
@@ -59,31 +67,21 @@ class Transform:
|
|||||||
if addMissing:
|
if addMissing:
|
||||||
tmp[name]["x"].append(date)
|
tmp[name]["x"].append(date)
|
||||||
tmp[name]["y"].append(0)
|
tmp[name]["y"].append(0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
on_state = len(sensor_data[date]["on"])
|
on_state = len(sensor_data[date]["on"])
|
||||||
off_state = len(sensor_data[date]["off"])
|
off_state = len(sensor_data[date]["off"])
|
||||||
activations = (on_state + off_state) / 2
|
activations = (on_state + off_state) / 2
|
||||||
|
# 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)
|
||||||
|
|
||||||
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]
|
|
||||||
temp.update(tmp)
|
temp.update(tmp)
|
||||||
|
|
||||||
return temp
|
return temp
|
||||||
|
|||||||
Reference in New Issue
Block a user