diff --git a/CHANGELOG.md b/CHANGELOG.md index 7824f36..8e81e0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * game overview: * sort purchases also by date purchased (on top of date released) * improve header format + * ignore manual sessions when calculating session average * stats: improve purchase name consistency * session list: use display name instead of sort name diff --git a/games/models.py b/games/models.py index 4288f58..da039cd 100644 --- a/games/models.py +++ b/games/models.py @@ -152,6 +152,19 @@ class SessionQuerySet(models.QuerySet): ) return result["duration"] + def calculated_duration_formatted(self): + return format_duration(self.calculated_duration_unformatted()) + + def calculated_duration_unformatted(self): + result = self.aggregate(duration=Sum(F("duration_calculated"))) + return result["duration"] + + def without_manual(self): + return self.exclude(duration_calculated__iexact=0) + + def only_manual(self): + return self.filter(duration_calculated__iexact=0) + class Session(models.Model): class Meta: diff --git a/games/templates/view_game.html b/games/templates/view_game.html index 35061af..422770f 100644 --- a/games/templates/view_game.html +++ b/games/templates/view_game.html @@ -14,7 +14,7 @@

First Released: {{ game.year_released }}

Playtime: - {{ hours_sum }} hours over {{ session_count }} sessions ({{ session_average }}/session) + {{ hours_sum }} hours over {{ session_count }} sessions ({{ session_average_without_manual }}/session)

Played in: diff --git a/games/views.py b/games/views.py index 8a3250c..94536d0 100644 --- a/games/views.py +++ b/games/views.py @@ -175,6 +175,9 @@ def view_game(request, game_id=None): purchase__edition__game=game ) session_count = sessions.count() + session_count_without_manual = ( + Session.objects.without_manual().filter(purchase__edition__game=game).count() + ) playrange_start = sessions.earliest().timestamp_start.strftime("%b %Y") latest_session = sessions.latest() @@ -186,7 +189,9 @@ def view_game(request, game_id=None): else f"{playrange_start} — {playrange_end}" ) total_hours = float(format_duration(sessions.total_duration_unformatted(), "%2.1H")) - + total_hours_without_manual = float( + format_duration(sessions.calculated_duration_unformatted(), "%2.1H") + ) context = { "edition_count": editions.count(), "editions": editions, @@ -194,6 +199,9 @@ def view_game(request, game_id=None): "playrange": playrange, "purchase_count": Purchase.objects.filter(edition__game=game).count(), "session_average": round(total_hours / int(session_count), 1), + "session_average_without_manual": round( + total_hours_without_manual / int(session_count_without_manual), 1 + ), "session_count": session_count, "sessions_with_notes_count": sessions.exclude(note="").count(), "sessions": sessions.order_by("-timestamp_start"),