From 1999f13cf2571842235e6a221a7719aae4d313db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 1 Jan 2024 18:42:14 +0100 Subject: [PATCH] stats: add first and last play --- games/templates/stats.html | 8 ++++++++ games/views.py | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/games/templates/stats.html b/games/templates/stats.html index c6977b9..0dbe718 100644 --- a/games/templates/stats.html +++ b/games/templates/stats.html @@ -63,6 +63,14 @@ {{ highest_session_average }} ({{ highest_session_average_game }}) + + First play + {{ first_play_name }} ({{ first_play_date }}) + + + Last play + {{ last_play_name }} ({{ last_play_date }}) +

Purchases

diff --git a/games/views.py b/games/views.py index 114e3e5..89ad61b 100644 --- a/games/views.py +++ b/games/views.py @@ -428,6 +428,18 @@ def stats(request, year: int = 0): .count() ) + first_play_name = "N/A" + first_play_date = "N/A" + last_play_name = "N/A" + last_play_date = "N/A" + if this_year_sessions: + first_session = this_year_sessions.earliest() + first_play_name = first_session.purchase.edition.name + first_play_date = first_session.timestamp_start.strftime("%x") + last_session = this_year_sessions.latest() + last_play_name = last_session.purchase.edition.name + last_play_date = last_session.timestamp_start.strftime("%x") + context = { "total_hours": format_duration( this_year_sessions.total_duration_unformatted(), "%2.0H" @@ -491,6 +503,10 @@ def stats(request, year: int = 0): if highest_session_average_game else 0, "highest_session_average_game": highest_session_average_game, + "first_play_name": first_play_name, + "first_play_date": first_play_date, + "last_play_name": last_play_name, + "last_play_date": last_play_date, "title": f"{year} Stats", }