mirror of https://github.com/snachodog/mybuddy.git
Add a Diaper Change types card.
This commit is contained in:
parent
63faa0b553
commit
c2c708883e
|
@ -0,0 +1,26 @@
|
|||
{% extends 'cards/diaperchange.html' %}
|
||||
|
||||
{% block header %}Diaper Change Types{% endblock %}
|
||||
|
||||
{% block title %}
|
||||
<strong>Past 5 Days</strong>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% for date, info in stats.items %}
|
||||
<div class="progress mt-3">
|
||||
<div class="progress-bar bg-info lead"
|
||||
role="progressbar"
|
||||
style="width: {{ info.wet_pct }}%; height: 30px; line-height: 30px">{{ info.wet }} wet</div>
|
||||
<div class="progress-bar bg-dark lead"
|
||||
role="progressbar"
|
||||
style="width: {{ info.solid_pct }}%; height: 30px; line-height: 30px">
|
||||
<strong>{{ info.solid }}</strong> solid</div>
|
||||
</div>
|
||||
<div class="text-center text-dark small">
|
||||
{{ date|date:'D' }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}Last change: {{ last_change.time }}{% endblock %}
|
|
@ -10,5 +10,6 @@
|
|||
{% card_diaperchange_last object %}
|
||||
{% card_tummytime_last object %}
|
||||
{% card_sleep_last object %}
|
||||
{% card_diaperchange_types object %}
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -1,7 +1,10 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from django import template
|
||||
from django.utils import timezone
|
||||
|
||||
from core.models import DiaperChange, Feeding, Sleep, TummyTime
|
||||
|
||||
|
@ -22,6 +25,30 @@ def card_diaperchange_last(child):
|
|||
return {'change': instance}
|
||||
|
||||
|
||||
@register.inclusion_tag('cards/diaperchange_types.html')
|
||||
def card_diaperchange_types(child):
|
||||
"""Diaper change statistics for the last five days including today."""
|
||||
limit = timezone.now() - timezone.timedelta(days=4)
|
||||
instances = DiaperChange.objects.filter(
|
||||
child=child).filter(time__gt=limit.date()).order_by('-time')
|
||||
stats = OrderedDict()
|
||||
for instance in instances:
|
||||
date = instance.time.date()
|
||||
if date not in stats.keys():
|
||||
stats[date] = {'wet': 0, 'solid': 0}
|
||||
if instance.wet:
|
||||
stats[date]['wet'] += 1
|
||||
if instance.solid:
|
||||
stats[date]['solid'] += 1
|
||||
|
||||
for date, info in stats.items():
|
||||
total = info['wet'] + info['solid']
|
||||
stats[date]['wet_pct'] = info['wet'] / total * 100
|
||||
stats[date]['solid_pct'] = info['solid'] / total * 100
|
||||
|
||||
return {'stats': stats, 'last_change': instances.last()}
|
||||
|
||||
|
||||
@register.inclusion_tag('cards/tummytime_last.html')
|
||||
def card_tummytime_last(child):
|
||||
instance = TummyTime.objects.filter(child=child).order_by('-end').first()
|
||||
|
|
Loading…
Reference in New Issue