From 73325099766c952c6c66d91b6a5b89f5e65fc2b0 Mon Sep 17 00:00:00 2001 From: stepan323446 Date: Fri, 19 Dec 2025 10:09:36 +0100 Subject: [PATCH] Fixed period api --- weather/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/weather/views.py b/weather/views.py index 984ab3f..5790554 100644 --- a/weather/views.py +++ b/weather/views.py @@ -116,29 +116,32 @@ class StatsByPeriodAPI(APIView): elif period == WeatherPeriods.hour: start_time = now - timedelta(hours=1) trunc_func = TruncMinute - step = 10 + step = 1 elif period == WeatherPeriods.hour_6: start_time = now - timedelta(hours=6) trunc_func = TruncHour + step = 1 elif period == WeatherPeriods.hour_12: start_time = now - timedelta(hours=12) trunc_func = TruncHour + step = 1 elif period == WeatherPeriods.hour_24: start_time = now - timedelta(hours=24) trunc_func = TruncHour + step = 1 qs = ( WeatherStats.objects .filter(created_at__gte=start_time) - .annotate(time_slot=trunc_func('created_at')) - .values('time_slot') + .annotate(date=trunc_func('created_at')) + .values('date') .annotate( humidity_air=Avg('humidity_air'), humidity_ground=Avg('humidity_ground'), temperature=Avg('temperature'), light=Avg('light') ) - .order_by('-time_slot') + .order_by('-date') ) data_dict = {entry['date']: entry for entry in qs}