From 5e6ae8ee75c8fcd493ed99c3d0be47f01576a6b9 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Thu, 29 Aug 2024 13:15:50 -0400 Subject: [PATCH] doorcontrol: Fix divide by zero in access report deltas --- doorcontrol/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doorcontrol/views.py b/doorcontrol/views.py index 80121f8..bedacc0 100644 --- a/doorcontrol/views.py +++ b/doorcontrol/views.py @@ -5,7 +5,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.postgres.aggregates import StringAgg from django.core.exceptions import BadRequest from django.db.models import Count, F, FloatField, Func, Q, Value, Window -from django.db.models.functions import Lead, Trunc +from django.db.models.functions import Lead, NullIf, Trunc from django.urls import path, reverse_lazy from django.utils.text import slugify from django.views.generic.list import ListView @@ -173,7 +173,7 @@ class AccessPerUnitTime(BaseAccessReport): members_delta=( F("members") / Window( - Lead("members"), + Lead(NullIf("members", 0.0)), order_by="-unit_time", output_field=FloatField(), ) @@ -184,7 +184,7 @@ class AccessPerUnitTime(BaseAccessReport): access_count_delta=( F("access_count") / Window( - Lead("access_count"), + Lead(NullIf("access_count", 0.0)), order_by="-unit_time", output_field=FloatField(), )