diff --git a/shiftregister/metrics/views.py b/shiftregister/metrics/views.py index 8a9cc6c..97ccac9 100644 --- a/shiftregister/metrics/views.py +++ b/shiftregister/metrics/views.py @@ -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.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): @@ -37,6 +38,16 @@ def metrics(request): .filter(number_validated=True, shift_count__gte=1) .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", Message.objects.all().count(),