def MonthlyPerformanceJSON(request):
series = request.GET.get('series')
if series not in ['AvgStudents','Registrations','EventRegistrations','Hours','StudentHours']:
series = 'EventRegistrations'
yearTotals = getMonthlyPerformance()[series]
# Return JSON as lists, not as dictionaries, for c3.js
# yearTotals_list = [dict(v,**{'year':k}) for k, v in yearTotals.items()]
# Now make the lists so that there is one row per month, not one row per year,
# to make things easier for working with c3.js.yearTotals
monthTotals_list = []
years = list(set([k for k,v in yearTotals.items()]))
# Only include calendar months for graphing
for month in range(1,13):
this_month_data = {'month': month, 'month_name': month_name[month]}
for year in years:
this_month_data[year] = yearTotals[year].get(month)
monthTotals_list.append(this_month_data)
monthTotals_list_sorted = sorted(monthTotals_list, key=lambda k: k['month'])
return JsonResponse(monthTotals_list_sorted,safe=False)
评论列表
文章目录