2
0
Fork 0

Add metrics related to fallback assignments

This commit is contained in:
Luca 2023-05-14 22:53:50 +02:00
parent aef78ce251
commit c4e30c83a1
1 changed files with 33 additions and 0 deletions

View File

@ -2,6 +2,8 @@ from django.db import models
from django.db.models import Count, Case, F, When, Sum from django.db.models import Count, Case, F, When, Sum
from django.http import HttpResponse from django.http import HttpResponse
from shiftregister.app.models import Helper, Room, Shift, ShiftRegistration, Message from shiftregister.app.models import Helper, Room, Shift, ShiftRegistration, Message
from shiftregister.fallback.models import FallbackAssignment
from shiftregister.importer.models import Event
def metrics(request): def metrics(request):
@ -14,6 +16,37 @@ def metrics(request):
( (
f"shiftregister_{name} {value}" f"shiftregister_{name} {value}"
for name, value in ( for name, value in (
(
"fallback_shifts",
Event.objects.filter(
deleted=False, calendar__needs_fallback=True
).count(),
),
(
"fallback_shifts_assigned",
FallbackAssignment.objects.aggregate(
count=Count("shift", distinct=True)
)["count"],
),
(
"fallback_shifts_full",
Shift.with_reg_count()
.annotate(
real_required_helpers=Case(
When(
required_helpers=0, then=F("room__required_helpers")
),
default=F("required_helpers"),
),
fallbackassignment_count=Count("fallbackassignment"),
)
.filter(
deleted=False,
reg_count__gte=F("real_required_helpers"),
fallbackassignment_count__gt=0,
)
.count(),
),
("helpers_total", Helper.objects.count()), ("helpers_total", Helper.objects.count()),
( (
"helpers_confirmed_total", "helpers_confirmed_total",