more stats
This commit is contained in:
parent
440e128bcc
commit
974a7e5a60
|
@ -1,8 +1,38 @@
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from shiftregister.app.models import Helper
|
from shiftregister.app.models import Helper, ShiftRegistration, Message, Shift
|
||||||
|
from django.db.models import F, Count, Q, ExpressionWrapper, Case, When, Sum
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
def metrics(request):
|
def metrics(request):
|
||||||
|
|
||||||
|
help_wanted = Q(required_helpers__gt=F("reg_count")) | Q(required_helpers=0) & Q(
|
||||||
|
room__required_helpers__gt=F("reg_count")
|
||||||
|
)
|
||||||
|
team_shifts = (
|
||||||
|
Shift.with_reg_count()
|
||||||
|
.annotate(team_count=Count("teambackup"))
|
||||||
|
.filter(
|
||||||
|
help_wanted,
|
||||||
|
team_count__gt=0,
|
||||||
|
deleted=False,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
helping_helpers = Helper.objects.annotate(
|
||||||
|
shift_count=Count(
|
||||||
|
Case(
|
||||||
|
When(
|
||||||
|
shiftregistration__state__in=[
|
||||||
|
ShiftRegistration.RegState.CHECKED_IN,
|
||||||
|
],
|
||||||
|
then=1,
|
||||||
|
),
|
||||||
|
output_field=models.IntegerField(),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).filter(number_validated=True, shift_count__gte=1)
|
||||||
|
|
||||||
response = HttpResponse(
|
response = HttpResponse(
|
||||||
"\n".join(
|
"\n".join(
|
||||||
(
|
(
|
||||||
|
@ -13,6 +43,24 @@ def metrics(request):
|
||||||
"helpers_confirmed_total",
|
"helpers_confirmed_total",
|
||||||
Helper.objects.filter(number_validated=True).count(),
|
Helper.objects.filter(number_validated=True).count(),
|
||||||
),
|
),
|
||||||
|
("helpers_helped", helping_helpers.count()),
|
||||||
|
(
|
||||||
|
"worked_shifts",
|
||||||
|
ShiftRegistration.objects.filter(
|
||||||
|
state=ShiftRegistration.RegState.CHECKED_IN
|
||||||
|
).count(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"messages_sent",
|
||||||
|
Message.objects.all().count(),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"hours_worked",
|
||||||
|
ShiftRegistration.objects.filter(
|
||||||
|
state=ShiftRegistration.RegState.CHECKED_IN
|
||||||
|
).aggregate(sum=Sum("shift__duration"))["sum"],
|
||||||
|
),
|
||||||
|
("team_shifts", team_shifts.count()),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue