mirror of https://github.com/snachodog/mybuddy.git
Add reports for temperature readings
This commit is contained in:
parent
c5a56aaabd
commit
2519dad74c
|
@ -9,5 +9,6 @@ from .height_change import height_change # NOQA
|
||||||
from .pumping_amounts import pumping_amounts # NOQA
|
from .pumping_amounts import pumping_amounts # NOQA
|
||||||
from .sleep_pattern import sleep_pattern # NOQA
|
from .sleep_pattern import sleep_pattern # NOQA
|
||||||
from .sleep_totals import sleep_totals # NOQA
|
from .sleep_totals import sleep_totals # NOQA
|
||||||
|
from .temperature_change import temperature_change # NOQA
|
||||||
from .tummytime_duration import tummytime_duration # NOQA
|
from .tummytime_duration import tummytime_duration # NOQA
|
||||||
from .weight_change import weight_change # NOQA
|
from .weight_change import weight_change # NOQA
|
||||||
|
|
|
@ -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"] = _("<b>Temperature</b>")
|
||||||
|
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)
|
|
@ -27,6 +27,7 @@
|
||||||
<a href="{% url 'reports:report-pumping-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Pumping Amounts" %}</a>
|
<a href="{% url 'reports:report-pumping-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Pumping Amounts" %}</a>
|
||||||
<a href="{% url 'reports:report-sleep-pattern-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Pattern" %}</a>
|
<a href="{% url 'reports:report-sleep-pattern-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Pattern" %}</a>
|
||||||
<a href="{% url 'reports:report-sleep-totals-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Totals" %}</a>
|
<a href="{% url 'reports:report-sleep-totals-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Totals" %}</a>
|
||||||
|
<a href="{% url 'reports:report-temperature-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Temperature" %}</a>
|
||||||
<a href="{% url 'reports:report-tummy-time-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Tummy Time Durations (Sum)" %}</a>
|
<a href="{% url 'reports:report-tummy-time-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Tummy Time Durations (Sum)" %}</a>
|
||||||
<a href="{% url 'reports:report-weight-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Weight" %}</a>
|
<a href="{% url 'reports:report-weight-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Weight" %}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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' %}
|
||||||
|
<li class="breadcrumb-item active" aria-current="page">{% trans "Temperature" %}</li>
|
||||||
|
{% endblock %}
|
|
@ -66,6 +66,11 @@ urlpatterns = [
|
||||||
views.SleepTotalsChildReport.as_view(),
|
views.SleepTotalsChildReport.as_view(),
|
||||||
name="report-sleep-totals-child",
|
name="report-sleep-totals-child",
|
||||||
),
|
),
|
||||||
|
path(
|
||||||
|
"children/<str:slug>/reports/temperature/temperature/",
|
||||||
|
views.TemperatureChangeChildReport.as_view(),
|
||||||
|
name="report-temperature-change-child",
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"children/<str:slug>/reports/tummy-time/duration/",
|
"children/<str:slug>/reports/tummy-time/duration/",
|
||||||
views.TummyTimeDurationChildReport.as_view(),
|
views.TummyTimeDurationChildReport.as_view(),
|
||||||
|
|
|
@ -50,6 +50,24 @@ def rangeselector_date():
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def rangeselector_time():
|
||||||
|
"""
|
||||||
|
Graph time range selectors settings for 12h, 24h, 48h, 3d and all.
|
||||||
|
:returns: a dict of settings for the selectors.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
"bgcolor": "rgb(35, 149, 86)",
|
||||||
|
"activecolor": "rgb(25, 108, 62)",
|
||||||
|
"buttons": [
|
||||||
|
{"count": 12, "label": "12h", "step": "hour", "stepmode": "backward"},
|
||||||
|
{"count": 24, "label": "24h", "step": "hour", "stepmode": "backward"},
|
||||||
|
{"count": 48, "label": "48h", "step": "hour", "stepmode": "backward"},
|
||||||
|
{"count": 3, "label": "3d", "step": "day", "stepmode": "backward"},
|
||||||
|
{"count": 7, "label": "7d", "step": "day", "stepmode": "backward"},
|
||||||
|
{"step": "all"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
def split_graph_output(output):
|
def split_graph_output(output):
|
||||||
"""
|
"""
|
||||||
Split out of a Plotly graph in to html and javascript.
|
Split out of a Plotly graph in to html and javascript.
|
||||||
|
|
|
@ -242,6 +242,24 @@ class SleepTotalsChildReport(PermissionRequiredMixin, DetailView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class TemperatureChangeChildReport(PermissionRequiredMixin, DetailView):
|
||||||
|
"""
|
||||||
|
Graph of temperature change over time.
|
||||||
|
"""
|
||||||
|
|
||||||
|
model = models.Child
|
||||||
|
permission_required = ("core.view_child",)
|
||||||
|
template_name = "reports/temperature_change.html"
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(TemperatureChangeChildReport, self).get_context_data(**kwargs)
|
||||||
|
child = context["object"]
|
||||||
|
objects = models.Temperature.objects.filter(child=child)
|
||||||
|
if objects:
|
||||||
|
context["html"], context["js"] = graphs.temperature_change(objects)
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
|
class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Graph of tummy time durations over time.
|
Graph of tummy time durations over time.
|
||||||
|
|
Loading…
Reference in New Issue