From 11bb6163b7d3c983a0ba9fa2221fb4e00798ee2e Mon Sep 17 00:00:00 2001 From: bugbountyguy Date: Wed, 30 Mar 2022 23:19:07 -0500 Subject: [PATCH] Fix bug when date is updated to earlier date --- reports/graphs/pumping_amounts.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/reports/graphs/pumping_amounts.py b/reports/graphs/pumping_amounts.py index fe288cca..a5f2f6aa 100644 --- a/reports/graphs/pumping_amounts.py +++ b/reports/graphs/pumping_amounts.py @@ -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)