2
0
Fork 0

Add 'helpers_required_total' metric

This commit is contained in:
Luca 2023-05-08 18:00:45 +02:00
parent a34f568083
commit 36cc1a5fec
1 changed files with 14 additions and 3 deletions

View File

@ -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(),