• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.get_stat_data函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中wazimap.data.utils.get_stat_data函数的典型用法代码示例。如果您正苦于以下问题:Python get_stat_data函数的具体用法?Python get_stat_data怎么用?Python get_stat_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_stat_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_households_profile

def get_households_profile(geo, session, year):
    with dataset_context(year=year):
        try:
            permanency, _ = get_stat_data('household percentage by permanency', geo,
                                          session,
                                          table_fields=[
                                              'household percentage by permanency'])
        except Exception:
            permanency = LOCATIONNOTFOUND

        try:
            light_source, total_households = get_stat_data(
                'household distribution by light source', geo,
                session, table_fields=['household distribution by light source'])
            energy_source, _ = get_stat_data(
                'household distribution by energy source', geo, session,
                table_fields=['household distribution by energy source'])
        except Exception:
            total_households = 0
            light_source = LOCATIONNOTFOUND
            energy_source, _ = LOCATIONNOTFOUND, 0

        is_missing = permanency.get('is_missing') and light_source.get('is_missing') and energy_source.get('is_missing')

        final_data = {
            'is_missing': is_missing,
            'percentage_by_permanency': permanency,
            'light_source_distribution': light_source,
            'energy_source_distribution': energy_source,
            'total_households': {
                "name": "Households",
                "values": {"this": total_households}
            }
        }
    return final_data
开发者ID:CodeForAfrica,项目名称:HURUmap-apps,代码行数:35,代码来源:census.py


示例2: get_disabilities_profile

def get_disabilities_profile(geocode, geo_level, session):
    try:
        disabled_or_not, total_ = get_stat_data('disabled or not', geo_level, geocode, session,
                                                table_fields=['disabled or not'])
        disability, _ = get_stat_data('disability', geo_level, geocode, session, table_fields=['disability'])
    except LocationNotFound:
        disabled_or_not, total_ = LOCATIONNOTFOUND, 0
        disability = LOCATIONNOTFOUND

    total_disabled = 0
    for data, value in disabled_or_not.get('With disability', {}).iteritems():
        if data == 'numerators':
            total_disabled += value['this']

    final_data = {
        'disabled_or_not_distribution': disabled_or_not,
        'disability': disability,
        'total_disabled': {
            'name': 'Disabled',
            'numerators': {'this': total_disabled},

        },

        'total_': {
            "name": "Population",
            "values": {"this": total_}
        }
    }
    try:
        final_data['total_disabled']['values'] = {
            'this': round(total_disabled / total_ * 100, 2)}
    except ZeroDivisionError:
        final_data['total_disabled']['values'] = {'this': 0}
    return final_data
开发者ID:kollinsayz,项目名称:Wazimap.Uganda,代码行数:34,代码来源:profiles.py


示例3: get_ITN_profile

def get_ITN_profile(geo_code, geo_level, session):
    # household possession and use of ITN
    possession_dist, _ = get_stat_data(['household possession of itn'], geo_level, geo_code, session)

    households_with_at_least_one_itn = \
        possession_dist['Households with at least one ITN']['numerators']['this']
    households_with_at_least_one_itn = get_dictionary('Possess at least one ITN', 'No ITN', households_with_at_least_one_itn, possession_dist)

    percentage_households_with_ITN_for_every_two_people = \
        possession_dist['Percentage households with ITN for every 2 people in household']['numerators']['this']
    percentage_households_with_ITN_for_every_two_people = get_dictionary('1:2',\
                                                                         'less than 1:2',\
                                                                         percentage_households_with_ITN_for_every_two_people, possession_dist)

    average_itn_per_household = possession_dist['Average ITN per household']['numerators']['this']

    use_dist, _ = get_stat_data(['household', 'users', 'itn_use'], geo_level, geo_code, session)
    households_with_at_least_one_itn_use_dist = use_dist['With at least one ITN']
    all_households_use_dist = use_dist['All']

    return {
        'households_with_at_least_one_itn': households_with_at_least_one_itn,
        'percentage_households_with_ITN_for_every_two_people': percentage_households_with_ITN_for_every_two_people,
        'average_itn_per_household': {
            'name': 'Average number of insecticide-treated nets (ITNs) per household',
            'numerators': {'this': average_itn_per_household},
            'values': {'this': average_itn_per_household},
            'metadata': possession_dist['metadata']
        },
        'households_with_at_least_one_itn_use_dist': households_with_at_least_one_itn_use_dist,
        'all_households_use_dist': all_households_use_dist
    }
