Fix bug when date is updated to earlier date

This commit is contained in:
bugbountyguy 2022-03-30 23:19:07 -05:00 committed by Christopher Charbonneau Wells
parent 254e796020
commit 11bb6163b7
1 changed files with 8 additions and 9 deletions

View File

@ -18,16 +18,13 @@ def pumping_amounts(objects):
# We need to find date totals for annotations at the end
curr_date = ''
date_totals = [0.0]
index = -1
date_totals = {}
for object in objects:
date_s = str(object.time.date())
if curr_date != date_s:
index += 1
date_totals.append(0.0)
date_totals[date_s] = 0.0
curr_date = date_s
date_totals[index] += object.amount
date_totals.pop(-1)
date_totals[date_s] += object.amount
dates = [] # Single array for each bar
amounts = [] # Array of arrays containing amounts
@ -39,12 +36,14 @@ def pumping_amounts(objects):
index_y += 1
index_x = 0
if len(amounts) == 0 or len(amounts) <= index_x:
amounts.append([0]*len(date_totals))
amounts.append([0]*len(date_totals.keys()))
amounts[index_x][index_y] = object.amount
index_x += 1
traces = []
for i in range(0, len(date_totals)-1):
print(amounts)
print(len(date_totals.keys()))
for i in range(0, len(amounts)-1):
traces.append(
go.Bar(
name="Amount",
@ -62,7 +61,7 @@ def pumping_amounts(objects):
layout_args["xaxis"]["rangeselector"] = utils.rangeselector_date()
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)]
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.update_layout(barmode="stack", annotations=total_labels)
output = plotly.plot(fig, output_type="div", include_plotlyjs=False)