def highlevelgraphs(request, language, template_name="submissions/highlevelgraphs.html", extra_context=None, titles=None): extra_context = extra_context or {} translation = request.translation indicators = calc_overall_agency_indicators(funcs=positive_funcs) for indicator in indicators: (baseline_value, _, latest_value, _) = indicators[indicator][0] name = "graph_%s" % indicator.lower() if indicator not in ["5DPc"]: graph = highlevel_graph_by_indicator(indicator, name, translation, baseline_value, latest_value, target_values[indicator]) else: graph = highlevel_graph_by_indicator(indicator, name, translation, baseline_value, latest_value) extra_context["graph_%s" % indicator] = graph agency_data = dict([(agency, agency_scorecard.get_agency_scorecard_data(agency)) for agency in Agency.objects.all()]) extra_context["graph_pfm"] = additional_graph_by_indicator("5DPb", "graph_pfm", translation, agency_data) extra_context["graph_procurement"] = additional_graph_by_indicator("5DPa", "graph_procurement", translation, agency_data) extra_context["graph_multi_year"] = additional_graph_by_indicator("3DP", "graph_multi_year", translation, agency_data) extra_context["graph_pba"] = additional_graph_by_indicator("2DPc", "graph_pba", translation, agency_data) extra_context["graph_tc"] = additional_graph_by_indicator("2DPb", "graph_tc", translation, agency_data) extra_context["graph_aob"] = additional_graph_by_indicator("2DPa", "graph_aob", translation, agency_data) return direct_to_template(request, template=template_name, extra_context=extra_context)
def agency_graphs_by_indicator(request, indicator, language, template_name="submissions/agency_graphs_by_indicator.html", extra_context=None): extra_context = extra_context or {} translation = request.translation indicators = calc_overall_agency_indicators(funcs=positive_funcs) extra_context["graphs"] = graphs = [] name = "graph_%s" % indicator (baseline_value, baseline_year, latest_value, latest_year) = indicators[indicator][0] target = target_values[indicator] graph = highlevel_graph_by_indicator(indicator, name, translation, baseline_value, latest_value, target=target) graphs.append({ "name" : name, "obj" : graph }) agency_data = dict([(agency, agency_scorecard.get_agency_scorecard_data(agency)) for agency in Agency.objects.all()]) name = "graph2_%s" % indicator graph = additional_graph_by_indicator(indicator, name, translation, agency_data) graphs.append({ "name" : name, "obj" : graph }) return direct_to_template(request, template=template_name, extra_context=extra_context)
def projectiongraphs(request, language, template_name="submissions/projectiongraphs.html", extra_context=None): extra_context = extra_context or {} translation = request.translation indicators = calc_overall_agency_indicators(funcs=positive_funcs) for indicator in ["2DPa", "5DPb"]: (baseline_value, baseline_year, latest_value, latest_year) = indicators[indicator][0] baseline_year, latest_year = int(baseline_year), int(latest_year) target_value = target_values[indicator] # Find the intersection point between the horizontal target line and the trend line # i.e. x = (y - c)/m m = (latest_value - baseline_value) / (latest_year - baseline_year) c = baseline_value intersection = (target_value - c) / m + baseline_year y = lambda x : m * (x - baseline_year) + c start_year = baseline_year end_year = int(round(intersection, 0) + 1) target_data = [target_value] * (end_year - start_year + 1) actual_data = [y(year) for year in range(start_year, latest_year + 1)] projected_data = [(year - start_year, y(year)) for year in range(latest_year, end_year + 1)] graph = DPChart("graph_%s" % indicator.lower()) graph.chart = { "marginTop" : 50, "defaultSeriesType": "line", } graph.title = {"text" : translation.projection_graphs[indicator]["title"]} graph.xAxis = {"categories" : range(start_year, end_year + 1)} graph.yAxis = {"title" : {"text" : ""}} graph.series = [{ "name" : "Actual", "data" : actual_data }, { "name" : "Projected", "data" : projected_data, "dashStyle" : "shortDash", "color" : "#89A54E", }, { "name": translation.target_language["target"], "data": target_data, "marker": { "enabled": "false" }, }] extra_context["graph_%s" % indicator] = graph return direct_to_template(request, template=template_name, extra_context=extra_context)