开发者ID:CodeForAfrica,项目名称:Wazimap.Kenya,代码行数:32,代码来源:profiles.py


示例4: get_demographics_profile

def get_demographics_profile(geo_code, geo_level, session):
    try:
        sex_dist_data, total_pop = get_stat_data('sex', geo_level, geo_code, session, table_fields=['sex'])
        urban_dist_data, _ = get_stat_data('rural or urban', geo_level, geo_code, session,
                                           table_fields=['rural or urban'])
    except LocationNotFound:
        sex_dist_data, total_pop = LOCATIONNOTFOUND, 0
        urban_dist_data = LOCATIONNOTFOUND

    total_urbanised = 0
    for data, value in urban_dist_data.get('Urban', {}).iteritems():
        if data == 'numerators':
            total_urbanised += value['this']

    final_data = {
        'sex_ratio': sex_dist_data,
        'urban_distribution': urban_dist_data,
        'urbanised': {
            'name': 'In urban areas',
            'numerators': {'this': total_urbanised},

        },
        'total_population': {
            "name": "People",
            "values": {"this": total_pop}
        }}
    try:
        final_data['urbanised']['values'] = {
            'this': round(total_urbanised / total_pop * 100, 2)}
    except ZeroDivisionError:
        final_data['urbanised']['values'] = {'this': 0}
    return final_data
开发者ID:kollinsayz,项目名称:Wazimap.Uganda,代码行数:32,代码来源:profiles.py


示例5: get_contraceptive_use_profile

def get_contraceptive_use_profile(geo_code, geo_level, session):
    # contraceptive_use stats
    contraceptive_use_dist_data, _ = get_stat_data(
        'contraceptive_use', geo_level, geo_code, session,
        key_order=['Modern', 'Traditional', 'Not using'])

    modern = contraceptive_use_dist_data['Modern']['numerators']['this']
    traditional = contraceptive_use_dist_data['Traditional']['numerators']['this']
    cpr = modern + traditional

    contraceptive_modern_method_dist_data, _ = get_stat_data(
        'contraceptive_modern_method', geo_level, geo_code, session)
    contraceptive_traditional_method_dist_data, _ = get_stat_data(
        'contraceptive_traditional_method', geo_level, geo_code, session)

    return  {
        'contraceptive_use_distribution': contraceptive_use_dist_data,
        'modern_methods_distribution': contraceptive_modern_method_dist_data,
        'traditional_methods_distribution': contraceptive_traditional_method_dist_data,
        'cpr': {
            'name': 'Contraceptive prevalence rate',
            'numerators': {'this': cpr},
            'values': {'this': cpr},
        },
    }
开发者ID:CodeForAfrica,项目名称:Wazimap.Kenya,代码行数:25,代码来源:profiles.py


示例6: get_child_households_profile

