Refactor naming pattern of simple "change" graphs

This commit is contained in:
Christopher C. Wells 2022-05-25 21:27:21 -07:00 committed by Christopher Charbonneau Wells
parent 4445faeeac
commit 348e622321
9 changed files with 128 additions and 129 deletions

View File

@ -1,15 +1,13 @@
from .pumping_amounts import pumping_amounts # NOQA from .bmi_change import bmi_change # NOQA
from .diaperchange_amounts import diaperchange_amounts # NOQA from .diaperchange_amounts import diaperchange_amounts # NOQA
from .diaperchange_lifetimes import diaperchange_lifetimes # NOQA from .diaperchange_lifetimes import diaperchange_lifetimes # NOQA
from .diaperchange_types import diaperchange_types # NOQA from .diaperchange_types import diaperchange_types # NOQA
from .feeding_amounts import feeding_amounts # NOQA from .feeding_amounts import feeding_amounts # NOQA
from .feeding_duration import feeding_duration # NOQA from .feeding_duration import feeding_duration # NOQA
from .head_circumference_change import head_circumference_change # NOQA
from .height_change import height_change # 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 .tummytime_duration import tummytime_duration # NOQA from .tummytime_duration import tummytime_duration # NOQA
from .weight_weight import weight_weight # NOQA from .weight_change import weight_change # NOQA
from .height_height import height_height # NOQA
from .head_circumference_head_circumference import (
head_circumference_head_circumference,
) # NOQA
from .bmi_bmi import bmi_bmi # NOQA

View File

@ -7,7 +7,7 @@ import plotly.graph_objs as go
from reports import utils from reports import utils
def bmi_bmi(objects): def bmi_change(objects):
""" """
Create a graph showing bmi over time. Create a graph showing bmi over time.
:param objects: a QuerySet of BMI instances. :param objects: a QuerySet of BMI instances.

View File

@ -7,7 +7,7 @@ import plotly.graph_objs as go
from reports import utils from reports import utils
def head_circumference_head_circumference(objects): def head_circumference_change(objects):
""" """
Create a graph showing head_circumference over time. Create a graph showing head_circumference over time.
:param objects: a QuerySet of Head Circumference instances. :param objects: a QuerySet of Head Circumference instances.

View File

@ -7,7 +7,7 @@ import plotly.graph_objs as go
from reports import utils from reports import utils
def height_height(objects): def height_change(objects):
""" """
Create a graph showing height over time. Create a graph showing height over time.
:param objects: a QuerySet of Height instances. :param objects: a QuerySet of Height instances.

View File

@ -7,7 +7,7 @@ import plotly.graph_objs as go
from reports import utils from reports import utils
def weight_weight(objects): def weight_change(objects):
""" """
Create a graph showing weight over time. Create a graph showing weight over time.
:param objects: a QuerySet of Weight instances. :param objects: a QuerySet of Weight instances.

View File

@ -7,19 +7,19 @@
<div class="container-fluid"> <div class="container-fluid">
<h1>Reports</h1> <h1>Reports</h1>
<div class="list-group"> <div class="list-group">
<a href="{% url 'reports:report-bmi-bmi-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Body Mass Index (BMI)" %}</a> <a href="{% url 'reports:report-bmi-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Body Mass Index (BMI)" %}</a>
<a href="{% url 'reports:report-diaperchange-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Amounts" %}</a> <a href="{% url 'reports:report-diaperchange-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Amounts" %}</a>
<a href="{% url 'reports:report-diaperchange-types-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Types" %}</a> <a href="{% url 'reports:report-diaperchange-types-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Types" %}</a>
<a href="{% url 'reports:report-diaperchange-lifetimes-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Lifetimes" %}</a> <a href="{% url 'reports:report-diaperchange-lifetimes-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Lifetimes" %}</a>
<a href="{% url 'reports:report-feeding-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Amounts" %}</a> <a href="{% url 'reports:report-feeding-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Amounts" %}</a>
<a href="{% url 'reports:report-feeding-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Durations (Average)" %}</a> <a href="{% url 'reports:report-feeding-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Durations (Average)" %}</a>
<a href="{% url 'reports:report-head-circumference-head-circumference-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Head Circumference" %}</a> <a href="{% url 'reports:report-head-circumference-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Head Circumference" %}</a>
<a href="{% url 'reports:report-height-height-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Height" %}</a> <a href="{% url 'reports:report-height-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Height" %}</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-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-tummytime-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-weight-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>
</div> </div>
{% endblock %} {% endblock %}

View File

