From 02080206c655b6a73bebfc9e2640aac74dc74c03 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 9 Feb 2024 12:16:30 -0500 Subject: [PATCH] doorcontrol: Add "detail by day" access report --- doorcontrol/views.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/doorcontrol/views.py b/doorcontrol/views.py index 6b6e3c1..b303593 100644 --- a/doorcontrol/views.py +++ b/doorcontrol/views.py @@ -271,6 +271,34 @@ class MostActiveMembers(BaseAccessReport): ) +class DetailByDayTable(tables.Table): + timestamp__date = tables.DateColumn(verbose_name="Date") + name = tables.Column() + access_count = tables.Column() + + +@register_report +class DetailByDay(BaseAccessReport): + _report_name = "Detail by Day" + table_class = DetailByDayTable + + def get_table_data(self): + return ( + super() + .get_table_data() + .with_member_id() + .values("timestamp__date", "member_id") + .filter(member_id__isnull=False) + .annotate( + access_count=Count("member_id"), + name=GroupConcat( + ConcatWS("forename", "surname", separator=" "), distinct=True + ), + ) + .order_by("-timestamp__date") + ) + + class BusiestDayOfWeekTable(tables.Table): timestamp__week_day = tables.Column("Week Day") events = tables.Column()