modified: __pycache__/app.cpython-310.pyc

modified:   app.py
	modified:   templates/weather.html
This commit is contained in:
SimolZimol
2026-04-21 09:32:33 +02:00
parent 882d8eaf33
commit fc456ae2ac
3 changed files with 25 additions and 6 deletions

Binary file not shown.

13
app.py
View File

@@ -5,6 +5,7 @@ from geopy.exc import GeocoderTimedOut
import math import math
import traceback import traceback
import pandas as pd import pandas as pd
import datetime as _dt
from wetterdienst.provider.dwd.mosmix import DwdMosmixRequest from wetterdienst.provider.dwd.mosmix import DwdMosmixRequest
@@ -199,7 +200,15 @@ def wetter():
station_lon = float(mosmix_station.get("longitude", lon)) station_lon = float(mosmix_station.get("longitude", lon))
station_dist = round(haversine(lat, lon, station_lat, station_lon), 1) 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] 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 # Tageszusammenfassung
daily = {} daily = {}
@@ -233,7 +242,7 @@ def wetter():
}) })
# Chart-Daten (erste 48 h) # 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]: for h in forecast[:48]:
dt = h["datetime"] dt = h["datetime"]
label = (dt.strftime("%d.%m %H:%M") if hasattr(dt, "strftime") label = (dt.strftime("%d.%m %H:%M") if hasattr(dt, "strftime")
@@ -241,6 +250,7 @@ def wetter():
chart_labels.append(label) chart_labels.append(label)
chart_temps.append(h["temp_c"]) chart_temps.append(h["temp_c"])
chart_precip.append(h.get("precip_mm") or 0) chart_precip.append(h.get("precip_mm") or 0)
chart_rain_prob.append(h.get("rain_prob") or 0)
return render_template( return render_template(
"weather.html", "weather.html",
@@ -257,6 +267,7 @@ def wetter():
chart_labels=chart_labels, chart_labels=chart_labels,
chart_temps=chart_temps, chart_temps=chart_temps,
chart_precip=chart_precip, chart_precip=chart_precip,
chart_rain_prob=chart_rain_prob,
wind_dir_name=wind_direction_name, wind_dir_name=wind_direction_name,
) )

View File

@@ -45,8 +45,8 @@
{% set items = [ {% set items = [
("Gefühlt wie", (current.temp_c|string + " °C") if current.temp_c is not none else ""), ("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 ""), ("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"), ("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 else ""), ("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 %} {% for label, val in items %}
<div class="hero-metric"> <div class="hero-metric">
@@ -174,6 +174,13 @@
const labels = {{ chart_labels | tojson }}; const labels = {{ chart_labels | tojson }};
const temps = {{ chart_temps | tojson }}; const temps = {{ chart_temps | tojson }};
const precip = {{ chart_precip | 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 // Nur jeden 3. Label anzeigen, Rest leer lassen
const sparseLabels = labels.map((l, i) => i % 3 === 0 ? l : ""); const sparseLabels = labels.map((l, i) => i % 3 === 0 ? l : "");
@@ -205,8 +212,8 @@
}, },
{ {
type: "bar", type: "bar",
label: "Niederschlag (mm)", label: barLabel,
data: precip, data: barData,
backgroundColor: "rgba(80,180,255,0.55)", backgroundColor: "rgba(80,180,255,0.55)",
borderColor: "rgba(80,180,255,0.9)", borderColor: "rgba(80,180,255,0.9)",
borderWidth: 1, borderWidth: 1,
@@ -254,7 +261,8 @@
yR: { yR: {
position: "right", position: "right",
min: 0, 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 } grid: { display: false }
} }
} }