Ejemplo n.º 1
0
def agency_table_by_agency(request, agency_id, language="English", template_name="submissions/agency_table.html", extra_context=None):
    extra_context = extra_context or {} 
    agency = get_object_or_404(models.Agency, pk=agency_id)

    extra_context["translation"] = translation = request.translation
    abs_values = {}
    for country in agency.countries:
        country_abs_values = {}
        inds = indicators.calc_agency_country_indicators(agency, country, indicators.positive_funcs)
        ratings = target.country_agency_indicator_ratings(country, agency)
        for indicator in inds:
            base_val, base_year, latest_val, latest_year = inds[indicator][0]
            country_abs_values[indicator] = {
                "base_val" : tbl_float_format(base_val), 
                "latest_val" : tbl_float_format(latest_val), 
                "perc_change" : tbl_float_format(perc_change(base_val, latest_val)),
                "base_year" : base_year,
                "latest_year" : latest_year,
                "rating" : ratings[indicator]
            } 
        abs_values[country.country] = country_abs_values
    extra_context["abs_values"] = sorted(abs_values.items())
    extra_context["spm_map"] = translation.spm_map
    extra_context["institution_name"] = translation.by_agency_title % agency.agency
    
    return direct_to_template(request, template=template_name, extra_context=extra_context)
Ejemplo n.º 2
0
def agency_table_by_indicator(request, indicator, language="English", template_name="submissions/agency_table_by_indicator.html", extra_context=None):
    dp_gov_map = {
        "1DP" : "1G",
        "2DPa" : "2Ga",
        "2DPb" : "2Gb",
        "3DP" : "3G",
        "4DP" : "4G",
        "5DPa" : "5Gb",
        "5DPb" : "5Ga",
        "6DP" : "6G",
        "7DP" : "7G",
        "8DP" : "8G",
    }
    extra_context = extra_context or {} 
    extra_context["translation"] = request.translation

    country_calcs = None
    countries = models.Country.objects.all().order_by("country")
    if indicator in dp_gov_map:
        gov_indicator = dp_gov_map[indicator]
        country_calcs = [(c, target.calc_country_ratings(c)[gov_indicator]) for c in countries]
    
    agencies = []
    for agency in models.Agency.objects.all():
        agency_values = []
        for country in countries:
            if country in agency.countries:
                inds = indicators.calc_agency_country_indicators(agency, country, indicators.positive_funcs)
                ratings = target.country_agency_indicator_ratings(country, agency)

                base_val, base_year, latest_val, cur_year = inds[indicator][0]
                country_abs_values = {
                    "baseline_value" : tbl_float_format(base_val), 
                    "base_year" : base_year,
                    "latest_value" : tbl_float_format(latest_val), 
                    "cur_year" : cur_year,
                    "rating" : ratings[indicator],
                    "cellclass" : "",
                } 
            else:
                country_abs_values = {
                    "baseline_value" : "",
                    "base_year" : "",
                    "latest_value" : "",
                    "cur_year" : "",
                    "rating" : "",
                    "cellclass" : "notactive",
                } 
                
            agency_values.append((country, country_abs_values))
        agency_values = sorted(agency_values, key=lambda x: x[0].country)
        agencies.append((agency, agency_values))

    agencies = sorted(agencies, key=lambda x: x[0].agency)
    extra_context["agencies"] = agencies
    extra_context["countries"] = countries
    extra_context["country_calcs"] = country_calcs
    
    return direct_to_template(request, template=template_name, extra_context=extra_context)
Ejemplo n.º 3
0
def country_agency_indicator_ratings(country, agency):
    """
    Evaluate ratings for a country-agency per indicator
    """
    indicators = {}
    targets = get_agency_targets(agency, dp_indicators)
    country_indicators = calc_agency_country_indicators(agency, country)

    for indicator in country_indicators:
        v = country_indicators[indicator]
        debug("extracting %s from %s" % (indicator, str(country_indicators)))
        values, comments = v
        (base_val, base_year, cur_val, cur_year) = values

        target = targets[indicator]
        result = evaluate_agency_country_indicator(agency, country, target, base_val, cur_val)
        indicators[indicator] = result
    return indicators
