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 %}
|
||||
|
||||
{% block content %}
|
||||
<div class="text-muted">
|
||||
Average sleep duration: <strong>{{ average|duration_string }}</strong>.
|
||||
</div>
|
||||
{% if total %}
|
||||
<div class="text-muted">
|
||||
Average sleep duration: <strong>{{ average|duration_string }}</strong>.
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block footer %}{{ count }} sleep entries{% endblock %}
|
|
@ -121,8 +121,10 @@ def card_sleep_day(child, date=None):
|
|||
|
||||
total += end - start
|
||||
|
||||
return {
|
||||
'total': total,
|
||||
'count': len(instances),
|
||||
'average': total/len(instances)
|
||||
}
|
||||
count = len(instances)
|
||||
if count > 0:
|
||||
average = total/count
|
||||
else:
|
||||
average = 0
|
||||
|
||||
return {'total': total, 'count': count, 'average': average}
|
||||
|
|
Loading…
Reference in New Issue