Fix errors caused by empty values
Django CI/CD / test (push) Successful in 1m10s Details
Django CI/CD / build-and-push (push) Successful in 1m41s Details

This commit is contained in:
Lukáš Kucharczyk 2024-01-01 18:21:50 +01:00
parent d9fbb4b896
commit 8466f67c86
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
1 changed files with 20 additions and 8 deletions

View File

@ -328,7 +328,10 @@ def stats(request, year: int = 0):
) )
) )
longest_session = this_year_sessions_with_durations.order_by("-duration").first() longest_session = this_year_sessions_with_durations.order_by("-duration").first()
this_year_games_with_session_counts = Game.objects.annotate( this_year_games = Game.objects.filter(
edition__purchase__session__in=this_year_sessions
).distinct()
this_year_games_with_session_counts = this_year_games.annotate(
session_count=Count( session_count=Count(
"edition__purchase__session", "edition__purchase__session",
filter=Q(edition__purchase__session__timestamp_start__year=year), filter=Q(edition__purchase__session__timestamp_start__year=year),
@ -469,15 +472,24 @@ def stats(request, year: int = 0):
), ),
"backlog_decrease_count": backlog_decrease_count, "backlog_decrease_count": backlog_decrease_count,
"longest_session_time": format_duration( "longest_session_time": format_duration(
longest_session.duration if longest_session else timedelta(0), longest_session.duration, "%2.0Hh %2.0mm"
"%2.0Hh %2.0mm", )
), if longest_session
"longest_session_game": longest_session.purchase.edition.name, else 0,
"highest_session_count": game_highest_session_count.session_count, "longest_session_game": longest_session.purchase.edition.name
"highest_session_count_game": game_highest_session_count.name, if longest_session
else "N/A",
"highest_session_count": game_highest_session_count.session_count
if game_highest_session_count
else 0,
"highest_session_count_game": game_highest_session_count.name
if game_highest_session_count
else "N/A",
"highest_session_average": format_duration( "highest_session_average": format_duration(
highest_session_average_game.session_average, "%2.0Hh %2.0mm" highest_session_average_game.session_average, "%2.0Hh %2.0mm"
), )
if highest_session_average_game
else 0,
"highest_session_average_game": highest_session_average_game, "highest_session_average_game": highest_session_average_game,
"title": f"{year} Stats", "title": f"{year} Stats",
} }