diff --git a/shiftregister/metrics/views.py b/shiftregister/metrics/views.py index 961e4ad..b8dc289 100644 --- a/shiftregister/metrics/views.py +++ b/shiftregister/metrics/views.py @@ -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()