From 9534492f179fcfc4950e4f31b3e8257c07eb97ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 16 Jan 2023 19:39:24 +0100 Subject: [PATCH] Exclude manual times from graphs Fixes #35 --- CHANGELOG.md | 3 ++- src/web/common/util/plots.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13951d5..5d8d57c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ -## Unreleased +## 0.2.4 / 2023-01-16 19:39+01:00 * Fixed * When filtering by game, the "Filtering by (...)" text would erroneously list an unrelated platform * Playtime graph would display timeline backwards * Playtime graph with many dates would overlap (https://git.kucharczyk.xyz/lukas/timetracker/issues/34) + * Manually added times (= without end timestamp) would make graphs look ugly and noisy (https://git.kucharczyk.xyz/lukas/timetracker/issues/35) ## 0.2.3 / 2023-01-15 23:13+01:00 diff --git a/src/web/common/util/plots.py b/src/web/common/util/plots.py index 5bc6a1b..4bd258b 100644 --- a/src/web/common/util/plots.py +++ b/src/web/common/util/plots.py @@ -17,11 +17,12 @@ def key_value_to_value_value(data): def playtime_over_time_chart(queryset: QuerySet = Session.objects): microsecond_in_second = 1000000 result = ( - queryset.annotate(date=TruncDay("timestamp_start")) + queryset.exclude(timestamp_end__exact=None) + .annotate(date=TruncDay("timestamp_start")) .values("date") .annotate( hours=Sum( - F("duration_calculated") + F("duration_manual"), + F("duration_calculated"), output_field=IntegerField(), ) ) @@ -37,7 +38,12 @@ def playtime_over_time_chart(queryset: QuerySet = Session.objects): running_total += int(item["hours"] / (3600 * microsecond_in_second)) values.append(running_total) data = [keys, values] - return get_chart(data, title="Playtime over time", xlabel="Date", ylabel="Hours") + return get_chart( + data, + title="Playtime over time (manual excluded)", + xlabel="Date", + ylabel="Hours", + ) def get_graph():