From c4e30c83a1326dfc8062cb37ad09054ec748629a Mon Sep 17 00:00:00 2001 From: Luca Date: Sun, 14 May 2023 22:53:50 +0200 Subject: [PATCH] Add metrics related to fallback assignments --- shiftregister/metrics/views.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/shiftregister/metrics/views.py b/shiftregister/metrics/views.py index b8dc289..f584030 100644 --- a/shiftregister/metrics/views.py +++ b/shiftregister/metrics/views.py @@ -2,6 +2,8 @@ from django.db import models from django.db.models import Count, Case, F, When, Sum from django.http import HttpResponse 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): @@ -14,6 +16,37 @@ def metrics(request): ( f"shiftregister_{name} {value}" 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_confirmed_total",