def get_child_households_profile(geo_code, geo_level, session):
    # head of household
    # gender
    head_gender_dist, total_households = get_stat_data(
            ['gender of head of household'], geo_level, geo_code, session,
            order_by='gender of head of household',
            table_name='genderofheadofhouseholdunder18')
    female_heads = head_gender_dist['Female']['numerators']['this']

    # annual household income
    income_dist_data, _ = get_stat_data(
            ['annual household income'], geo_level, geo_code, session,
            exclude=['Unspecified'],
            recode=HOUSEHOLD_INCOME_RECODE,
            key_order=HOUSEHOLD_INCOME_RECODE.values(),
            table_name='annualhouseholdincomeunder18')

    # median income
    median = calculate_median_stat(income_dist_data)
    median_income = HOUSEHOLD_INCOME_ESTIMATE[median]

    # type of dwelling
    type_of_dwelling_dist, _ = get_stat_data(
            ['type of main dwelling'], geo_level, geo_code, session,
            recode=TYPE_OF_DWELLING_RECODE,
            order_by='-total')
    informal = type_of_dwelling_dist['Shack']['numerators']['this']

    # size of household
    household_size_dist, _ = get_stat_data(
        ['household size', 'age of household head'],
        geo_level, geo_code, session
    )

    return {
        'total_households': {
            'name': 'Households with heads under 18 years old',
            'values': {'this': total_households},
        },
        'type_of_dwelling_distribution': type_of_dwelling_dist,
        'informal': {
            'name': 'Child-headed households that are informal dwellings (shacks)',
            'values': {'this': percent(informal, total_households)},
            'numerators': {'this': informal},
        },
        'annual_income_distribution': income_dist_data,
        'median_annual_income': {
            'name': 'Average annual child-headed household income',
            'values': {'this': median_income},
        },
        'household_size_distribution': household_size_dist,
        'head_of_household': {
            'gender_distribution': head_gender_dist,
            'female': {
                'name': 'Child-headed households with women as their head',
                'values': {'this': percent(female_heads, total_households)},
                'numerators': {'this': female_heads},
                },
        },
    }
开发者ID:lamb003,项目名称:wazimap-za,代码行数:60,代码来源:census.py


示例7: get_demographics_profile

def get_demographics_profile(geo_code, geo_level, session):
    pop_dist_data, pop_total = get_stat_data(
            ['population group'], geo_level, geo_code, session)

    youth_pop_dist_data, youth_pop_total = get_stat_data(['age in completed years'], geo_level, geo_code, session, table_name='youth_gender_age_in_completed_years')

    youth_gender_data, _ = get_stat_data(['gender'], geo_level, geo_code, session, table_name='youth_gender_population_group')
    youth_pop_group_data, _ = get_stat_data(['population group'], geo_level, geo_code, session, table_name='youth_gender_population_group')

    final_data = {
        'total_population': {
            "name": "People",
            "values": {"this": pop_total}
        },
        'youth_population_total': {
            "name": "Youth aged 15-24",
            "values": {"this": youth_pop_total}
        },
        'youth_population_perc': {
            "name": "Of population are youth aged 15-24",
            "values": {"this": percent(youth_pop_total, pop_total)},
        },
        'youth_population_by_year': youth_pop_dist_data,
        'youth_population_by_gender': youth_gender_data,
        'youth_population_by_pop_group': youth_pop_group_data
    }

    geo = geo_data.get_geography(geo_code, geo_level)
    if geo.square_kms:
        final_data['population_density'] = {
            'name': "people per square kilometre",
            'values': {"this": pop_total / geo.square_kms}
        }

    return final_data
开发者ID:lamb003,项目名称:wazimap-za,代码行数:35,代码来源:youth.py


示例8: get_demographics_profile

def get_demographics_profile(geo, session):
    year = current_context().get('year')

    with dataset_context(year=year):
        # gender
        gender_dist_data, total_pop = get_stat_data(
            'gender', geo, session,
            table_fields=['gender', 'age group'])

        # age group
        age_group_dist_data, _ = get_stat_data(
            'age group', geo, session,
            table_fields=['gender', 'age group'])
        total_under_15 = age_group_dist_data['0-14 Years']['numerators']['this']

        # rural or urban
        rural_dist_data, _ = get_stat_data(
            ['rural or urban','gender'], geo, session,
            table_fields=['gender', 'rural or urban'])

    final_data = {
        'gender_ratio': gender_dist_data,
        'age_group_distribution': age_group_dist_data,
        'under_15': {
            'name': 'Under 15 years',
            'values': {'this': total_under_15}
        },
        'rural_distribution': rural_dist_data,
        'total_population': {
            "name": "People",
            "values": {"this": total_pop}
        }}

    return final_data
开发者ID:CodeForAfrica,项目名称:HURUmap-apps,代码行数:34,代码来源:profiles.py


示例9: get_households_profile

