Ignore manual sessions when calculating session average
Django CI/CD / test (push) Successful in 1m0s Details
Django CI/CD / build-and-push (push) Successful in 2m2s Details

This commit is contained in:
Lukáš Kucharczyk 2024-07-02 17:14:56 +02:00
parent fe6cf2758c
commit 588e52aba2
Signed by: lukas
SSH Key Fingerprint: SHA256:vMuSwvwAvcT6htVAioMP7rzzwMQNi3roESyhv+nAxeg
4 changed files with 24 additions and 2 deletions

View File

@ -12,6 +12,7 @@
* game overview: * game overview:
* sort purchases also by date purchased (on top of date released) * sort purchases also by date purchased (on top of date released)
* improve header format * improve header format
* ignore manual sessions when calculating session average
* stats: improve purchase name consistency * stats: improve purchase name consistency
* session list: use display name instead of sort name * session list: use display name instead of sort name

View File

@ -152,6 +152,19 @@ class SessionQuerySet(models.QuerySet):
) )
return result["duration"] 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 Session(models.Model):
class Meta: class Meta:

View File

@ -14,7 +14,7 @@
<h2 class="text-lg my-2 ml-2 dark:text-slate-500">First Released: <span class="text-white">{{ game.year_released }}</span></h2> <h2 class="text-lg my-2 ml-2 dark:text-slate-500">First Released: <span class="text-white">{{ game.year_released }}</span></h2>
<h2 class="text-lg my-2 ml-2"> <h2 class="text-lg my-2 ml-2">
<span class="dark:text-slate-500">Playtime: </span> <span class="dark:text-slate-500">Playtime: </span>
{{ hours_sum }} <span class="dark:text-slate-500">hours over</span> {{ session_count }} <span class="dark:text-slate-500">sessions (</span>{{ session_average }}<span class="dark:text-slate-500">/session)</span> {{ hours_sum }} <span class="dark:text-slate-500">hours over</span> {{ session_count }} <span class="dark:text-slate-500">sessions (</span>{{ session_average_without_manual }}<span class="dark:text-slate-500">/session)</span>
</h2> </h2>
<h2 class="text-lg my-2 ml-2"> <h2 class="text-lg my-2 ml-2">
<span class="dark:text-slate-500">Played in: </span> <span class="dark:text-slate-500">Played in: </span>

View File

@ -175,6 +175,9 @@ def view_game(request, game_id=None):
purchase__edition__game=game purchase__edition__game=game
) )
session_count = sessions.count() 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") playrange_start = sessions.earliest().timestamp_start.strftime("%b %Y")
latest_session = sessions.latest() latest_session = sessions.latest()
@ -186,7 +189,9 @@ def view_game(request, game_id=None):
else f"{playrange_start}{playrange_end}" else f"{playrange_start}{playrange_end}"
) )
total_hours = float(format_duration(sessions.total_duration_unformatted(), "%2.1H")) 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 = { context = {
"edition_count": editions.count(), "edition_count": editions.count(),
"editions": editions, "editions": editions,
@ -194,6 +199,9 @@ def view_game(request, game_id=None):
"playrange": playrange, "playrange": playrange,
"purchase_count": Purchase.objects.filter(edition__game=game).count(), "purchase_count": Purchase.objects.filter(edition__game=game).count(),
"session_average": round(total_hours / int(session_count), 1), "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, "session_count": session_count,
"sessions_with_notes_count": sessions.exclude(note="").count(), "sessions_with_notes_count": sessions.exclude(note="").count(),
"sessions": sessions.order_by("-timestamp_start"), "sessions": sessions.order_by("-timestamp_start"),