diff --git a/gibil/classes/weather_store.py b/gibil/classes/weather_store.py index 3c10378..a6db1d8 100644 --- a/gibil/classes/weather_store.py +++ b/gibil/classes/weather_store.py @@ -216,8 +216,20 @@ class WeatherStore: temperature_c, shortwave_radiation_w_m2, cloud_cover_pct - FROM weather_forecast_points - WHERE target_at >= %s AND target_at <= %s + FROM ( + SELECT + issued_at, + target_at, + horizon_hours, + source, + temperature_c, + shortwave_radiation_w_m2, + cloud_cover_pct, + ROW_NUMBER() OVER (PARTITION BY target_at, horizon_hours ORDER BY issued_at DESC) as rn + FROM weather_forecast_points + WHERE target_at >= %s AND target_at <= %s + ) as ranked + WHERE rn = 1 ORDER BY target_at, horizon_hours LIMIT 5000 """,