def get_households_profile(geo, session):
    # head of household
    # gender
    head_gender_dist, total_households = get_stat_data(
        ['gender of household head'], geo, session,
        order_by='gender of household head')
    female_heads = head_gender_dist['Female']['numerators']['this']

    # age
    db_model_u18 = get_model_from_fields(
        ['gender of head of household'], geo.geo_level,
        table_name='genderofheadofhouseholdunder18'
    )
    objects = get_objects_by_geo(db_model_u18, geo, session)
    total_under_18 = float(sum(o[0] for o in objects))

    # type of dwelling
    type_of_dwelling_dist, _ = get_stat_data(
        ['type of dwelling'], geo, session,
        recode=TYPE_OF_DWELLING_RECODE,
        order_by='-total')
    informal = type_of_dwelling_dist['Shack']['numerators']['this']

    _, total_ecd_children = get_stat_data(
        ['age in completed years'], geo, session,
        table_name='ageincompletedyears',
        only=['0', '1', '2', '3', '4', '5'])

    ecd_children_per_household = ratio(total_ecd_children, total_households)

    return {
        'total_households': {
            'name': 'Households',
            'values': {'this': total_households},
        },
        'type_of_dwelling_distribution': type_of_dwelling_dist,
        'informal': {
            'name': 'Households that are informal dwellings (shacks)',
            'values': {'this': percent(informal, total_households)},
            'numerators': {'this': informal},
        },
        'head_of_household': {
            'gender_distribution': head_gender_dist,
            'female': {
                'name': 'Households with women as their head',
                'values': {'this': percent(female_heads, total_households)},
                'numerators': {'this': female_heads},
            },
            'under_18': {
                'name': 'Households with heads under 18 years old',
                'values': {'this': total_under_18},
            }
        },
        'ecd_children_per_household': {
            'name': 'Average number of children (aged 0-5) in each household',
            'values': {'this': ecd_children_per_household},
        },
    }
开发者ID:Code4SA,项目名称:wazimap-za,代码行数:58,代码来源:ecd.py


示例10: get_land_audit_profile

def get_land_audit_profile(geo, session):
    year = current_context().get('year')
    with dataset_context(year=year):
        land_use_dist = LOCATIONNOTFOUND
        land_user_dist = LOCATIONNOTFOUND
        land_distribution_gender = LOCATIONNOTFOUND
        land_ownership = LOCATIONNOTFOUND

        try:
            land_use_dist, _ = get_stat_data('land_use', geo, session,
                                             table_name='landuse',
                                             table_fields=['land_use'])
        except Exception as e:
            pass

        try:
            land_user_dist, _ = get_stat_data('land_user', geo, session,
                                              table_name='landuser',
                                              table_fields=['land_user'])
        except Exception:
            pass

        try:
            land_distribution_gender, _ = get_stat_data(
                'land_ownership_by_gender', geo, session,
                table_name='privatelanddistributionbygender',
                table_fields=['land_ownership_by_gender'])
        except Exception:
            pass

        try:
            land_ownership, _ = get_stat_data('private_vs_state_ownership', geo,
                                              session,
                                              table_name='landownership',
                                              table_fields=[
                                                  'private_vs_state_ownership'])
        except Exception:
            pass

        is_missing = land_user_dist.get('is_missing') and \
                     land_use_dist.get('is_missing') and \
                     land_distribution_gender.get('is_missing') and \
                     land_ownership.get('is_missing')

    return {
        'is_missing': is_missing,
        'land_user_dist': land_user_dist,
        'land_use_dist': land_use_dist,
        'land_distribution_gender': land_distribution_gender,
        'land_ownership': land_ownership,
    }
开发者ID:CodeForAfrica,项目名称:HURUmap-apps,代码行数:51,代码来源:land.py


示例11: get_households_profile

