diff --git a/dashboard/templates/cards/diaperchange_types.html b/dashboard/templates/cards/diaperchange_types.html
index 36965777..8e7ef996 100644
--- a/dashboard/templates/cards/diaperchange_types.html
+++ b/dashboard/templates/cards/diaperchange_types.html
@@ -17,20 +17,31 @@
{% block content %}
{% for key, info in stats.items %}
- {% if info.wet > 0 or info.solid > 0 %}
+ {% if info.wet > 0 or info.solid > 0 or info.empty > 0 %}
{% if info.wet_pct > 0 %}
{{ info.wet|floatformat:'0' }} {% trans "wet" %}
+ style="width: {{ info.wet_pct|safe }}%;">
+ {{ info.wet|floatformat:'0' }} {% trans "wet" %}
+
{% endif %}
{% if info.solid_pct > 0 %}
- {{ info.solid|floatformat:'0' }} {% trans "solid" %}
+ {{ info.solid|floatformat:'0' }} {% trans "solid" %}
+
+ {% endif %}
+
+ {% if info.empty_pct > 0 %}
+
+ {{ info.empty|floatformat:'0' }}
+
{% endif %}
diff --git a/dashboard/templatetags/cards.py b/dashboard/templatetags/cards.py
index 69b656c2..b88a0164 100644
--- a/dashboard/templatetags/cards.py
+++ b/dashboard/templatetags/cards.py
@@ -55,7 +55,7 @@ def card_diaperchange_types(context, child, date=None):
seven days.
:param child: an instance of the Child model.
:param date: a Date object for the day to filter.
- :returns: a dictionary with the wet/dry statistics.
+ :returns: a dictionary with the wet/solid/empty statistics.
"""
if not date:
time = timezone.localtime()
@@ -70,7 +70,7 @@ def card_diaperchange_types(context, child, date=None):
)
for x in range(7):
- stats[x] = {"wet": 0.0, "solid": 0.0}
+ stats[x] = {"wet": 0.0, "solid": 0.0, "empty": 0.0}
instances = (
models.DiaperChange.objects.filter(child=child)
@@ -86,13 +86,16 @@ def card_diaperchange_types(context, child, date=None):
stats[key]["wet"] += 1
if instance.solid:
stats[key]["solid"] += 1
+ if not instance.wet and not instance.solid:
+ stats[key]["empty"] += 1
for key, info in stats.items():
- total = info["wet"] + info["solid"]
+ total = info["wet"] + info["solid"] + info["empty"]
week_total += total
if total > 0:
stats[key]["wet_pct"] = info["wet"] / total * 100
stats[key]["solid_pct"] = info["solid"] / total * 100
+ stats[key]["empty_pct"] = info["empty"] / total * 100
return {
"type": "diaperchange",
diff --git a/dashboard/tests/tests_templatetags.py b/dashboard/tests/tests_templatetags.py
index 312dabe2..d2e8ecc5 100644
--- a/dashboard/tests/tests_templatetags.py
+++ b/dashboard/tests/tests_templatetags.py
@@ -92,13 +92,62 @@ class TemplateTagsTestCase(TestCase):
data = cards.card_diaperchange_types(self.context, self.child, self.date)
self.assertEqual(data["type"], "diaperchange")
stats = {
- 0: {"wet_pct": 50.0, "solid_pct": 50.0, "solid": 1, "wet": 1},
- 1: {"wet_pct": 0.0, "solid_pct": 100.0, "solid": 2, "wet": 0},
- 2: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 2},
- 3: {"wet_pct": 75.0, "solid_pct": 25.0, "solid": 1, "wet": 3},
- 4: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 1},
- 5: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 2},
- 6: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 1},
+ 0: {
+ "wet_pct": 50.0,
+ "solid_pct": 50.0,
+ "empty_pct": 0.0,
+ "solid": 1,
+ "wet": 1,
+ "empty": 0.0,
+ },
+ 1: {
+ "wet_pct": 0.0,
+ "solid_pct": 100.0,
+ "empty_pct": 0.0,
+ "solid": 2,
+ "wet": 0,
+ "empty": 0.0,
+ },
+ 2: {
+ "wet_pct": 100.0,
+ "solid_pct": 0.0,
+ "empty_pct": 0.0,
+ "solid": 0,
+ "wet": 2,
+ "empty": 0.0,
+ },
+ 3: {
+ "wet_pct": 75.0,
+ "solid_pct": 25.0,
+ "empty_pct": 0.0,
+ "solid": 1,
+ "wet": 3,
+ "empty": 0.0,
+ },
+ 4: {
+ "wet_pct": 100.0,
+ "solid_pct": 0.0,
+ "empty_pct": 0.0,
+ "solid": 0,
+ "wet": 1,
+ "empty": 0.0,
+ },
+ 5: {
+ "wet_pct": 100.0,
+ "solid_pct": 0.0,
+ "empty_pct": 0.0,
+ "solid": 0,
+ "wet": 2,
+ "empty": 0.0,
+ },
+ 6: {
+ "wet_pct": 100.0,
+ "solid_pct": 0.0,
+ "empty_pct": 0.0,
+ "solid": 0,
+ "wet": 1,
+ "empty": 0.0,
+ },
}
self.assertEqual(data["stats"], stats)