mirror of https://github.com/snachodog/mybuddy.git
Continue initial attempt at sleep graph (WIP).
This commit is contained in:
parent
e3b73d53c5
commit
7ba85f29d4
|
@ -7,42 +7,54 @@
|
||||||
Sleep report for {{ object }}.
|
Sleep report for {{ object }}.
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="pull-left p-1">
|
<pre>{{ stats|pprint }}</pre>
|
||||||
<strong>8 Aug</strong>
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-1 d-flex align-self-center">
|
||||||
|
Tuesday, 22 Aug.
|
||||||
|
</div>
|
||||||
|
<div class="col-md-11">
|
||||||
|
<div class="progress" style="height: 32px; border-radius: 0;">
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
|
<div class="progress-bar" role="progressbar" style="width: 8%; background: none;"></div>
|
||||||
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="progress" style="height: 32px; border-radius: 0;">
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
<div class="row">
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
<div class="col-md-1">
|
||||||
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
Monday, 21 Aug.
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
</div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
<div class="col-md-11">
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
<div class="progress" style="height: 32px; border-radius: 0;">
|
||||||
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 8%; background: none;"></div>
|
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
||||||
</div>
|
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
||||||
<div class="pull-left p-1">
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
<strong>7 Aug</strong>
|
<div class="progress-bar" role="progressbar" style="width: 8%; background: none;"></div>
|
||||||
</div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
||||||
<div class="progress" style="height: 32px; border-radius: 0;">
|
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
</div>
|
||||||
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
</div>
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 5%; background: none;"></div>
|
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 2%"></div>
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 3%; background: none;"></div>
|
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 8%; background: none;"></div>
|
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 10%"></div>
|
|
||||||
<div class="progress-bar" role="progressbar" style="width: 15%; background: none;"></div>
|
|
||||||
<div class="progress-bar bg-info" role="progressbar" style="width: 6%"></div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -1,14 +1,47 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||||
|
from django.utils import timezone
|
||||||
from django.views.generic.detail import DetailView
|
from django.views.generic.detail import DetailView
|
||||||
|
|
||||||
from core.models import Child
|
from core.models import Child, Sleep
|
||||||
|
|
||||||
|
|
||||||
class SleepReport(PermissionRequiredMixin, DetailView):
|
class SleepReport(PermissionRequiredMixin, DetailView):
|
||||||
"""TODO: Account for sleep sessions crossing midnight."""
|
"""All sleep data for a child."""
|
||||||
model = Child
|
model = Child
|
||||||
permission_required = ('core.view_child',)
|
permission_required = ('core.view_child',)
|
||||||
template_name = 'reports/sleep.html'
|
template_name = 'reports/sleep.html'
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(SleepReport, self).get_context_data(**kwargs)
|
||||||
|
child = context['object']
|
||||||
|
|
||||||
|
sleep_entries = Sleep.objects.filter(child=child).order_by('-end')
|
||||||
|
diff = timezone.localtime().date() - timezone.localtime(sleep_entries.last().end).date()
|
||||||
|
stats = OrderedDict()
|
||||||
|
for x in range(0, diff.days + 1):
|
||||||
|
key = (timezone.localtime() - timezone.timedelta(days=x))
|
||||||
|
stats[key.date()] = []
|
||||||
|
|
||||||
|
last = None
|
||||||
|
for entry in sleep_entries:
|
||||||
|
start = timezone.localtime(entry.start)
|
||||||
|
end = timezone.localtime(entry.end)
|
||||||
|
|
||||||
|
if not stats[end.date()]:
|
||||||
|
last = end.replace(hour=23, minute=59, second=59)
|
||||||
|
|
||||||
|
# TODO: Account for sleep sessions crossing midnight.
|
||||||
|
stats[start.date()].append((
|
||||||
|
(last - end).seconds/86400 * 100,
|
||||||
|
(end - start).seconds/86400 * 100
|
||||||
|
))
|
||||||
|
last = start
|
||||||
|
|
||||||
|
context['stats'] = stats
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
Loading…
Reference in New Issue