mirror of https://github.com/snachodog/mybuddy.git
Add empty diapers support to dashboard card
This commit is contained in:
parent
4916a810e0
commit
81ecff0296
|
@ -17,20 +17,31 @@
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
{% for key, info in stats.items %}
|
{% 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 %}
|
||||||
<div class="progress mt-3">
|
<div class="progress mt-3">
|
||||||
|
|
||||||
{% if info.wet_pct > 0 %}
|
{% if info.wet_pct > 0 %}
|
||||||
<div class="progress-bar bg-primary lead"
|
<div class="progress-bar bg-primary lead"
|
||||||
role="progressbar"
|
role="progressbar"
|
||||||
style="width: {{ info.wet_pct|safe }}%;">{{ info.wet|floatformat:'0' }} {% trans "wet" %}</div>
|
style="width: {{ info.wet_pct|safe }}%;">
|
||||||
|
{{ info.wet|floatformat:'0' }} {% trans "wet" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if info.solid_pct > 0 %}
|
{% if info.solid_pct > 0 %}
|
||||||
<div class="progress-bar bg-secondary lead"
|
<div class="progress-bar bg-secondary lead"
|
||||||
role="progressbar"
|
role="progressbar"
|
||||||
style="width: {{ info.solid_pct|safe }}%;">
|
style="width: {{ info.solid_pct|safe }}%;">
|
||||||
{{ info.solid|floatformat:'0' }} {% trans "solid" %}</div>
|
{{ info.solid|floatformat:'0' }} {% trans "solid" %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if info.empty_pct > 0 %}
|
||||||
|
<div class="progress-bar bg-transparent lead"
|
||||||
|
role="progressbar"
|
||||||
|
style="width: {{ info.empty_pct|safe }}%;">
|
||||||
|
{{ info.empty|floatformat:'0' }}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="text-center text-light small">
|
<div class="text-center text-light small">
|
||||||
|
|
|
@ -55,7 +55,7 @@ def card_diaperchange_types(context, child, date=None):
|
||||||
seven days.
|
seven days.
|
||||||
:param child: an instance of the Child model.
|
:param child: an instance of the Child model.
|
||||||
:param date: a Date object for the day to filter.
|
: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:
|
if not date:
|
||||||
time = timezone.localtime()
|
time = timezone.localtime()
|
||||||
|
@ -70,7 +70,7 @@ def card_diaperchange_types(context, child, date=None):
|
||||||
)
|
)
|
||||||
|
|
||||||
for x in range(7):
|
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 = (
|
instances = (
|
||||||
models.DiaperChange.objects.filter(child=child)
|
models.DiaperChange.objects.filter(child=child)
|
||||||
|
@ -86,13 +86,16 @@ def card_diaperchange_types(context, child, date=None):
|
||||||
stats[key]["wet"] += 1
|
stats[key]["wet"] += 1
|
||||||
if instance.solid:
|
if instance.solid:
|
||||||
stats[key]["solid"] += 1
|
stats[key]["solid"] += 1
|
||||||
|
if not instance.wet and not instance.solid:
|
||||||
|
stats[key]["empty"] += 1
|
||||||
|
|
||||||
for key, info in stats.items():
|
for key, info in stats.items():
|
||||||
total = info["wet"] + info["solid"]
|
total = info["wet"] + info["solid"] + info["empty"]
|
||||||
week_total += total
|
week_total += total
|
||||||
if total > 0:
|
if total > 0:
|
||||||
stats[key]["wet_pct"] = info["wet"] / total * 100
|
stats[key]["wet_pct"] = info["wet"] / total * 100
|
||||||
stats[key]["solid_pct"] = info["solid"] / total * 100
|
stats[key]["solid_pct"] = info["solid"] / total * 100
|
||||||
|
stats[key]["empty_pct"] = info["empty"] / total * 100
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"type": "diaperchange",
|
"type": "diaperchange",
|
||||||
|
|
|
@ -92,13 +92,62 @@ class TemplateTagsTestCase(TestCase):
|
||||||
data = cards.card_diaperchange_types(self.context, self.child, self.date)
|
data = cards.card_diaperchange_types(self.context, self.child, self.date)
|
||||||
self.assertEqual(data["type"], "diaperchange")
|
self.assertEqual(data["type"], "diaperchange")
|
||||||
stats = {
|
stats = {
|
||||||
0: {"wet_pct": 50.0, "solid_pct": 50.0, "solid": 1, "wet": 1},
|
0: {
|
||||||
1: {"wet_pct": 0.0, "solid_pct": 100.0, "solid": 2, "wet": 0},
|
"wet_pct": 50.0,
|
||||||
2: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 2},
|
"solid_pct": 50.0,
|
||||||
3: {"wet_pct": 75.0, "solid_pct": 25.0, "solid": 1, "wet": 3},
|
"empty_pct": 0.0,
|
||||||
4: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 1},
|
"solid": 1,
|
||||||
5: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "wet": 2},
|
"wet": 1,
|
||||||
6: {"wet_pct": 100.0, "solid_pct": 0.0, "solid": 0, "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)
|
self.assertEqual(data["stats"], stats)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue