2
0
Fork 0

Add per-room shift count metrics

This commit is contained in:
Luca 2023-05-09 23:24:31 +02:00
parent ad52a9b9fe
commit d5137f78f1
1 changed files with 39 additions and 1 deletions

View File

@ -1,7 +1,7 @@
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, Shift, ShiftRegistration, Message
from shiftregister.app.models import Helper, Room, Shift, ShiftRegistration, Message
def metrics(request):
@ -82,6 +82,44 @@ def metrics(request):
)
).count(),
),
*(
(
f'shifts{{room="{room.name}"}}',
Shift.objects.filter(deleted=False, room=room).count(),
)
for room in Room.objects.all()
),
*(
(
f'shifts_occupied{{room="{room.name}"}}',
Shift.with_reg_count()
.filter(deleted=False, reg_count__gte=1, room=room)
.count(),
)
for room in Room.objects.all()
),
*(
(
f'shifts_full{{room="{room.name}"}}',
Shift.with_reg_count()
.annotate(
real_required_helpers=Case(
When(
required_helpers=0,
then=F("room__required_helpers"),
),
default=F("required_helpers"),
)
)
.filter(
deleted=False,
reg_count__gte=F("real_required_helpers"),
room=room,
)
.count(),
)
for room in Room.objects.all()
),
(
"worked_seconds_total",
worked_seconds_total.total_seconds()