mirror of https://github.com/snachodog/mybuddy.git
Fix zero division error when a day has no sleep entries.
This commit is contained in:
parent
6ec4307173
commit
0ae9c5a408
|
@ -14,9 +14,11 @@
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="text-muted">
|
{% if total %}
|
||||||
Average sleep duration: <strong>{{ average|duration_string }}</strong>.
|
<div class="text-muted">
|
||||||
</div>
|
Average sleep duration: <strong>{{ average|duration_string }}</strong>.
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block footer %}{{ count }} sleep entries{% endblock %}
|
{% block footer %}{{ count }} sleep entries{% endblock %}
|
|
@ -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}
|
||||||
|
|
Loading…
Reference in New Issue