From d4670a7d02d56dc29a3ee3d9d5eb8bce9182cb0d Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Fri, 9 Feb 2024 12:20:01 -0500 Subject: [PATCH] doorcontrol: Add unique member count to "busiest..." reports --- doorcontrol/views.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/doorcontrol/views.py b/doorcontrol/views.py index b303593..cd702a6 100644 --- a/doorcontrol/views.py +++ b/doorcontrol/views.py @@ -302,6 +302,7 @@ class DetailByDay(BaseAccessReport): class BusiestDayOfWeekTable(tables.Table): timestamp__week_day = tables.Column("Week Day") events = tables.Column() + members = tables.Column() def render_timestamp__week_day(self, value): return calendar.day_name[(value - 2) % 7] @@ -317,14 +318,18 @@ class BusiestDayOfWeek(BaseAccessReport): return ( super() .get_table_data() + .with_member_id() .values("timestamp__week_day") - .annotate(events=Count("timestamp")) + .annotate( + events=Count("timestamp"), members=Count("member_id", distinct=True) + ) ) class BusiestTimeOfDayTable(tables.Table): timestamp__hour = tables.TemplateColumn("{{ value }}:00", verbose_name="Hour") events = tables.Column() + members = tables.Column() @register_report @@ -337,6 +342,9 @@ class BusiestTimeOfDay(BaseAccessReport): return ( super() .get_table_data() + .with_member_id() .values("timestamp__hour") - .annotate(events=Count("timestamp")) + .annotate( + events=Count("timestamp"), members=Count("member_id", distinct=True) + ) )