update readme

This commit is contained in:
WorldTeacher
2024-10-21 12:50:10 +02:00
parent 8b3ae27e5a
commit 8a1676f318
3 changed files with 29 additions and 369 deletions

View File

@@ -1,3 +1,29 @@
# ZSDiagram # ZSDiagram
a small application to display graphs of Sensor data collected by Homassistant and formatted in a certain way 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. ...

BIN
requirements.txt Normal file

Binary file not shown.

View File

@@ -3,7 +3,7 @@ from PyQt6 import QtWidgets
class Graph: class Graph:
def __init__(self, data: dict | list): def __init__(self, data: list):
self.xlist = [] self.xlist = []
if isinstance(data, dict): if isinstance(data, dict):
self.xlist += data[list(data.keys())[0]]["x"] self.xlist += data[list(data.keys())[0]]["x"]
@@ -21,7 +21,7 @@ class Graph:
stringaxis_x.setTicks([xdict.items()]) stringaxis_x.setTicks([xdict.items()])
self.graph = pg.PlotWidget(axisItems={"bottom": stringaxis_x}) self.graph = pg.PlotWidget(axisItems={"bottom": stringaxis_x})
# self.graph.("Zeitschriftennutzung") # 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.setLabel("bottom", "Datum")
self.graph.addLegend() self.graph.addLegend()
@@ -30,12 +30,8 @@ class Graph:
self.plot_lines(data) self.plot_lines(data)
else: else:
self.plot_line(data) self.plot_line(data)
# remove duplicate x values
self.graph.showGrid(x=True, y=True) 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"): def plot_line(self, data, color="r"):
line_label = list(data.keys())[0] line_label = list(data.keys())[0]
@@ -43,9 +39,6 @@ class Graph:
self.xlist += x_data self.xlist += x_data
x_data = [date.split("2024-")[1] for date in x_data] x_data = [date.split("2024-")[1] for date in x_data]
xdict = dict(enumerate(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 global_xdict = self.xdict
# remove all x values that are not in the xdict # remove all x values that are not in the xdict
@@ -75,362 +68,3 @@ def launch(data):
graph.graph.show() graph.graph.show()
app.exec() 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)