def get_households_profile(geocode, geo_level, session):
    try:
        light_source, total_households = get_stat_data('household distribution by light source', geo_level, geocode,
                                                       session, table_fields=['household distribution by light source'])
        energy_source, _ = get_stat_data('household distribution by energy source', geo_level, geocode, session,
                                         table_fields=['household distribution by energy source'])
    except LocationNotFound:
        household_dist, total_households = LOCATIONNOTFOUND, 0
        light_source = LOCATIONNOTFOUND
        energy_source, _ = LOCATIONNOTFOUND, 0

    total_electrified_lighting = 0
    for data, value in light_source.get('Electricity', {}).iteritems():
        if data == 'numerators':
            total_electrified_lighting += value['this']

    total_charcoal_energy = 0
    for data, value in energy_source.get('Charcoal', {}).iteritems():
        if data == 'numerators':
            total_charcoal_energy += value['this']

    final_data = {
        'light_source_distribution': light_source,
        'electrified_lighting': {
            'name': 'Lighting with Electricity',
            'numerators': {'this': total_electrified_lighting},

        },
        'energy_source_distribution': energy_source,
        'charcoal_energy': {
            'name': 'Cooking with Charcoal',
            'numerators': {'this': total_charcoal_energy},
        },
        'total_households': {
            "name": "Households",
            "values": {"this": total_households}
        }
    }
    try:
        final_data['electrified_lighting']['values'] = {
            'this': round(total_electrified_lighting / total_households * 100, 2)}
    except ZeroDivisionError:
        final_data['electrified_lighting']['values'] = {'this': 0}

    try:
        final_data['charcoal_energy']['values'] = {
            'this': round(total_electrified_lighting / _ * 100, 2)}
    except ZeroDivisionError:
        final_data['charcoal_energy']['values'] = {'this': 0}
    return final_data
开发者ID:kollinsayz,项目名称:Wazimap.Uganda,代码行数:50,代码来源:profiles.py


示例12: get_demographics_profile

def get_demographics_profile(geo, session, year):
    with dataset_context(year=year):
        geo.version = str(geo.version)
        # sex
        try:
            sex_dist_data, total_pop = get_stat_data(
                'sex', geo, session,
                table_fields=['sex'])

        except Exception:
            sex_dist_data = LOCATIONNOTFOUND
            total_pop = 0


        # urban/rural by sex
        total_urbanised = 0
        try:
            urban_dist_data, _ = get_stat_data(
                ['rural or urban'], geo, session,
                table_fields=['rural or urban'])

            for data in urban_dist_data['Urban'].values():
                if 'numerators' in data:
                    total_urbanised += data['numerators']['this']

        except Exception:
            urban_dist_data = LOCATIONNOTFOUND

        is_missing = sex_dist_data.get('is_missing') and urban_dist_data.get('is_missing')

        final_data = {
            'is_missing': is_missing,
            'sex_ratio': sex_dist_data,
            'urban_distribution': urban_dist_data,
            'urbanised': {
                'name': 'In urban areas',
                'numerators': {'this': total_urbanised},

            },
            'total_population': {
                "name": "People",
                "values": {"this": total_pop}
            }}
        try:
            final_data['urbanised']['values'] = {
                'this': round(total_urbanised / total_pop * 100, 2)}
        except ZeroDivisionError:
            final_data['urbanised']['values'] = {'this': 0}
    return final_data
开发者ID:CodeForAfrica,项目名称:HURUmap-apps,代码行数:49,代码来源:census.py


示例13: get_type_treatment_profile

def get_type_treatment_profile(geo_code, geo_level, session):
    # Treatment for acute respiratory infection symptoms, fever, and diarrhoea stats
    dist, _ = get_stat_data(['type', 'treatment'], geo_level, geo_code, session,
                            key_order={
                                'type': ['ARI', 'Fever','Diarrhoea'],
                                'treatment': ['Sought treatment from health facility or provider', \
                                              'ORT', 'Zinc', 'ORS and zinc','Fluid from ORS packet'
                                              ]
                            })
    # need to use numerators instead of values
    for key in dist:
        if key == 'metadata': continue
        for other_key in dist[key]:
            if other_key == 'metadata': continue
            try:
                dist[key][other_key]['values']['this'] = dist[key][other_key]['numerators']['this']
            except:
                dist[key][other_key] = {'values': {'this': 0}, 'numerators': {'this': 0}}

    ari = dist['ARI']['Sought treatment from health facility or provider']['numerators']['this']
    fever = dist['Fever']['Sought treatment from health facility or provider']['numerators']['this']
    dist.pop('ARI')
    dist.pop('Fever')
    ari_dist = get_dictionary('Sought', 'Did not seek', ari, dist)
    fever_dist = get_dictionary('Sought', 'Did not seek', fever, dist)


    treatment_of_chidren_with_fever_dist, _ = get_stat_data(['treatment of children with fever'], geo_level, geo_code, session)
    children_with_fever = treatment_of_chidren_with_fever_dist['Had fever']['numerators']['this']
    treatment_of_chidren_with_fever_dist.pop('Had fever')

    # need to use numerators instead of values
    for v in treatment_of_chidren_with_fever_dist:
        if v == 'metadata': continue
        treatment_of_chidren_with_fever_dist[v]['values']['this'] = treatment_of_chidren_with_fever_dist[v]['numerators']['this']


    return {
        'treatment_distribution': dist,
        'ari_dist': ari_dist,
        'fever_dist': fever_dist,
        'treatment_of_chidren_with_fever_dist': treatment_of_chidren_with_fever_dist,
        'children_with_fever': {
            'name': 'Percentage of children with fever in the two weeks preceding the survey',
            'numerators': {'this': children_with_fever},
            'values': {'this': children_with_fever},
            'metadata': dist['metadata']
        },
    }