@ -35,7 +35,7 @@ class ViewsTestCase(TestCase):
page = self.c.get(base_url) page = self.c.get(base_url)
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/pumping/amounts/".format(base_url)) page = self.c.get("{}/bmi/bmi/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/changes/amounts/".format(base_url)) page = self.c.get("{}/changes/amounts/".format(base_url))
@ -50,19 +50,22 @@ class ViewsTestCase(TestCase):
page = self.c.get("{}/feeding/duration/".format(base_url)) page = self.c.get("{}/feeding/duration/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/sleep/pattern/".format(base_url)) page = self.c.get("{}/head-circumference/head-circumference/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/sleep/totals/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/weight/weight/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/height/height/".format(base_url)) page = self.c.get("{}/height/height/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/head-circumference/head-circumference/".format(base_url)) page = self.c.get("{}/pumping/amounts/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)
page = self.c.get("{}/bmi/bmi/".format(base_url)) page = self.c.get("{}/sleep/pattern/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/sleep/totals/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/tummy-time/duration/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/weight/weight/".format(base_url))
self.assertEqual(page.status_code, 200) self.assertEqual(page.status_code, 200)

View File

@ -12,9 +12,9 @@ urlpatterns = [
name="report-list", name="report-list",
), ),
path( path(
"children/<str:slug>/reports/pumping/amounts/", "children/<str:slug>/reports/bmi/bmi/",
views.PumpingAmounts.as_view(), views.BMIChangeChildReport.as_view(),
name="report-pumping-amounts-child", name="report-bmi-change-child",
), ),
path( path(
"children/<str:slug>/reports/changes/amounts/", "children/<str:slug>/reports/changes/amounts/",
@ -36,11 +36,26 @@ urlpatterns = [
views.FeedingAmountsChildReport.as_view(), views.FeedingAmountsChildReport.as_view(),
name="report-feeding-amounts-child", name="report-feeding-amounts-child",
), ),
path(
"children/<str:slug>/reports/head-circumference/head-circumference/",
views.HeadCircumferenceChangeChildReport.as_view(),
name="report-head-circumference-change-child",
),
path(
"children/<str:slug>/reports/height/height/",
views.HeightChangeChildReport.as_view(),
name="report-height-change-child",
),
path( path(
"children/<str:slug>/reports/feeding/duration/", "children/<str:slug>/reports/feeding/duration/",
views.FeedingDurationChildReport.as_view(), views.FeedingDurationChildReport.as_view(),
name="report-feeding-duration-child", name="report-feeding-duration-child",
), ),
path(
"children/<str:slug>/reports/pumping/amounts/",
views.PumpingAmounts.as_view(),
name="report-pumping-amounts-child",
),
path( path(
"children/<str:slug>/reports/sleep/pattern/", "children/<str:slug>/reports/sleep/pattern/",
views.SleepPatternChildReport.as_view(), views.SleepPatternChildReport.as_view(),
@ -52,28 +67,13 @@ urlpatterns = [
name="report-sleep-totals-child", name="report-sleep-totals-child",
), ),
path( path(
"children/<str:slug>/reports/tummytime/duration/", "children/<str:slug>/reports/tummy-time/duration/",
views.TummyTimeDurationChildReport.as_view(), views.TummyTimeDurationChildReport.as_view(),
name="report-tummytime-duration-child", name="report-tummy-time-duration-child",
), ),
path( path(
"children/<str:slug>/reports/weight/weight/", "children/<str:slug>/reports/weight/weight/",
views.WeightWeightChildReport.as_view(), views.WeightChangeChildReport.as_view(),
name="report-weight-weight-child", name="report-weight-change-child",
),
path(
"children/<str:slug>/reports/height/height/",
views.HeightHeightChildReport.as_view(),
name="report-height-height-child",
),
path(
"children/<str:slug>/reports/head-circumference/head-circumference/",
views.HeadCircumferenceHeadCircumferenceChildReport.as_view(),
name="report-head-circumference-head-circumference-child",
),
path(
"children/<str:slug>/reports/bmi/bmi/",
views.BMIBMIChildReport.as_view(),
name="report-bmi-bmi-child",
), ),
] ]

View File

