From 3ee36932c3268e12eb826489327f700a43f52c42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Thu, 2 Nov 2023 09:17:08 +0100 Subject: [PATCH] Limit stats of single year correctly --- CHANGELOG.md | 5 +++++ games/views.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4319fb..68cb264 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased + +### Fixed +* Correctly limit sessions to a single year for stats + ## 1.2.0 / 2023-11-01 20:18+01:00 ### New diff --git a/games/views.py b/games/views.py index b6d123b..34076c0 100644 --- a/games/views.py +++ b/games/views.py @@ -232,7 +232,10 @@ def list_sessions( def stats(request, year: int): first_day_of_year = datetime(year, 1, 1) - year_sessions = Session.objects.filter(timestamp_start__gte=first_day_of_year) + last_day_of_year = datetime(year + 1, 1, 1) + year_sessions = Session.objects.filter( + timestamp_start__gte=first_day_of_year + ).filter(timestamp_start__lt=last_day_of_year) year_purchases = Purchase.objects.filter(session__in=year_sessions).distinct() year_purchases_with_playtime = year_purchases.annotate( total_playtime=Sum(