diff --git a/README.md b/README.md index 117bff6..1d92070 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,29 @@ # ZSDiagram -a small application to display graphs of Sensor data collected by Homassistant and formatted in a certain way \ No newline at end of file +ZSDiagram ist eine kleine Grafische Anwendung, welche eine JSON-Datei in einem bestimmten Format einliest und daraus ein Diagram erstellt. + +Das Diagramm kann entweder für einen, mehrere, oder alle Sensoren auf einmal erstellt werden. + +## Filtermethoden: +- Sensoren +- Zeitraum + +## Zusatz: +- Fehlende Tage einfügen + - Standardmäßig werden nur die Tage angezeigt, an denen auch Daten vorhanden sind. Dies ist problematisch, wenn mehrere Sensoren in einem Diagram angezeigt werden, da die Daten nicht immer an den gleichen Tagen vorhanden sind. + +# Installation +1. Repository klonen +2. In das Verzeichnis wechseln +3. venv erstellen + - `python -m venv venv` + - `source venv/bin/activate` + - Windows: `venv\Scripts\activate` + - `pip install --upgrade pip` + - `pip install -r requirements.txt` +4. Programm ausführen + - `python application.py` + +## Daten einlesen +1. JSON-Datei mit Drag&Drop auf das Fenster ziehen, der Pfad wird automatisch eingetragen +2. ... \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6419526 Binary files /dev/null and b/requirements.txt differ diff --git a/src/ui/graph.py b/src/ui/graph.py index 9beb983..5b70275 100644 --- a/src/ui/graph.py +++ b/src/ui/graph.py @@ -3,7 +3,7 @@ from PyQt6 import QtWidgets class Graph: - def __init__(self, data: dict | list): + def __init__(self, data: list): self.xlist = [] if isinstance(data, dict): self.xlist += data[list(data.keys())[0]]["x"] @@ -21,7 +21,7 @@ class Graph: stringaxis_x.setTicks([xdict.items()]) self.graph = pg.PlotWidget(axisItems={"bottom": stringaxis_x}) # self.graph.("Zeitschriftennutzung") - self.graph.setLabel("left", "Anzahl der potentiellen Nutzungen") + self.graph.setLabel("left", "Anzahl der Aktivierungen") self.graph.setLabel("bottom", "Datum") self.graph.addLegend() @@ -30,12 +30,8 @@ class Graph: self.plot_lines(data) else: self.plot_line(data) - # remove duplicate x values self.graph.showGrid(x=True, y=True) - # set max and min values for x and y axis - - # self.graph.resize(800, 600) def plot_line(self, data, color="r"): line_label = list(data.keys())[0] @@ -43,9 +39,6 @@ class Graph: self.xlist += x_data x_data = [date.split("2024-")[1] for date in x_data] xdict = dict(enumerate(x_data)) - # stringaxis_x = pg.AxisItem(orientation="bottom") - # stringaxis_x.setTicks([xdict.items()]) - # self.graph.getAxis("bottom").setTicks([xdict.items()]) global_xdict = self.xdict # remove all x values that are not in the xdict @@ -75,362 +68,3 @@ def launch(data): graph.graph.show() app.exec() - -if __name__ == "__main__": - data = [ - { - "t^1": { - "x": [ - "2024-04-04", - "2024-04-05", - "2024-04-06", - "2024-04-07", - "2024-04-08", - "2024-04-09", - "2024-04-10", - "2024-04-11", - "2024-04-12", - "2024-04-13", - "2024-04-14", - "2024-04-15", - "2024-04-16", - "2024-04-17", - "2024-04-18", - "2024-04-19", - "2024-04-20", - "2024-04-21", - "2024-04-22", - "2024-04-23", - "2024-04-24", - "2024-04-25", - "2024-04-26", - "2024-04-27", - "2024-04-28", - "2024-04-29", - "2024-04-30", - "2024-05-01", - "2024-05-02", - "2024-05-03", - "2024-05-04", - "2024-05-05", - "2024-05-06", - "2024-05-07", - "2024-05-08", - "2024-05-09", - "2024-05-10", - "2024-05-11", - "2024-05-12", - "2024-05-13", - "2024-05-14", - "2024-05-15", - "2024-05-16", - "2024-05-17", - "2024-05-18", - "2024-05-19", - "2024-05-20", - "2024-05-21", - "2024-05-22", - "2024-05-23", - "2024-05-24", - "2024-05-25", - "2024-05-26", - "2024-05-27", - "2024-05-28", - ], - "y": [ - 0, - 9.0, - 0, - 0, - 0, - 0, - 0, - 0, - 2.0, - 0, - 0, - 2.0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 2.0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 3.0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - } - }, - { - "t^2": { - "x": [ - "2024-04-04", - "2024-04-05", - "2024-04-06", - "2024-04-07", - "2024-04-08", - "2024-04-09", - "2024-04-10", - "2024-04-11", - "2024-04-12", - "2024-04-13", - "2024-04-14", - "2024-04-15", - "2024-04-16", - "2024-04-17", - "2024-04-18", - "2024-04-19", - "2024-04-20", - "2024-04-21", - "2024-04-22", - "2024-04-23", - "2024-04-24", - "2024-04-25", - "2024-04-26", - "2024-04-27", - "2024-04-28", - "2024-04-29", - "2024-04-30", - "2024-05-01", - "2024-05-02", - "2024-05-03", - "2024-05-04", - "2024-05-05", - "2024-05-06", - "2024-05-07", - "2024-05-08", - "2024-05-09", - "2024-05-10", - "2024-05-11", - "2024-05-12", - "2024-05-13", - "2024-05-14", - "2024-05-15", - "2024-05-16", - "2024-05-17", - "2024-05-18", - "2024-05-19", - "2024-05-20", - "2024-05-21", - "2024-05-22", - "2024-05-23", - "2024-05-24", - "2024-05-25", - "2024-05-26", - "2024-05-27", - "2024-05-28", - ], - "y": [ - 0, - 0, - 0, - 0, - 0, - 0, - 4.0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 4.0, - 0, - 0, - 6.0, - 0, - 2.0, - 2.0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 2.0, - 2.0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - } - }, - { - "t^3": { - "x": [ - "2024-04-04", - "2024-04-05", - "2024-04-06", - "2024-04-07", - "2024-04-08", - "2024-04-09", - "2024-04-10", - "2024-04-11", - "2024-04-12", - "2024-04-13", - "2024-04-14", - "2024-04-15", - "2024-04-16", - "2024-04-17", - "2024-04-18", - "2024-04-19", - "2024-04-20", - "2024-04-21", - "2024-04-22", - "2024-04-23", - "2024-04-24", - "2024-04-25", - "2024-04-26", - "2024-04-27", - "2024-04-28", - "2024-04-29", - "2024-04-30", - "2024-05-01", - "2024-05-02", - "2024-05-03", - "2024-05-04", - "2024-05-05", - "2024-05-06", - "2024-05-07", - "2024-05-08", - "2024-05-09", - "2024-05-10", - "2024-05-11", - "2024-05-12", - "2024-05-13", - "2024-05-14", - "2024-05-15", - "2024-05-16", - "2024-05-17", - "2024-05-18", - "2024-05-19", - "2024-05-20", - "2024-05-21", - "2024-05-22", - "2024-05-23", - "2024-05-24", - "2024-05-25", - "2024-05-26", - "2024-05-27", - "2024-05-28", - ], - "y": [ - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - ], - } - }, - ] - launch(data)