コード例 #1
0
ファイル: choropleth.py プロジェクト: chejennifer/website
def get_denoms_data(places, denom_stat_vars):
    """Get denominator time series given stat vars"""
    denoms_data_raw = dc_service.get_stat_set_series(
        list(places), list(denom_stat_vars)).get('data', {})
    denoms_data = {}
    # Covert data to compatible format
    for place, stat_data in denoms_data_raw.items():
        for stat_var, info in stat_data['data'].items():
            if 'val' in info:
                denoms_data[stat_var] = {
                    place: {
                        'data': info['val'],
                        'provenanceUrl': info['metadata']['provenanceUrl']
                    }
                }
    return denoms_data
コード例 #2
0
def get_stats_wrapper(places_str, stat_vars_str):
    """Wrapper function to get stats for multiple places and give stat var.

    This wrapper takes concatenated place dcids as a string argument so the
    flask cache can work.

    Args:
        places_str: place dcids concatenated by "^".
        stat_vars_str: stat var dcids concatenated by "^".
    Returns:
        An object keyed by the place dcid with values keyed by the stat var dcid
        with value to be the time series data.
    """
    places = places_str.split('^')
    stat_vars = stat_vars_str.split('^')
    result = dc.get_stat_set_series(places, stat_vars)['data']
    return json.dumps(result)