Fix lint issues

This commit is contained in:
bugbountyguy 2022-04-04 10:40:25 -05:00 committed by Christopher Charbonneau Wells
parent b21c193488
commit 0d89574a65
2 changed files with 42 additions and 19 deletions

View File

@ -7,24 +7,43 @@ import django.db.models.deletion
class Migration(migrations.Migration): class Migration(migrations.Migration):
dependencies = [ dependencies = [
('core', '0020_bmi_tags_diaperchange_tags_feeding_tags_and_more'), ("core", "0020_bmi_tags_diaperchange_tags_feeding_tags_and_more"),
] ]
operations = [ operations = [
migrations.CreateModel( migrations.CreateModel(
name='Pumping', name="Pumping",
fields=[ fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), (
('amount', models.FloatField(verbose_name='Amount')), "id",
('time', models.DateTimeField(verbose_name='Time')), models.AutoField(
('notes', models.TextField(blank=True, null=True, verbose_name='Notes')), auto_created=True,
('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pumping', to='core.child', verbose_name='Child')), primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("amount", models.FloatField(verbose_name="Amount")),
("time", models.DateTimeField(verbose_name="Time")),
(
"notes",
models.TextField(blank=True, null=True, verbose_name="Notes"),
),
(
"child",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="pumping",
to="core.child",
verbose_name="Child",
),
),
], ],
options={ options={
'verbose_name': 'Pumping', "verbose_name": "Pumping",
'verbose_name_plural': 'Pumping', "verbose_name_plural": "Pumping",
'ordering': ['-time'], "ordering": ["-time"],
'default_permissions': ('view', 'add', 'change', 'delete'), "default_permissions": ("view", "add", "change", "delete"),
}, },
), ),
] ]

View File

@ -17,7 +17,7 @@ def pumping_amounts(objects):
objects = objects.order_by("time") objects = objects.order_by("time")
# We need to find date totals for annotations at the end # We need to find date totals for annotations at the end
curr_date = '' curr_date = ""
date_totals = {} date_totals = {}
for object in objects: for object in objects:
date_s = str(object.time.date()) date_s = str(object.time.date())
@ -28,7 +28,7 @@ def pumping_amounts(objects):
dates = [] # Single array for each bar dates = [] # Single array for each bar
amounts = [] # Array of arrays containing amounts amounts = [] # Array of arrays containing amounts
index_x, index_y = 0,-1 index_x, index_y = 0, -1
for object in objects: for object in objects:
date_s = str(object.time.date()) date_s = str(object.time.date())
if date_s not in dates: if date_s not in dates:
@ -36,12 +36,12 @@ def pumping_amounts(objects):
index_y += 1 index_y += 1
index_x = 0 index_x = 0
if len(amounts) == 0 or len(amounts) <= index_x: if len(amounts) == 0 or len(amounts) <= index_x:
amounts.append([0]*len(date_totals.keys())) amounts.append([0] * len(date_totals.keys()))
amounts[index_x][index_y] = object.amount amounts[index_x][index_y] = object.amount
index_x += 1 index_x += 1
traces = [] traces = []
for i in range(0, len(amounts)-1): for i in range(0, len(amounts) - 1):
traces.append( traces.append(
go.Bar( go.Bar(
name="Amount", name="Amount",
@ -59,7 +59,11 @@ def pumping_amounts(objects):
layout_args["xaxis"]["rangeselector"] = utils.rangeselector_date() layout_args["xaxis"]["rangeselector"] = utils.rangeselector_date()
layout_args["yaxis"]["title"] = _("Pumping Amount") layout_args["yaxis"]["title"] = _("Pumping Amount")
total_labels = [{"x": x, "y": total*1.1, "text": str(total), "showarrow": False} for x, total in zip(list(dates), date_totals.values())] total_labels = [
{"x": x, "y": total * 1.1, "text": str(total), "showarrow": False}
for x, total in zip(list(dates), date_totals.values())
]
fig = go.Figure({"data": traces, "layout": go.Layout(**layout_args)}) fig = go.Figure({"data": traces, "layout": go.Layout(**layout_args)})
fig.update_layout(barmode="stack", annotations=total_labels) fig.update_layout(barmode="stack", annotations=total_labels)
output = plotly.plot(fig, output_type="div", include_plotlyjs=False) output = plotly.plot(fig, output_type="div", include_plotlyjs=False)