开发者ID:CodeForAfrica,项目名称:Wazimap.Kenya,代码行数:49,代码来源:profiles.py


示例14: get_population

def get_population(geo, session):
    with dataset_context(year='2017'):
        sex_dist, total_population_sex = LOCATIONNOTFOUND, 0
        residence_dist, total_population_residence = LOCATIONNOTFOUND, 0
        religion_dist, total_population_religion = LOCATIONNOTFOUND, 0

        try:
            sex_dist, total_population_sex = get_stat_data(
                'sex', geo, session, table_fields=['sex'])
        except Exception:
            pass
        try:
            residence_dist, total_population_residence = get_stat_data(
                'residence', geo, session,
                table_fields=['residence'])
        except Exception:
            pass

        try:
            religion_dist, total_population_religion = get_stat_data(
                'religion', geo, session,
                table_fields=['religion'])
        except Exception:
            pass

        total_population = 0
        is_missing = sex_dist.get('is_missing') and \
            residence_dist.get('is_missing') and \
                     religion_dist.get('is_missing')
        if not is_missing:
            total_population = total_population_sex if total_population_sex > 0 else total_population_residence
        total_population_dist = _create_single_value_dist(
            'People', total_population)

    demographics_data = {
        'is_missing': is_missing,
        'sex_dist': sex_dist,
        'residence_dist': residence_dist,
        'religion_dist': religion_dist,
        'total_population': total_population_dist,
    }

    if geo.square_kms:
        demographics_data['population_density'] = {
            'name': "people per square kilometre",
            'values': {"this": total_population / geo.square_kms},
        }
    return demographics_data
开发者ID:CodeForAfrica,项目名称:HURUmap-apps,代码行数:48,代码来源:census.py


示例15: get_pupil_teacher_ratios_profile

def get_pupil_teacher_ratios_profile(geo_code, geo_level, session):
    # pupil teacher ratios
    ratio_data, _ = get_stat_data(
        'pupil teacher ratios', geo_level, geo_code, session)

    pupil_teacher_ratio = ratio_data['Pupil teacher ratio']['numerators']['this']
    pupils_per_textbook = ratio_data['Pupils per textbook']['numerators']['this']

    pupil_attendance_rate_dist = \
        ratio_data['Government school attendance rate']['numerators']['this']
    pupil_attendance_rate_dist = get_dictionary("Attending school", "Absent", pupil_attendance_rate_dist)

    teachers_absent_dist = ratio_data['Teachers absent']['numerators']['this']
    teachers_absent_dist = get_dictionary("Teachers absent", "Teachers present", teachers_absent_dist)

    return  {
        'pupil_attendance_rate_dist': pupil_attendance_rate_dist,
        'teachers_absent_dist': teachers_absent_dist,
        'pupil_teacher_ratio': {
            'name': 'For every one teacher there are ' +  str(pupil_teacher_ratio) + " pupils",
            'numerators': {'this': pupil_teacher_ratio},
            'values': {'this': pupil_teacher_ratio}
        },
        'pupils_per_textbook': {
            'name': 'Pupils per textbook',
            'numerators': {'this': pupils_per_textbook},
            'values': {'this': pupils_per_textbook}
        }
    }
