Exemple #1
0
def get_map_context(context):
    '''
    In the map page we pass the level 1 and 2 indicators to the
    template with the `indicators` variable. It has the following form:

    [
        {
            'code': '1',
            'title': 'Governance',
            'level': 1,
            'core': True,
            'indicators': [
                {
                    'code': '1.1',
                    'title': 'International Framework',
                    'level': 2,
                    'core': True,
                },
                {
                    'code': '1.2',
                    'title': 'National Law',
                    'level': 2,
                    'core': True,
                },
                ...
            ]
        },
        {
            'code': '2',
            'title': 'Availability',
            'level': 1,
            'core': True,
            'indicators': [
                ...
            ]
        },
        ...
    ]

    We also pass the `themes` variable to build the second menu, with
    identical format.

    '''
    context['indicators'] = data.get_indicators()
    context['themes'] = data.get_themes()
Exemple #2
0
def get_country_context(context, country_code, year):
    '''In the RTEI by Country page we pass the following variables:

    * `available_countries`: a dict with the countries where data is avaiable,
        ordered alphabetically by name:

        {
            'CL': 'Chile',
            'NG: 'Nigeria',
            ...
        }

    Only if there is a country selected (via `id` param):

    * `country_code`
    * `country_name`
    * `country_indicators`: full indicators data for the country, in the form:

        {
            '1': 74.34,
            '1.1': 23.43,
            '1.1.1': None,
            ...
        }

    * `chart_data`: data necessary to build the C3 chart for just this
        particular country, eg:

            [{
                'name': 'Tanzania',
                'index': 64.063,
                '1': 16.91,
                '3': 15.92,
                '2': 8.68,
                '5': 8.32,
                '4': 14.24
            }]

    '''

    if country_code:
        country_data = data.get_indicators_for_country(country_code, year)
        if not country_data:
            raise Http404(_('No data available for this country'))

        context['country_code'] = country_code

        context['country_name'] = data.get_country_name(country_code)

        context['country_indicators'] = country_data

        for country in data.get_c3_scores_per_country(year):
            if country['name'] == context['country_name']:
                chart_data = country
                break

        context['chart_data'] = json.dumps([chart_data])
        context['indicators'] = data.get_indicators(year)
        context['themes'] = data.get_themes(year)

        context['chart_labels'] = json.dumps(
            get_chart_labels(context['indicators'], context['themes']))

    context['available_countries'] = OrderedDict(
        sorted({
            code: data.get_country_name(code)
            for code, c in data.get_scores_per_country(year).iteritems()
        }.items(),
               key=lambda t: t[1]))
Exemple #3
0
def get_theme_context(context, year):
    context['indicators'] = data.get_indicators(year)
    context['themes'] = data.get_themes(year)
    context['chart_labels'] = json.dumps(
        get_chart_labels(context['indicators'], context['themes']))
Exemple #4
0
def get_country_context(context, country_code):
    '''In the RTEI by Country page we pass the following variables:

    * `available_countries`: a dict with the countries where data is avaiable,
        ordered alphabetically by name:

        {
            'CL': 'Chile',
            'NG: 'Nigeria',
            ...
        }

    Only if there is a country selected (via `id` param):

    * `country_code`
    * `country_name`
    * `country_indicators`: full indicators data for the country, in the form:

        {
            '1': 74.34,
            '1.1': 23.43,
            '1.1.1': None,
            ...
        }

    * `chart_data`: data necessary to build the C3 chart for just this
        particular country, eg:

            [{
                'name': 'Tanzania',
                'index': 64.063,
                '1': 16.91,
                '3': 15.92,
                '2': 8.68,
                '5': 8.32,
                '4': 14.24
            }]

    '''

    if country_code:
        country_data = data.get_indicators_for_country(country_code)
        if not country_data:
            raise Http404(_('No data available for this country'))

        context['country_code'] = country_code

        context['country_name'] = data.get_country_name(country_code)

        context['country_indicators'] = country_data

        for country in data.get_c3_scores_per_country():
            if country['name'] == context['country_name']:
                chart_data = country
                break

        context['chart_data'] = json.dumps([chart_data])
        context['indicators'] = data.get_indicators()
        context['themes'] = data.get_themes()

        context['chart_labels'] = json.dumps(
            get_chart_labels(context['indicators'], context['themes']))

    context['available_countries'] = OrderedDict(
        sorted({code: data.get_country_name(code) for code, c
                in data.get_scores_per_country().iteritems()}.items(),
               key=lambda t: t[1]))
Exemple #5
0
def get_theme_context(context):
    context['indicators'] = data.get_indicators()
    context['themes'] = data.get_themes()
    context['chart_labels'] = json.dumps(
        get_chart_labels(context['indicators'], context['themes']))