Ejemplo n.º 4
0
def country_agency_indicator_ratings(country, agency):
    """
    Evaluate ratings for a country-agency per indicator
    """
    indicators = {}
    targets = get_agency_targets(agency, dp_indicators)
    country_indicators = calc_agency_country_indicators(agency, country)

    for indicator in country_indicators:
        v = country_indicators[indicator]
        #TODO - temporary hack until 8DP is fixed
        if indicator == "8DP":
            indicators[indicator] = "tick"
        else:
            debug("extracting %s from %s" % (indicator, str(country_indicators)))
            values, comments = v
            (base_val, base_year, cur_val, cur_year) = values

            target = targets[indicator]
            result = evaluate_agency_country_indicator(agency, country, target, base_val, cur_val)
            indicators[indicator] = result
    return indicators
Ejemplo n.º 5
0
def countrygraphs(request, country_name, language, template_name="submissions/countrygraphs.html", extra_context=None):
    extra_context = extra_context or {}

    translation = request.translation
    country = Country.objects.get(country__iexact=country_name)
    
    data = {}
    for agency in country.agencies:
        agency_data = {}
        indicators = calc_agency_country_indicators(agency, country)
        for indicator in ["2DPa", "2DPb", "2DPc", "3DP", "4DP", "5DPa", "5DPb", "5DPc"]:
            base_val, _, latest_val, _ = indicators[indicator][0]
            agency_data[indicator] = calc_graph_values(indicator, base_val, latest_val)
        data[agency.agency] = agency_data

    country_name = country.country
    extra_context["graph_2DPa"] = CountryAgencyLatestBarGraph(
        country.agencies, "graph_2DPa", 
        [data[agency.agency]["2DPa"][1] for agency in country.agencies],
        title=translation.country_graphs["2DPa"]["title"] % locals(),
        yAxis=translation.country_graphs["2DPa"]["yAxis"] % locals(),
    )

    extra_context["graph_2DPb"] = CountryAgencyBarGraph(
        country.agencies, "graph_2DPb",
        [data[agency.agency]["2DPb"][0] for agency in country.agencies],
        [data[agency.agency]["2DPb"][1] for agency in country.agencies],
        title=translation.country_graphs["2DPb"]["title"] % locals(),
        yAxis=translation.country_graphs["2DPb"]["yAxis"] % locals(),
    )

    extra_context["graph_2DPc"] = CountryAgencyBarGraph(
        country.agencies, "graph_2DPc",
        [data[agency.agency]["2DPc"][0] for agency in country.agencies],
        [data[agency.agency]["2DPc"][1] for agency in country.agencies],
        title=translation.country_graphs["2DPc"]["title"] % locals(),
        yAxis=translation.country_graphs["2DPc"]["yAxis"] % locals(),
    )

    extra_context["graph_3DP"] = CountryAgencyBarGraph(
        country.agencies, "graph_3DP",
        [data[agency.agency]["3DP"][0] for agency in country.agencies],
        [data[agency.agency]["3DP"][1] for agency in country.agencies],
        title=translation.country_graphs["3DP"]["title"] % locals(),
        yAxis=translation.country_graphs["3DP"]["yAxis"] % locals(),
    )

    extra_context["graph_4DP"] = CountryAgencyBarGraph(
        country.agencies, "graph_4DP",
        [data[agency.agency]["4DP"][0] for agency in country.agencies],
        [data[agency.agency]["4DP"][1] for agency in country.agencies],
        title=translation.country_graphs["4DP"]["title"] % locals(),
        yAxis=translation.country_graphs["4DP"]["yAxis"] % locals(),
    )

    extra_context["graph_5DPa"] = CountryAgencyLatestBarGraph(
        country.agencies, "graph_5DPa",
        [data[agency.agency]["5DPa"][1] for agency in country.agencies],
        title=translation.country_graphs["5DPa"]["title"] % locals(),
        yAxis=translation.country_graphs["5DPa"]["yAxis"] % locals(),
    )

    extra_context["graph_5DPb"] = CountryAgencyLatestBarGraph(
        country.agencies, "graph_5DPb",
        [data[agency.agency]["5DPb"][1] for agency in country.agencies],
        title=translation.country_graphs["5DPb"]["title"] % locals(),
        yAxis=translation.country_graphs["5DPb"]["yAxis"] % locals(),
    )

    extra_context["graph_5DPc"] = CountryAgencyBarGraph(
        country.agencies, "graph_5DPc",
        [data[agency.agency]["5DPc"][0] for agency in country.agencies],
        [data[agency.agency]["5DPc"][1] for agency in country.agencies],
        title=translation.country_graphs["5DPc"]["title"] % locals(),
        yAxis=translation.country_graphs["5DPc"]["yAxis"] % locals(),
    )
    
    return direct_to_template(request, template=template_name, extra_context=extra_context)