开发者ID:CodeForAfricaLabs,项目名称:Wazimap.Tanzania,代码行数:29,代码来源:profiles.py


示例16: get_elections2016_profile

def get_elections2016_profile(geocode, geo_level, session):
    try:
        candidate, total_votes = get_stat_data('presidential candidate', geo_level, geocode, session,
                                               table_fields=['presidential candidate'])
    except LocationNotFound:
        candidate, total_votes = LOCATIONNOTFOUND, 0

    total_besigye = 0
    for data, value in candidate.get('Kizza besigye', {}).iteritems():
        if data == 'numerators':
            total_besigye += value['this']

    final_data = {
        'candidate_distribution': candidate,
        'besigye_votes': {
            'name': 'Besigye Votes',
            'numerators': {'this': total_besigye},

        },

        'total_votes': {
            "name": "Votes",
            "values": {"this": total_votes}
        }
    }
    try:
        final_data['besigye_votes']['values'] = {
            'this': round(total_besigye / total_votes * 100, 2)}
    except ZeroDivisionError:
        final_data['besigye_votes']['values'] = {'this': 0}
    return final_data
开发者ID:kollinsayz,项目名称:Wazimap.Uganda,代码行数:31,代码来源:profiles.py


示例17: get_fertility_profile

def get_fertility_profile(geo_code, geo_level, session):
    # fertility
    dist, _ = get_stat_data(['fertility'], geo_level, geo_code, session)

    percentage_women_age_15_49_currently_pregnant = dist['Pregnant']['numerators']['this']

    percentage_women_age_15_49_currently_pregnant = get_dictionary('Pregnant', 'Not pregnant',\
                                                                   percentage_women_age_15_49_currently_pregnant, dist)

    fertility_rate = dist['Rate']['numerators']['this']
    mean_number_of_children_ever_born_to_women_aged_40_49 =  dist['Mean']['numerators']['this']

    return {
        'percentage_women_age_15_49_currently_pregnant': percentage_women_age_15_49_currently_pregnant,
        'fertility_rate': {
            'name': 'Fertility',
            'numerators': {'this': fertility_rate},
            'values': {'this': fertility_rate},
            'metadata': dist['metadata']
        },
        'mean_number_of_children_ever_born_to_women_aged_40_49': {
            'name': 'Mean number of children ever born to women aged 40-49',
            'numerators': {'this': mean_number_of_children_ever_born_to_women_aged_40_49},
            'values': {'this': mean_number_of_children_ever_born_to_women_aged_40_49},
            'metadata': dist['metadata']
        },

    }
开发者ID:CodeForAfrica,项目名称:Wazimap.Kenya,代码行数:28,代码来源:profiles.py


示例18: get_economics_profile

def get_economics_profile(geo_code, geo_level, session):
    # income
    income_dist_data, total_workers = get_stat_data(
            ['employed individual monthly income'], geo_level, geo_code, session,
            exclude=['Not applicable'],
            recode=COLLAPSED_INCOME_CATEGORIES,
            key_order=COLLAPSED_INCOME_CATEGORIES.values())

    # median income
    median = calculate_median_stat(income_dist_data)
    median_income = ESTIMATED_INCOME_CATEGORIES[median]

    # employment status
    employ_status, total_workers = get_stat_data(
            ['official employment status'], geo_level, geo_code, session,
            exclude=['Age less than 15 years', 'Not applicable'],
            order_by='official employment status',
            table_name='officialemploymentstatus')

    # sector
    sector_dist_data, _ = get_stat_data(
            ['type of sector'], geo_level, geo_code, session,
            exclude=['Not applicable'],
            order_by='type of sector')

    # access to internet
    internet_access_dist, total_with_access = get_stat_data(
            ['access to internet'], geo_level, geo_code, session, exclude=['No access to internet'],
            order_by='access to internet')
    _, total_without_access = get_stat_data(
            ['access to internet'], geo_level, geo_code, session, only=['No access to internet'])
    total_households = total_with_access + total_without_access

    return {'individual_income_distribution': income_dist_data,
            'median_individual_income': {
                'name': 'Average monthly income',
                'values': {'this': median_income},
                },
            'employment_status': employ_status,
            'sector_type_distribution': sector_dist_data,
            'internet_access_distribution': internet_access_dist,
            'internet_access': {
                'name': 'Households with internet access',
                'values': {'this': percent(total_with_access, total_households)},
                'numerators': {'this': total_with_access},
                }
            }
