From 779a76dd9289712b123362cbd9600b932729ce50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20X=2E=20F=C3=BCrst?= Date: Mon, 18 May 2026 09:53:00 +0200 Subject: [PATCH] V 1.5.7 fix: Tagesregen per MAX statt SUM (Server kumuliert selbst) Co-Authored-By: Claude Sonnet 4.6 --- api/main.py | 49 +++++++++++++++++++++++++------------------ frontend/package.json | 2 +- 2 files changed, 30 insertions(+), 21 deletions(-) diff --git a/api/main.py b/api/main.py index 41b52c2..524fa6f 100644 --- a/api/main.py +++ b/api/main.py @@ -270,11 +270,16 @@ async def get_weather_statistics( AVG(pressure) as avg_pressure, AVG(wind_speed * 1.60934) as avg_wind_speed, MAX(wind_gust * 1.60934) as max_wind_gust, - SUM(rain) as total_rain, + (SELECT COALESCE(SUM(daily_max), 0) FROM ( + SELECT MAX(rain) as daily_max + FROM weather_data + WHERE datetime >= NOW() - make_interval(hours => %s) + GROUP BY DATE(datetime) + ) sub) as total_rain, COUNT(*) as data_points FROM weather_data WHERE datetime >= NOW() - make_interval(hours => %s) - """, (hours,)) + """, (hours, hours)) result = cursor.fetchone() if not result or result['data_points'] == 0: @@ -300,7 +305,7 @@ async def get_daily_statistics( AVG(pressure) as avg_pressure, AVG(wind_speed * 1.60934) as avg_wind_speed, MAX(wind_gust * 1.60934) as max_wind_gust, - SUM(rain) as total_rain, + MAX(rain) as total_rain, COUNT(*) as data_points FROM weather_data WHERE datetime >= NOW() - make_interval(days => %s) @@ -429,14 +434,14 @@ async def get_daily_aggregated_data( MAX(wind_gust * 1.60934)::float as wind_gust, (array_agg(datetime ORDER BY wind_gust DESC NULLS LAST))[1] as max_wind_gust_time, AVG(wind_dir)::float as wind_dir, - SUM(rain)::float as total_rain + MAX(rain)::float as total_rain FROM weather_data WHERE datetime >= NOW() - make_interval(days => %s) GROUP BY date_trunc('day', datetime) ORDER BY datetime ASC """, (days,)) results = cursor.fetchall() - + return [dict(row) for row in results] @@ -469,7 +474,7 @@ async def get_daily_with_minmax_data( MAX(wind_gust * 1.60934)::float as wind_gust, (array_agg(datetime ORDER BY wind_gust DESC NULLS LAST))[1] as max_wind_gust_time, AVG(wind_dir)::float as wind_dir, - SUM(rain)::float as total_rain + MAX(rain)::float as total_rain FROM weather_data WHERE datetime >= NOW() - make_interval(days => %s) GROUP BY date_trunc('day', datetime) @@ -488,9 +493,9 @@ async def get_daily_rain_data( """Gibt tägliche Regensummen zurück""" with conn.cursor() as cursor: cursor.execute(""" - SELECT + SELECT date_trunc('day', datetime) as date, - SUM(rain) as total_rain + MAX(rain) as total_rain FROM weather_data WHERE datetime >= NOW() - make_interval(days => %s) GROUP BY date_trunc('day', datetime) @@ -511,21 +516,25 @@ async def get_weekly_rain_data( # Bei 365 Tagen: alle verfügbaren Daten zurückgeben if days >= 365: cursor.execute(""" - SELECT - date_trunc('week', datetime) as week_start, - SUM(rain) as total_rain - FROM weather_data - GROUP BY date_trunc('week', datetime) + SELECT week_start, SUM(daily_max) as total_rain + FROM ( + SELECT date_trunc('week', datetime) as week_start, MAX(rain) as daily_max + FROM weather_data + GROUP BY date_trunc('week', datetime), DATE(datetime) + ) sub + GROUP BY week_start ORDER BY week_start ASC """) else: cursor.execute(""" - SELECT - date_trunc('week', datetime) as week_start, - SUM(rain) as total_rain - FROM weather_data - WHERE datetime >= NOW() - make_interval(days => %s) - GROUP BY date_trunc('week', datetime) + SELECT week_start, SUM(daily_max) as total_rain + FROM ( + SELECT date_trunc('week', datetime) as week_start, MAX(rain) as daily_max + FROM weather_data + WHERE datetime >= NOW() - make_interval(days => %s) + GROUP BY date_trunc('week', datetime), DATE(datetime) + ) sub + GROUP BY week_start ORDER BY week_start ASC """, (days,)) results = cursor.fetchall() @@ -596,7 +605,7 @@ async def get_daily_aggregated_range( MAX(wind_gust * 1.60934)::float as wind_gust, (array_agg(datetime ORDER BY wind_gust DESC NULLS LAST))[1] as max_wind_gust_time, AVG(wind_dir)::float as wind_dir, - SUM(rain)::float as total_rain + MAX(rain)::float as total_rain FROM weather_data WHERE datetime BETWEEN %s AND %s GROUP BY date_trunc('day', datetime) diff --git a/frontend/package.json b/frontend/package.json index eaceaed..d99ff59 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -1,7 +1,7 @@ { "name": "wetterstation-frontend", "private": true, - "version": "1.5.6", + "version": "1.5.7", "type": "module", "scripts": { "dev": "vite",