Add metrics related to fallback assignments
This commit is contained in:
parent
aef78ce251
commit
c4e30c83a1
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue