From 1762dc503522edb266955a4ed6e5cf06ed0d3863 Mon Sep 17 00:00:00 2001
From: "R. Miles McCain"
Date: Wed, 22 Apr 2020 12:46:26 -0400
Subject: [PATCH] Improve stat deltas, division by zero
---
.../dashboard/includes/service_overview.html | 4 ++--
.../templates/dashboard/pages/service.html | 24 +++++++++----------
shynet/dashboard/templatetags/helpers.py | 4 +++-
3 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/shynet/dashboard/templates/dashboard/includes/service_overview.html b/shynet/dashboard/templates/dashboard/includes/service_overview.html
index 4394890..b3fa67e 100644
--- a/shynet/dashboard/templates/dashboard/includes/service_overview.html
+++ b/shynet/dashboard/templates/dashboard/includes/service_overview.html
@@ -29,10 +29,10 @@
{% if stats.bounce_rate_pct != None %}
{{stats.bounce_rate_pct|floatformat:"-1"}}%
- {% compare stats.compare.bounce_rate_pct stats.bounce_rate_pct "DOWN" %}
{% else %}
?
{% endif %}
+ {% compare stats.compare.bounce_rate_pct stats.bounce_rate_pct "DOWN" %}
@@ -40,10 +40,10 @@
{% if stats.avg_session_duration != None %}
{{stats.avg_session_duration|naturaldelta}}
- {% compare stats.compare.avg_session_duration stats.avg_session_duration "UP" %}
{% else %}
?
{% endif %}
+ {% compare stats.compare.avg_session_duration stats.avg_session_duration "UP" %}
diff --git a/shynet/dashboard/templates/dashboard/pages/service.html b/shynet/dashboard/templates/dashboard/pages/service.html
index 303256a..b03341a 100644
--- a/shynet/dashboard/templates/dashboard/pages/service.html
+++ b/shynet/dashboard/templates/dashboard/pages/service.html
@@ -36,12 +36,12 @@
{% if stats.avg_load_time %}
{{stats.avg_load_time|floatformat:"0"}}ms
-
- {% compare stats.compare.avg_load_time stats.avg_load_time "DOWN" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
-
{% else %}
?
{% endif %}
+
+ {% compare stats.compare.avg_load_time stats.avg_load_time "DOWN" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
+
@@ -49,12 +49,12 @@
{% if stats.bounce_rate_pct %}
{{stats.bounce_rate_pct|floatformat:"-1"}}%
-
- {% compare stats.compare.bounce_rate_pct stats.bounce_rate_pct "DOWN" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
-
{% else %}
?
{% endif %}
+
+ {% compare stats.compare.bounce_rate_pct stats.bounce_rate_pct "DOWN" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
+
@@ -62,12 +62,12 @@
{% if stats.avg_session_duration %}
{{stats.avg_session_duration|naturaldelta}}
-
- {% compare stats.compare.avg_session_duration stats.avg_session_duration "UP" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
-
{% else %}
?
{% endif %}
+
+ {% compare stats.compare.avg_session_duration stats.avg_session_duration "UP" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
+
@@ -75,12 +75,12 @@
{% if stats.avg_hits_per_session %}
{{stats.avg_hits_per_session|floatformat:"-1"}}
-
- {% compare stats.compare.avg_hits_per_session stats.avg_hits_per_session "UP" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
-
{% else %}
?
{% endif %}
+
+ {% compare stats.compare.avg_hits_per_session stats.avg_hits_per_session "UP" classes=classes good_classes=good_classes bad_classes=bad_classes neutral_classes=neutral_classes %}
+
{% endwith %}
diff --git a/shynet/dashboard/templatetags/helpers.py b/shynet/dashboard/templatetags/helpers.py
index 8efb4a2..a3d83ef 100644
--- a/shynet/dashboard/templatetags/helpers.py
+++ b/shynet/dashboard/templatetags/helpers.py
@@ -67,12 +67,14 @@ def percent_change_display(start, end):
if start == None or end == None:
return SafeString("Δ n/a")
if start == end:
- direction = ""
+ direction = "Δ "
else:
direction = "↑ " if end > start else "↓ "
if start == 0 and end != 0:
pct_change = "100%"
+ elif start == 0:
+ pct_change = "0%"
else:
change = int(round(100 * abs(end - start) / start))
if change > 999: