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__":
|
||||
|
||||
@@ -3,7 +3,9 @@ from PyQt6 import QtWidgets
|
||||
|
||||
|
||||
class Graph:
|
||||
def __init__(self, data: list):
|
||||
def __init__(self, data: list,label_data, legend_data):
|
||||
self.label_data = label_data
|
||||
self.legend_data = legend_data
|
||||
self.xlist = []
|
||||
if isinstance(data, dict):
|
||||
self.xlist += data[list(data.keys())[0]]["x"]
|
||||
@@ -14,8 +16,6 @@ class Graph:
|
||||
xlist = list(set(self.xlist))
|
||||
xlist.sort()
|
||||
xdict = dict(enumerate(xlist))
|
||||
print("xlist:", xlist)
|
||||
print(xdict)
|
||||
self.xdict = xdict
|
||||
stringaxis_x = pg.AxisItem(orientation="bottom")
|
||||
stringaxis_x.setTicks([xdict.items()])
|
||||
@@ -30,11 +30,15 @@ class Graph:
|
||||
self.plot_lines(data)
|
||||
else:
|
||||
self.plot_line(data)
|
||||
|
||||
self.add_information()
|
||||
self.graph.showGrid(x=True, y=True)
|
||||
|
||||
|
||||
def add_information(self, ):
|
||||
pass
|
||||
def plot_line(self, data, color="r"):
|
||||
line_label = list(data.keys())[0]
|
||||
line_data = self.legend_data[line_label]
|
||||
line_addon = f" ({line_data['total_activations']}|{line_data['usage']})"
|
||||
x_data = data[line_label]["x"]
|
||||
self.xlist += x_data
|
||||
x_data = [date.split("2024-")[1] for date in x_data]
|
||||
@@ -45,13 +49,12 @@ class Graph:
|
||||
global_xdict = {
|
||||
key: global_xdict[key] for key in xdict.keys() if key in global_xdict.keys()
|
||||
}
|
||||
print(line_label, global_xdict)
|
||||
|
||||
y_data = data[line_label]["y"]
|
||||
self.graph.plot(
|
||||
list(xdict.keys()),
|
||||
y_data,
|
||||
name=line_label,
|
||||
name=f"{line_label}{line_addon}",
|
||||
pen=pg.mkPen(color=color, width=2),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user