Fix zero division error when a day has no sleep entries.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-15 07:09:43 -04:00
parent 6ec4307173
commit 0ae9c5a408
2 changed files with 12 additions and 8 deletions

View File

@ -14,9 +14,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if total %}
<div class="text-muted"> <div class="text-muted">
Average sleep duration: <strong>{{ average|duration_string }}</strong>. Average sleep duration: <strong>{{ average|duration_string }}</strong>.
</div> </div>
{% endif %}
{% endblock %} {% endblock %}
{% block footer %}{{ count }} sleep entries{% endblock %} {% block footer %}{{ count }} sleep entries{% endblock %}

View File

@ -121,8 +121,10 @@ def card_sleep_day(child, date=None):
total += end - start total += end - start
return { count = len(instances)
'total': total, if count > 0:
'count': len(instances), average = total/count
'average': total/len(instances) else:
} average = 0
return {'total': total, 'count': count, 'average': average}