From 944d33390d013c1f0a623a62251851d39335fe44 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Sun, 10 Sep 2017 17:26:18 -0400 Subject: [PATCH] Begin Sleep Amount graph (WIP). --- reports/graphs.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/reports/graphs.py b/reports/graphs.py index 294c9d65..8f2802dc 100644 --- a/reports/graphs.py +++ b/reports/graphs.py @@ -58,6 +58,21 @@ def diaperchange_types(child): return split_graph_output(output) +def sleep_amount(child): + """Create a graph showing total time sleeping for each day.""" + instances = Sleep.objects.filter(child=child).order_by('start') + + totals = {} + for instance in instances: + start_time = timezone.localtime(instance.start) + start_date = start_time.date().isoformat() + + if start_date not in totals.keys(): + totals[start_date] = timezone.timedelta() + + totals[start_date] += instance.duration + + def sleep_times(child): """Create a graph showing blocked out periods of sleep during each day.""" instances = Sleep.objects.filter(child=child).order_by('start')