开发者ID:lamb003,项目名称:wazimap-za,代码行数:47,代码来源:census.py


示例19: get_vaccinations_profile

def get_vaccinations_profile(geo_code, geo_level, session):
    # vaccinations
    dist, _ = get_stat_data(['vaccinations'], geo_level, geo_code, session,
                            key_order=['BCG','Pentavalent 1','Pentavalent 2','Pentavalent 3','Polio 0','Polio 1', \
                                       'Polio 2','Polio 3','Measles','Pneumococcal 1', \
                                       'Pneumococcal 2','Pneumococcal 3',],
                            only=['BCG','Pentavalent 1','Pentavalent 2','Pentavalent 3','Polio 0','Polio 1', \
                                  'Polio 2','Polio 3','Measles','Pneumococcal 1', \
                                  'Pneumococcal 2','Pneumococcal 3',],
                            )

    # need to use numerators instead of values
    for key in dist:
        if key == 'metadata':
            continue
        dist[key]['values']['this'] = dist[key]['numerators']['this']

    vacc_dist, _ = get_stat_data(['vaccinations'], geo_level, geo_code, session,
                                 # only=['All basic vaccinations', 'Percentage with vaccination card',\
                                 # 'Fully vaccinated', 'Not vaccinated'],
                                 )

    fully_vaccinated = vacc_dist['Fully vaccinated']['numerators']['this']
    fully_vaccinated = get_dictionary('Fully vaccinated', 'Not fully vaccinated', fully_vaccinated, dist)

    all_basic_vaccinations = vacc_dist['All basic vaccinations']['numerators']['this']
    all_basic_vaccinations = get_dictionary('All basic vaccinations', 'Basic vaccinations not administered', \
                                            all_basic_vaccinations, dist)

    percentage_with_vaccination_cards = vacc_dist['Percentage with vaccination card']['numerators']['this']
    percentage_with_vaccination_cards = get_dictionary('Have vaccination cards', 'No vaccination cards',\
                                                       percentage_with_vaccination_cards, dist)
    not_vaccinated = vacc_dist['Not vaccinated']['numerators']['this']

    return {
        'distribution': dist,
        'fully_vaccinated': fully_vaccinated,
        'all_basic_vaccinations': all_basic_vaccinations,
        'percentage_with_vaccination_cards': percentage_with_vaccination_cards,
        'not_vaccinated': {
            'name': 'Not vaccinated',
            'numerators': {'this': not_vaccinated},
            'values': {'this': not_vaccinated},
            'metadata': dist['metadata']
        },
    }
开发者ID:CodeForAfrica,项目名称:Wazimap.Kenya,代码行数:46,代码来源:profiles.py


示例20: test_get_stat_data_nulls

    def test_get_stat_data_nulls(self):
        self.field_table(['gender'], """
lev,code,Male,10
lev,code,Female,
""")
        data, total = get_stat_data(['gender'], self.geo, self.s)
        self.assertEqual(total, 10)
        self.assertEqual(data['Male']['numerators']['this'], 10)
        self.assertEqual(data['Male']['values']['this'], 100)
        self.assertIsNone(data['Female']['numerators']['this'])
        self.assertIsNone(data['Female']['values']['this'])

        data, total = get_stat_data(['gender'], self.geo, self.s, percent=False)
        self.assertEqual(total, 10)
        self.assertIsNone(data['Male']['numerators']['this'])
        self.assertEqual(data['Male']['values']['this'], 10)
        self.assertIsNone(data['Female']['numerators']['this'])
        self.assertIsNone(data['Female']['values']['this'])
开发者ID:CodeForAfrica,项目名称:wazimap,代码行数:18,代码来源:test_utils.py



注:本文中的wazimap.data.utils.get_stat_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wb_common.dprint_ex函数代码示例发布时间:2022-05-26
下一篇:
Python appengine_robot_runner.run函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap