diff --git a/__pycache__/app.cpython-310.pyc b/__pycache__/app.cpython-310.pyc index 3ac5196..bf6f1a2 100644 Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ diff --git a/app.py b/app.py index 14dc439..24d3f5c 100644 --- a/app.py +++ b/app.py @@ -5,6 +5,7 @@ from geopy.exc import GeocoderTimedOut import math import traceback import pandas as pd +import datetime as _dt from wetterdienst.provider.dwd.mosmix import DwdMosmixRequest @@ -199,7 +200,15 @@ def wetter(): station_lon = float(mosmix_station.get("longitude", lon)) station_dist = round(haversine(lat, lon, station_lat, station_lon), 1) + # "Aktuell" = erste Stunde >= jetzt (UTC), sonst erste verfügbare + now_utc = _dt.datetime.now(_dt.timezone.utc).replace(tzinfo=None) current = forecast[0] + for h in forecast: + dt = h["datetime"] + dt_naive = dt.replace(tzinfo=None) if hasattr(dt, "tzinfo") and dt.tzinfo is not None else dt + if dt_naive >= now_utc: + current = h + break # Tageszusammenfassung daily = {} @@ -233,7 +242,7 @@ def wetter(): }) # Chart-Daten (erste 48 h) - chart_labels, chart_temps, chart_precip = [], [], [] + chart_labels, chart_temps, chart_precip, chart_rain_prob = [], [], [], [] for h in forecast[:48]: dt = h["datetime"] label = (dt.strftime("%d.%m %H:%M") if hasattr(dt, "strftime") @@ -241,6 +250,7 @@ def wetter(): chart_labels.append(label) chart_temps.append(h["temp_c"]) chart_precip.append(h.get("precip_mm") or 0) + chart_rain_prob.append(h.get("rain_prob") or 0) return render_template( "weather.html", @@ -257,6 +267,7 @@ def wetter(): chart_labels=chart_labels, chart_temps=chart_temps, chart_precip=chart_precip, + chart_rain_prob=chart_rain_prob, wind_dir_name=wind_direction_name, ) diff --git a/templates/weather.html b/templates/weather.html index e85f54c..e460f57 100644 --- a/templates/weather.html +++ b/templates/weather.html @@ -45,8 +45,8 @@ {% set items = [ ("Gefühlt wie", (current.temp_c|string + " °C") if current.temp_c is not none else "–"), ("Böen", (current.gust_kmh|string + " km/h") if current.gust_kmh is not none else "–"), - ("Niederschlag", (current.precip_mm|string + " mm") if current.precip_mm is not none else "0 mm"), - ("Sonne", (current.sun_min|string + " min/h") if current.sun_min is not none else "–"), + ("Niederschlag", (current.precip_mm|string + " mm") if (current.precip_mm is not none and current.precip_mm > 0) else ((current.rain_prob|string + " %") if (current.rain_prob is not none and current.rain_prob > 0) else "0 mm")), + ("Sonne", (current.sun_min|string + " min/h") if (current.sun_min is not none and current.sun_min > 0) else "–"), ] %} {% for label, val in items %}
@@ -174,6 +174,13 @@ const labels = {{ chart_labels | tojson }}; const temps = {{ chart_temps | tojson }}; const precip = {{ chart_precip | tojson }}; + const rainProb = {{ chart_rain_prob | tojson }}; + + // Prüfen ob echte Niederschlagsmengen vorhanden sind + const hasRealPrecip = precip.some(v => v > 0); + const barData = hasRealPrecip ? precip : rainProb; + const barLabel = hasRealPrecip ? "Niederschlag (mm)" : "Regenwahrsch. (%)"; + const barMax = hasRealPrecip ? undefined : 100; // Nur jeden 3. Label anzeigen, Rest leer lassen const sparseLabels = labels.map((l, i) => i % 3 === 0 ? l : ""); @@ -205,8 +212,8 @@ }, { type: "bar", - label: "Niederschlag (mm)", - data: precip, + label: barLabel, + data: barData, backgroundColor: "rgba(80,180,255,0.55)", borderColor: "rgba(80,180,255,0.9)", borderWidth: 1, @@ -254,7 +261,8 @@ yR: { position: "right", min: 0, - ticks: { color: "#50b4ff", font: { family: "Inter", size: 11 }, callback: v => v + "mm" }, + ...(barMax !== undefined ? { max: barMax } : {}), + ticks: { color: "#50b4ff", font: { family: "Inter", size: 11 }, callback: v => hasRealPrecip ? v + "mm" : v + "%" }, grid: { display: false } } }