Ejemplo n.º 6
0
def agencygraphs(request, agency_name, language=None, template_name="submissions/agencygraphs.html", extra_context=None):
    extra_context = extra_context or {}

    agency = Agency.objects.get(agency__iexact=agency_name)
    extra_context["translation"] = translation = request.translation

    data = {}
    for country in agency.countries:
        country_data = {}
        indicators = calc_agency_country_indicators(agency, country)
        for indicator in ["2DPa", "2DPb", "2DPc", "3DP", "4DP", "5DPa", "5DPb", "5DPc"]:
            base_val, _, latest_val, _ = indicators[indicator][0]
            country_data[indicator] = calc_graph_values(indicator, base_val, latest_val)
        data[country.country] = country_data
    
    agency_name = agency.agency

    extra_context["graph_2DPa"] = AgencyCountryLatestBarGraph(
        agency.countries, "graph_2DPa", 
        [data[country.country]["2DPa"][1] for country in agency.countries],
        title=translation.agency_graphs["2DPa"]["title"] % locals(),
        yAxis=translation.agency_graphs["2DPa"]["yAxis"],
    )

    extra_context["graph_2DPb"] = AgencyCountryBarGraph(
        agency.countries, "graph_2DPb",
        [data[country.country]["2DPb"][0] for country in agency.countries],
        [data[country.country]["2DPb"][1] for country in agency.countries],
        title=translation.agency_graphs["2DPb"]["title"] % locals(),
        yAxis=translation.agency_graphs["2DPb"]["yAxis"],
    )

    extra_context["graph_2DPc"] = AgencyCountryBarGraph(
        agency.countries, "graph_2DPc",
        [data[country.country]["2DPc"][0] for country in agency.countries],
        [data[country.country]["2DPc"][1] for country in agency.countries],
        title=translation.agency_graphs["2DPc"]["title"] % locals(),
        yAxis=translation.agency_graphs["2DPc"]["yAxis"],
    )

    extra_context["graph_3DP"] = AgencyCountryBarGraph(
        agency.countries, "graph_3DP",
        [data[country.country]["3DP"][0] for country in agency.countries],
        [data[country.country]["3DP"][1] for country in agency.countries],
        title=translation.agency_graphs["3DP"]["title"],
        yAxis=translation.agency_graphs["3DP"]["yAxis"],
    )

    extra_context["graph_4DP"] = AgencyCountryBarGraph(
        agency.countries, "graph_4DP",
        [data[country.country]["4DP"][0] for country in agency.countries],
        [data[country.country]["4DP"][1] for country in agency.countries],
        title=translation.agency_graphs["4DP"]["title"] % agency.agency,
        yAxis=translation.agency_graphs["4DP"]["yAxis"],
    )

    extra_context["graph_5DPa"] = AgencyCountryLatestBarGraph(
        agency.countries, "graph_5DPa",
        [data[country.country]["5DPa"][1] for country in agency.countries],
        title=translation.agency_graphs["5DPa"]["title"],
        yAxis=translation.agency_graphs["5DPa"]["yAxis"],
    )

    extra_context["graph_5DPb"] = AgencyCountryLatestBarGraph(
        agency.countries, "graph_5DPb",
        [data[country.country]["5DPb"][1] for country in agency.countries],
        title=translation.agency_graphs["5DPb"]["title"] % agency.agency,
        yAxis=translation.agency_graphs["5DPb"]["yAxis"],
    )

    extra_context["graph_5DPc"] = AgencyCountryBarGraph(
        agency.countries, "graph_5DPc",
        [data[country.country]["5DPc"][0] for country in agency.countries],
        [data[country.country]["5DPc"][1] for country in agency.countries],
        title=translation.agency_graphs["5DPc"]["title"] % agency.agency,
        yAxis=translation.agency_graphs["5DPc"]["yAxis"],
    )
    
    return direct_to_template(request, template=template_name, extra_context=extra_context)