Add 'helpers_required_total' metric

pull/1/head
Luca 2 years ago
parent a34f568083
commit 36cc1a5fec

@ -1,7 +1,8 @@
from django.http import HttpResponse
from shiftregister.app.models import Helper, ShiftRegistration, Message
from django.db.models import Count, Case, When, Sum
from django.db import models from django.db import models
from django.db.models import Count, Case, F, When, Sum
from django.db.models.functions import Coalesce
from django.http import HttpResponse
from shiftregister.app.models import Helper, Shift, ShiftRegistration, Message
def metrics(request): def metrics(request):
@ -37,6 +38,16 @@ def metrics(request):
.filter(number_validated=True, shift_count__gte=1) .filter(number_validated=True, shift_count__gte=1)
.count(), .count(),
), ),
(
"helpers_required_total",
Shift.objects.filter(deleted=False)
.annotate(
real_required_helpers=Coalesce(
F("required_helpers"), F("room__required_helpers")
)
)
.aggregate(sum=Sum("real_required_helpers"))["sum"],
),
( (
"messages_sent_total", "messages_sent_total",
Message.objects.all().count(), Message.objects.all().count(),

Loading…
Cancel
Save