diff --git a/shiftregister/metrics/views.py b/shiftregister/metrics/views.py index 25a73d8..8a9cc6c 100644 --- a/shiftregister/metrics/views.py +++ b/shiftregister/metrics/views.py @@ -5,6 +5,10 @@ from django.db import models def metrics(request): + worked_seconds_total = ShiftRegistration.objects.filter( + state=ShiftRegistration.RegState.CHECKED_IN + ).aggregate(sum=Sum("shift__duration"))["sum"] + response = HttpResponse( "\n".join( ( @@ -37,20 +41,18 @@ def metrics(request): "messages_sent_total", Message.objects.all().count(), ), + ( + "worked_seconds_total", + worked_seconds_total.total_seconds() + if worked_seconds_total + else 0.0, + ), ( "worked_shifts_total", ShiftRegistration.objects.filter( state=ShiftRegistration.RegState.CHECKED_IN ).count(), ), - ( - "worked_seconds_total", - ShiftRegistration.objects.filter( - state=ShiftRegistration.RegState.CHECKED_IN - ) - .aggregate(sum=Sum("shift__duration"))["sum"] - .total_seconds(), - ), ) ) )