feat: add usage, activation to line, persistent alias, auto-updating data based on time
This commit is contained in:
@@ -47,21 +47,25 @@ class Transform:
|
||||
for key, value in self.data.items():
|
||||
sensors.append({"id": key, "value": value})
|
||||
temp = {}
|
||||
s_data = {}
|
||||
|
||||
start_date = start_date
|
||||
end_date = end_date
|
||||
# create a list of all dates between the start and end date
|
||||
all_dates = createDateList(start_date, end_date)
|
||||
|
||||
for sensor in sensors:
|
||||
tmp = {}
|
||||
sensor_values = {}
|
||||
name = sensor["id"]
|
||||
sensor_values[name] = sensor["value"]
|
||||
tmp[name] = {"x": [], "y": []}
|
||||
sensor_data = sensor["value"]
|
||||
sensor_dates = list(sensor_data.keys())
|
||||
print(len(all_dates))
|
||||
sum_activations = 0
|
||||
|
||||
|
||||
for date in all_dates:
|
||||
# print(date)
|
||||
if date not in sensor_dates:
|
||||
# print("Date not in sensor data", name, date)
|
||||
if addMissing:
|
||||
@@ -71,6 +75,11 @@ class Transform:
|
||||
on_state = len(sensor_data[date]["on"])
|
||||
off_state = len(sensor_data[date]["off"])
|
||||
activations = (on_state + off_state) / 2
|
||||
if activations == 1:
|
||||
activations = 0
|
||||
else:
|
||||
activations = on_state
|
||||
sum_activations += activations
|
||||
# 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)
|
||||
@@ -83,8 +92,10 @@ class Transform:
|
||||
# tmp[name]["y"].append(activations if activations > 1 else 0)
|
||||
|
||||
temp.update(tmp)
|
||||
#create new entry in s_data for sensor, add key "total_activations" and the sum of all activations, as well as the usage, which is activation divided by the number of days
|
||||
s_data[name] = {"total_activations": sum_activations, "usage": round(sum_activations / 2)}
|
||||
|
||||
return temp
|
||||
return temp, s_data
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user