def getMonthlyPerformance():
when_all = {<EOL>'<STR_LIT>': False,<EOL>'<STR_LIT>': False,<EOL>}<EOL>series_counts = list(Series.objects.annotate(<EOL>eventregistrations=Sum(Case(When(Q(**when_all),then=<NUM_LIT:1>),output_field=IntegerField())),)<EOL>.values('<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>'))<EOL>for series in series_counts:<EOL><INDENT>series['<STR_LIT>'] = (series.get('<STR_LIT>') or <NUM_LIT:0>) * (series.get('<STR_LIT>') or <NUM_LIT:0>)<EOL><DEDENT>all_years = set([x['<STR_LIT>'] for x in series_counts])<EOL>dataseries_list = ['<STR_LIT>', '<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']<EOL>yearTotals = {}<EOL>for dataseries in dataseries_list:<EOL><INDENT>yearTotals[dataseries] = {'<STR_LIT>': {}}<EOL>for year in all_years:<EOL><INDENT>yearTotals[dataseries][year] = {}<EOL><DEDENT><DEDENT>for year in all_years:<EOL><INDENT>for month in range(<NUM_LIT:1>,<NUM_LIT>):<EOL><INDENT>yearTotals['<STR_LIT>'][year][month] = sum([x['<STR_LIT>'] or <NUM_LIT:0> for x in series_counts if x['<STR_LIT>'] == month and x['<STR_LIT>'] == year])<EOL>yearTotals['<STR_LIT>'][year][month] = len(Registration.objects.filter(eventregistration__dropIn=False, eventregistration__cancelled=False,eventregistration__event__year=year,eventregistration__event__month=month).distinct())<EOL>yearTotals['<STR_LIT>'][year][month] = sum([x['<STR_LIT>'] or <NUM_LIT:0> for x in series_counts if x['<STR_LIT>'] == month and x['<STR_LIT>'] == year])<EOL>yearTotals['<STR_LIT>'][year][month] = sum([x['<STR_LIT>'] or <NUM_LIT:0> for x in series_counts if x['<STR_LIT>'] == month and x['<STR_LIT>'] == year])<EOL>if yearTotals['<STR_LIT>'][year][month] > <NUM_LIT:0>:<EOL><INDENT>yearTotals['<STR_LIT>'][year][month] = yearTotals['<STR_LIT>'][year][month] / float(yearTotals['<STR_LIT>'][year][month])<EOL><DEDENT>else:<EOL><INDENT>yearTotals['<STR_LIT>'][year][month] = <NUM_LIT:0><EOL><DEDENT><DEDENT>for sub_series in ['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']:<EOL><INDENT>yearTotals[sub_series][year]['<STR_LIT>'] = sum([x for x in yearTotals[sub_series][year].values()])<EOL><DEDENT>month_count = len([x for k,x in yearTotals['<STR_LIT>'][year].items() if k in range(<NUM_LIT:1>,<NUM_LIT>) and x > <NUM_LIT:0>])<EOL>if month_count > <NUM_LIT:0>:<EOL><INDENT>for sub_series in ['<STR_LIT>','<STR_LIT>','<STR_LIT>','<STR_LIT>']:<EOL><INDENT>yearTotals[sub_series][year]['<STR_LIT>'] = yearTotals[sub_series][year]['<STR_LIT>'] / float(month_count)<EOL><DEDENT>yearTotals['<STR_LIT>'][year]['<STR_LIT>'] = yearTotals['<STR_LIT>'][year]['<STR_LIT>'] / float(yearTotals['<STR_LIT>'][year]['<STR_LIT>'])<EOL><DEDENT><DEDENT>for month in range(<NUM_LIT:1>,<NUM_LIT>):<EOL><INDENT>yearly_hours_data = [x[month] for k,x in yearTotals['<STR_LIT>'].items() if k in all_years and x[month] > <NUM_LIT:0>]<EOL>yearly_studenthours_data = [x[month] for k,x in yearTotals['<STR_LIT>'].items() if k in all_years and x[month] > <NUM_LIT:0>]<EOL>yearly_eventregistrations_data = [x[month] for k,x in yearTotals['<STR_LIT>'].items() if k in all_years and yearTotals['<STR_LIT>'][k][month] > <NUM_LIT:0>]<EOL>yearly_registrations_data = [x[month] for k,x in yearTotals['<STR_LIT>'].items() if k in all_years and yearTotals['<STR_LIT>'][k][month] > <NUM_LIT:0>]<EOL>year_count = len(yearly_hours_data)<EOL>if year_count > <NUM_LIT:0>:<EOL><INDENT>yearTotals['<STR_LIT>']['<STR_LIT>'][month] = sum([x for x in yearly_eventregistrations_data]) / year_count<EOL>yearTotals['<STR_LIT>']['<STR_LIT>'][month] = sum([x for x in yearly_registrations_data]) / year_count<EOL>yearTotals['<STR_LIT>']['<STR_LIT>'][month] = sum([x for x in yearly_hours_data]) / year_count<EOL>yearTotals['<STR_LIT>']['<STR_LIT>'][month] = sum([x for x in yearly_studenthours_data]) / year_count<EOL>yearTotals['<STR_LIT>']['<STR_LIT>'][month] = yearTotals['<STR_LIT>']['<STR_LIT>'][month] / float(yearTotals['<STR_LIT>']['<STR_LIT>'][month])<EOL><DEDENT><DEDENT>return yearTotals<EOL>
This function does the work of compiling monthly performance data
that can either be rendered as CSV or as JSON