@ -7,6 +7,24 @@ from core import models
from . import graphs from . import graphs
class BMIChangeChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of BMI change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/bmi_change.html"
def get_context_data(self, **kwargs):
context = super(BMIChangeChildReport, self).get_context_data(**kwargs)
child = context["object"]
objects = models.BMI.objects.filter(child=child)
if objects:
context["html"], context["js"] = graphs.bmi_change(objects)
return context
class ChildReportList(PermissionRequiredMixin, DetailView): class ChildReportList(PermissionRequiredMixin, DetailView):
""" """
Listing of available reports for a child. Listing of available reports for a child.
@ -17,24 +35,6 @@ class ChildReportList(PermissionRequiredMixin, DetailView):
template_name = "reports/report_list.html" template_name = "reports/report_list.html"
class PumpingAmounts(PermissionRequiredMixin, DetailView):
"""
Graph of pumping milk amounts collected.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/pumping_amounts.html"
def get_context_data(self, **kwargs):
context = super(PumpingAmounts, self).get_context_data(**kwargs)
child = context["object"]
changes = models.Pumping.objects.filter(child=child)
if changes and changes.count() > 0:
context["html"], context["js"] = graphs.pumping_amounts(changes)
return context
class DiaperChangeAmounts(PermissionRequiredMixin, DetailView): class DiaperChangeAmounts(PermissionRequiredMixin, DetailView):
""" """
Graph of diaper "amounts" - measurements of urine output. Graph of diaper "amounts" - measurements of urine output.
@ -137,6 +137,65 @@ class FeedingDurationChildReport(PermissionRequiredMixin, DetailView):
return context return context
class HeadCircumferenceChangeChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of head circumference change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/head_circumference_change.html"
def get_context_data(self, **kwargs):
context = super(HeadCircumferenceChangeChildReport, self).get_context_data(
**kwargs
)
child = context["object"]
objects = models.HeadCircumference.objects.filter(child=child)
if objects:
(
context["html"],
context["js"],
) = graphs.head_circumference_change(objects)
return context
class HeightChangeChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of height change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/height_change.html"
def get_context_data(self, **kwargs):
context = super(HeightChangeChildReport, self).get_context_data(**kwargs)
child = context["object"]
objects = models.Height.objects.filter(child=child)
if objects:
context["html"], context["js"] = graphs.height_change(objects)
return context
class PumpingAmounts(PermissionRequiredMixin, DetailView):
"""
Graph of pumping milk amounts collected.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/pumping_amounts.html"
def get_context_data(self, **kwargs):
context = super(PumpingAmounts, self).get_context_data(**kwargs)
child = context["object"]
changes = models.Pumping.objects.filter(child=child)
if changes and changes.count() > 0:
context["html"], context["js"] = graphs.pumping_amounts(changes)
return context
class SleepPatternChildReport(PermissionRequiredMixin, DetailView): class SleepPatternChildReport(PermissionRequiredMixin, DetailView):
""" """
Graph of sleep pattern comparing sleep to wake times by day. Graph of sleep pattern comparing sleep to wake times by day.
@ -206,7 +265,7 @@ class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
return context return context
class WeightWeightChildReport(PermissionRequiredMixin, DetailView): class WeightChangeChildReport(PermissionRequiredMixin, DetailView):
""" """
Graph of weight change over time. Graph of weight change over time.
""" """
@ -216,70 +275,9 @@ class WeightWeightChildReport(PermissionRequiredMixin, DetailView):
template_name = "reports/weight_change.html" template_name = "reports/weight_change.html"
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(WeightWeightChildReport, self).get_context_data(**kwargs) context = super(WeightChangeChildReport, self).get_context_data(**kwargs)
child = context["object"] child = context["object"]
objects = models.Weight.objects.filter(child=child) objects = models.Weight.objects.filter(child=child)
if objects: if objects:
context["html"], context["js"] = graphs.weight_weight(objects) context["html"], context["js"] = graphs.weight_change(objects)
return context
class HeightHeightChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of height change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/height_change.html"
def get_context_data(self, **kwargs):
context = super(HeightHeightChildReport, self).get_context_data(**kwargs)
child = context["object"]
objects = models.Height.objects.filter(child=child)
if objects:
context["html"], context["js"] = graphs.height_height(objects)
return context
class HeadCircumferenceHeadCircumferenceChildReport(
PermissionRequiredMixin, DetailView
):
"""
Graph of head circumference change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/head_circumference_change.html"
def get_context_data(self, **kwargs):
context = super(
HeadCircumferenceHeadCircumferenceChildReport, self
).get_context_data(**kwargs)
child = context["object"]
objects = models.HeadCircumference.objects.filter(child=child)
if objects:
(
context["html"],
context["js"],
) = graphs.head_circumference_head_circumference(objects)
return context
class BMIBMIChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of BMI change over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/bmi_change.html"
def get_context_data(self, **kwargs):
context = super(BMIBMIChildReport, self).get_context_data(**kwargs)
child = context["object"]
objects = models.BMI.objects.filter(child=child)
if objects:
context["html"], context["js"] = graphs.bmi_bmi(objects)
return context return context