Ignore manual sessions when calculating session average
This commit is contained in:
parent
fe6cf2758c
commit
811fec4b11
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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,14 +189,21 @@ 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,
|
||||||
"game": game,
|
"game": game,
|
||||||
"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_without_manual": round(
|
||||||
|
safe_division(
|
||||||
|
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"),
|
||||||
|
|
Loading…
Reference in New Issue