Limit stats of single year correctly

This commit is contained in:
Lukáš Kucharczyk 2023-11-02 09:17:08 +01:00
parent 391fcc79a8
commit 3ee36932c3
2 changed files with 9 additions and 1 deletions

View File

@ -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 ## 1.2.0 / 2023-11-01 20:18+01:00
### New ### New

View File

@ -232,7 +232,10 @@ def list_sessions(
def stats(request, year: int): def stats(request, year: int):
first_day_of_year = datetime(year, 1, 1) 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 = Purchase.objects.filter(session__in=year_sessions).distinct()
year_purchases_with_playtime = year_purchases.annotate( year_purchases_with_playtime = year_purchases.annotate(
total_playtime=Sum( total_playtime=Sum(