Merge pull request #25787 from akhilnarang/dashboard-chart-fix-KeyError

fix: errors with dashboard chart
This commit is contained in:
Akhil Narang 2024-04-04 11:41:50 +05:30 committed by GitHub
commit 0f15ecf1c2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -260,7 +260,7 @@ def get_heatmap_chart_config(chart, filters, heatmap_year):
}
def get_group_by_chart_config(chart, filters):
def get_group_by_chart_config(chart, filters) -> dict | None:
aggregate_function = get_aggregate_function(chart.group_by_type)
value_field = chart.aggregate_function_based_on or "1"
group_by_field = chart.group_by_based_on
@ -281,11 +281,10 @@ def get_group_by_chart_config(chart, filters):
if data:
return {
"labels": [item["name"] if item["name"] else "Not Specified" for item in data],
"labels": [item.get("name", "Not Specified") for item in data],
"datasets": [{"name": chart.name, "values": [item["count"] for item in data]}],
}
else:
return None
return None
def get_aggregate_function(chart_type):
@ -304,8 +303,8 @@ def get_result(data, timegrain, from_date, to_date, chart_type):
for d in result:
count = 0
while data_index < len(data) and getdate(data[data_index][0]) <= d[0]:
d[1] += data[data_index][1]
count += data[data_index][2]
d[1] += cint(data[data_index][1])
count += cint(data[data_index][2])
data_index += 1
if chart_type == "Average" and count != 0:
d[1] = d[1] / count