def project_data(request, project_id): project = get_object_or_404(Project, pk=project_id) result = __get_deficit_days_comparison( project, lambda d, g, t: analysis.monthly_deficit_pct(d, g), "Month") response = HttpResponse(content_type="application/json") result.to_json(response, orient='index') return response
def project_deficit_days_plot(request, project_id): project = get_object_or_404(Project, pk=project_id) data = __get_deficit_days_comparison( project, lambda d, g, t: analysis.monthly_deficit_pct(d, g), "Month") plt.style.use(DEFAULT_PLOT_STYLE) fig, ax = new_figure() data.plot(kind='bar', ax=ax, table=False) ax.set_title("Deficit days comparison") ax.yaxis.set_major_formatter(FuncFormatter(to_percent)) ax.set_ylim([0.0, 1.0]) return plot_to_response(fig)
def project_deficit_days_csv(request, project_id): project = get_object_or_404(Project, pk=project_id) monthly_result = __get_deficit_days_comparison(project, lambda d, g, t: analysis.monthly_deficit_pct(d, g), "Month") annual_result = __get_deficit_days_comparison(project, lambda d, g, t: analysis.annual_deficit_pct(d, g), "Annual Average").mean() annual_result.name = "Annual Average" result = pd.concat([monthly_result, annual_result.to_frame().transpose()], axis=0) result.index.name = "Month" response = HttpResponse(content_type="text/csv") result.to_csv(response) return response
def project_deficit_days_plot(request, project_id): project = get_object_or_404(Project, pk=project_id) data = __get_deficit_days_comparison( project, lambda d, g, t: analysis.monthly_deficit_pct(d, g), "Month" ) plt.style.use(DEFAULT_PLOT_STYLE) fig, ax = new_figure() data.plot(kind='bar', ax=ax, table=False) ax.set_title("Deficit days comparison") ax.yaxis.set_major_formatter(FuncFormatter(to_percent)) ax.set_ylim([0.0, 1.0]) return plot_to_response(fig)
def project_deficit_days_csv(request, project_id): project = get_object_or_404(Project, pk=project_id) monthly_result = __get_deficit_days_comparison( project, lambda d, g, t: analysis.monthly_deficit_pct(d, g), "Month") annual_result = __get_deficit_days_comparison( project, lambda d, g, t: analysis.annual_deficit_pct(d, g), "Annual Average").mean() annual_result.name = "Annual Average" result = pd.concat( [monthly_result, annual_result.to_frame().transpose()], axis=0) result.index.name = "Month" response = HttpResponse(content_type="text/csv") result.to_csv(response) return response
def deficit_days_plot_data(scenario): data = scenario.get_data() return analysis.monthly_deficit_pct(data, scenario.get_gap_attribute_name())