diff --git a/reports/graphs/__init__.py b/reports/graphs/__init__.py index 6d31a582..712694df 100644 --- a/reports/graphs/__init__.py +++ b/reports/graphs/__init__.py @@ -9,5 +9,6 @@ from .height_change import height_change # NOQA from .pumping_amounts import pumping_amounts # NOQA from .sleep_pattern import sleep_pattern # NOQA from .sleep_totals import sleep_totals # NOQA +from .temperature_change import temperature_change # NOQA from .tummytime_duration import tummytime_duration # NOQA from .weight_change import weight_change # NOQA diff --git a/reports/graphs/temperature_change.py b/reports/graphs/temperature_change.py new file mode 100644 index 00000000..25cf6bc7 --- /dev/null +++ b/reports/graphs/temperature_change.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from django.utils.translation import gettext as _ + +import plotly.offline as plotly +import plotly.graph_objs as go + +from reports import utils + + +def temperature_change(objects): + """ + Create a graph showing temperature over time. + :param objects: a QuerySet of Temperature instances. + :returns: a tuple of the graph's html and javascript. + """ + objects = objects.order_by("-time") + + trace = go.Scatter( + name=_("Temperature"), + x=list(objects.values_list("time", flat=True)), + y=list(objects.values_list("temperature", flat=True)), + fill="tozeroy", + ) + + layout_args = utils.default_graph_layout_options() + layout_args["barmode"] = "stack" + layout_args["title"] = _("Temperature") + layout_args["xaxis"]["title"] = _("Time") + layout_args["xaxis"]["rangeselector"] = utils.rangeselector_time() + layout_args["yaxis"]["title"] = _("Temperature") + + fig = go.Figure({"data": [trace], "layout": go.Layout(**layout_args)}) + output = plotly.plot(fig, output_type="div", include_plotlyjs=False) + return utils.split_graph_output(output) diff --git a/reports/templates/reports/report_list.html b/reports/templates/reports/report_list.html index af62656e..2a4f3856 100644 --- a/reports/templates/reports/report_list.html +++ b/reports/templates/reports/report_list.html @@ -27,6 +27,7 @@ {% trans "Pumping Amounts" %} {% trans "Sleep Pattern" %} {% trans "Sleep Totals" %} + {% trans "Temperature" %} {% trans "Tummy Time Durations (Sum)" %} {% trans "Weight" %} diff --git a/reports/templates/reports/temperature_change.html b/reports/templates/reports/temperature_change.html new file mode 100644 index 00000000..2bd0cbc1 --- /dev/null +++ b/reports/templates/reports/temperature_change.html @@ -0,0 +1,10 @@ +{% extends 'reports/report_base.html' %} +{% load i18n %} + +{% block title %}{% trans "Temperature" %} - {{ object }}{% endblock %} + +{% block breadcrumbs %} + {{ block.super }} + {% include 'reports/breadcrumb_common_chunk.html' with target_url='reports:report-temperature-change-child' %} +