diff --git a/scripts/meter_reading_dashboard.form.json b/scripts/meter_reading_dashboard.form.json new file mode 100644 index 0000000..fc85e1e --- /dev/null +++ b/scripts/meter_reading_dashboard.form.json @@ -0,0 +1,46 @@ +{ + "title": "Messwerte Dashboard", + "description": "Messwerte fuer eine Zaehlernummer der letzten 3 Monate als interaktive Grafik", + "fields": [ + { + "name": "meter_number", + "widget": "text_field", + "label": "Zaehlernummer", + "hint_text": "z.B. Z-12345", + "prefix_icon": "search", + "validators": [{"type": "required", "error_text": "Zaehlernummer ist erforderlich"}] + }, + { + "name": "chart_type", + "widget": "dropdown", + "label": "Diagrammtyp", + "initial_value": "line", + "options": [ + {"value": "line", "label": "Linie"}, + {"value": "bar", "label": "Balken"}, + {"value": "radar", "label": "Radar"}, + {"value": "doughnut", "label": "Donut"}, + {"value": "pie", "label": "Torte"} + ] + }, + { + "name": "group_by", + "widget": "segmented_control", + "label": "Gruppierung", + "initial_value": "hour", + "options": [ + {"value": "hour", "label": "Stunde"}, + {"value": "day", "label": "Tag"}, + {"value": "week", "label": "Woche"}, + {"value": "month", "label": "Monat"} + ] + }, + { + "name": "include_statistics", + "widget": "switch_field", + "label": "Statistiken anzeigen", + "initial_value": true + } + ], + "submit_label": "Dashboard erstellen" +} diff --git a/scripts/meter_reading_dashboard.py b/scripts/meter_reading_dashboard.py index 0dbc901..65e332b 100644 --- a/scripts/meter_reading_dashboard.py +++ b/scripts/meter_reading_dashboard.py @@ -5,12 +5,10 @@ from datetime import datetime, timedelta import httpx -# === PARAMETER START === -METER_NUMBER = "" -CHART_TYPE = "line" # options: line,bar,radar,doughnut,pie -GROUP_BY = "hour" # options: hour,day,week,month -INCLUDE_STATISTICS = True -# === PARAMETER ENDE === +METER_NUMBER = PARAMS["meter_number"] +CHART_TYPE = PARAMS.get("chart_type", "line") +GROUP_BY = PARAMS.get("group_by", "hour") +INCLUDE_STATISTICS = PARAMS.get("include_statistics", True) FIND_SENSORS_QUERY = """ query FindSensors($meterNumber: String!) { @@ -443,8 +441,7 @@ def build_report(): try: - result = build_report() + html_output = build_report() + result = {"type": "html", "content": html_output} except Exception as exc: - result = build_message(f"Allgemeiner Fehler: {exc}", "error") - -print(result) + result = {"type": "html", "content": build_message(f"Allgemeiner Fehler: {exc}", "error")} diff --git a/scripts/sensor_list_report.py b/scripts/sensor_list_report.py index 2a5ea77..c5ef00a 100644 --- a/scripts/sensor_list_report.py +++ b/scripts/sensor_list_report.py @@ -432,5 +432,5 @@ def build_report(): return html_output -result = build_report() -print(result) +html_output = build_report() +result = {"type": "html", "content": html_output}