Skip to content

Commit

Permalink
Update wazimap dep to 1.1.1 with geo object changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cliftonmcintosh committed Dec 1, 2019
1 parent 4da5abe commit 458e6de
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 52 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Django==1.9.10
django-cors-headers==2.4.1
gunicorn==19.5.0
wazimap[gdal]==0.8.2
wazimap[gdal]==1.1.1
GDAL==2.1.3
Shapely==1.5.17
whitenoise==3.3.1
Expand Down
9 changes: 6 additions & 3 deletions wazimap_np/agriculture.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from wazimap.data.utils import get_stat_data


def get_agriculture_profile(geo_code, geo_level, session):
land_dist, total_land = get_stat_data(['Agricultural land use area'], geo_level, geo_code, session,
def get_agriculture_profile(geo, session):
land_dist, total_land = get_stat_data(['Agricultural land use area'],
geo,
session,
percent=True,
order_by='-total')

holding_dist, total_holding = get_stat_data(['Agricultural holdings size by land tenure'], geo_level, geo_code,
holding_dist, total_holding = get_stat_data(['Agricultural holdings size by land tenure'],
geo,
session,
percent=True,
order_by='-total')
Expand Down
17 changes: 7 additions & 10 deletions wazimap_np/demographics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
('Deaf-Blind', 'Deaf and Blind')
])

def get_demographics_profile(geo_code, geo_level, session):

def get_demographics_profile(geo, session):
pop_data, total_pop = get_stat_data(
'sex', geo_level, geo_code, session,
'sex', geo, session,
table_fields=['sex'],
table_name='population')

Expand All @@ -29,24 +30,20 @@ def get_demographics_profile(geo_code, geo_level, session):
}
}

religion_data, _ = get_stat_data(['religion name'], geo_level,
geo_code, session,
order_by='-total')
religion_data, _ = get_stat_data(['religion name'], geo, session, order_by='-total')
most_populous_religion = religion_data[religion_data.keys()[0]]

# language
language_data, _ = get_stat_data(
['language'], geo_level, geo_code, session, order_by='-total')
language_data, _ = get_stat_data(['language'], geo, session, order_by='-total')
language_most_spoken = language_data[language_data.keys()[0]]

# caste or ethnic group
caste_data, _ = get_stat_data(['caste or ethnic group'], geo_level,
geo_code, session, order_by='-total')
caste_data, _ = get_stat_data(['caste or ethnic group'], geo, session, order_by='-total')
most_populous_caste = caste_data[caste_data.keys()[0]]

# population by disability
disability_dist_data, total_disabled = get_stat_data(
'disability', geo_level, geo_code, session,
'disability', geo, session,
table_fields=['disability', 'sex'],
recode=dict(DISABILITY_RECODES),
key_order=DISABILITY_RECODES.values(),
Expand Down
10 changes: 5 additions & 5 deletions wazimap_np/education.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
])


def get_education_profile(geo_code, geo_level, session):
def get_education_profile(geo, session):
edu_level_reached, pop_five_and_older = get_stat_data(
'education level passed', geo_level, geo_code, session,
'education level passed', geo, session,
recode=dict(EDUCATION_LEVEL_PASSED_RECODES),
key_order=EDUCATION_LEVEL_PASSED_RECODES.values())

Expand All @@ -37,7 +37,7 @@ def get_education_profile(geo_code, geo_level, session):
total_primary += data['numerators']['this']

all_edu_level_by_sex, _ = get_stat_data(
['education level passed', 'sex'], geo_level, geo_code, session,
['education level passed', 'sex'], geo, session,
recode={
'education level passed': dict(EDUCATION_LEVEL_PASSED_RECODES)},
key_order={
Expand All @@ -59,15 +59,15 @@ def get_education_profile(geo_code, geo_level, session):
total_secondary_by_sex += data['numerators']['this']

literacy_by_sex, t_lit = get_stat_data(
['literacy', 'sex'], geo_level, geo_code, session,
['literacy', 'sex'], geo, session,
recode={'literacy': dict(LITERACY_RECODES)},
key_order={
'literacy': LITERACY_RECODES.values(),
'sex': ['Female', 'Male']},
percent_grouping=['sex'])

literacy_dist, _ = get_stat_data(
'literacy', geo_level, geo_code, session,
'literacy', geo, session,
recode=dict(LITERACY_RECODES),
key_order=LITERACY_RECODES.values())

Expand Down
20 changes: 10 additions & 10 deletions wazimap_np/households.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@
])


def get_households_profile(geo_code, geo_level, session):
def get_households_profile(geo, session):
sex_dist_data, total_pop = get_stat_data(
'sex', geo_level, geo_code, session,
'sex', geo, session,
table_fields=['sex'],
table_name='population')

# home ownership
home_ownership_dict, total_households = get_stat_data(
'home ownership', geo_level, geo_code, session,
'home ownership', geo, session,
recode=dict(HOME_OWNERSHIP_RECODES),
key_order=HOME_OWNERSHIP_RECODES.values())
total_own_home = home_ownership_dict['Owned']['numerators']['this']
Expand All @@ -99,52 +99,52 @@ def get_households_profile(geo_code, geo_level, session):

# drinking water source
drinking_water_dict, _ = get_stat_data(
'drinking water source', geo_level, geo_code, session,
'drinking water source', geo, session,
recode=dict(DRINKING_WATER_RECODES),
order_by='-total')
total_piped_tap = drinking_water_dict['Piped Tap']['numerators']['this']

# lighting fuel
lighting_fuel_dict, _ = get_stat_data(
'lighting fuel', geo_level, geo_code, session,
'lighting fuel', geo, session,
recode=dict(LIGHTING_FUEL_RECODES),
order_by='-total')
total_electricity = lighting_fuel_dict['Electricity']['numerators']['this']

# cooking fuel
cooking_fuel_dict, total_households = get_stat_data(
'main type of cooking fuel', geo_level, geo_code, session,
'main type of cooking fuel', geo, session,
recode=dict(COOKING_FUEL_RECODES),
key_order=COOKING_FUEL_RECODES.values())
total_wood = cooking_fuel_dict['Wood']['numerators']['this']

# toilet type
toilet_type_dict, _ = get_stat_data(
'toilet type', geo_level, geo_code, session,
'toilet type', geo, session,
recode=dict(TOILET_TYPE_RECODES),
key_order=TOILET_TYPE_RECODES.values())
total_flush_toilet = toilet_type_dict['Flush (Septic)']['numerators']['this'] \
+ toilet_type_dict['Flush (Sewerage)']['numerators']['this']

# foundation type
foundation_type_dict, _ = get_stat_data(
'foundation type', geo_level, geo_code, session,
'foundation type', geo, session,
recode=dict(FOUNDATION_TYPE_RECODES),
key_order=FOUNDATION_TYPE_RECODES.values())
total_mud_bonded_foundation = \
foundation_type_dict['Mud Bonded']['numerators']['this']

# outer wall type
outer_wall_type_dict, _ = get_stat_data(
'outer wall type', geo_level, geo_code, session,
'outer wall type', geo, session,
recode=dict(OUTER_WALL_TYPE_RECODES),
key_order=OUTER_WALL_TYPE_RECODES.values())
total_mud_bonded_wall = \
outer_wall_type_dict['Mud Bonded']['numerators']['this']

# roof type
roof_type_dict, _ = get_stat_data(
'roof type', geo_level, geo_code, session,
'roof type', geo, session,
recode=dict(ROOF_TYPE_RECODES),
key_order=ROOF_TYPE_RECODES.values())
total_galvanized_roof = \
Expand Down
42 changes: 23 additions & 19 deletions wazimap_np/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,55 @@
'45099', '49099', '58099', '67099', '68099', '69099', '70099', '72099', '76099', '77099'}


def should_have_data(geo_code, geo_level):
return not (geo_level == 'local' and geo_code in park_geo_codes)
def should_have_data(geo):
return not (geo.geo_level == 'local' and geo.geo_code in park_geo_codes)


def get_census_profile(geo_code, geo_level, profile_name=None):
def get_census_profile(geo, _profile_name, _request):
session = get_session()

try:
geo_summary_levels = geo_data.get_summary_geo_info(geo_code, geo_level)
comparative_geos = geo_data.get_comparative_geos(geo)
data = {}

for section in PROFILE_SECTIONS:
function_name = 'get_%s_profile' % section
if function_name in globals():
func = globals()[function_name]
if should_have_data(geo_code, geo_level):
data[section] = func(geo_code, geo_level, session)
if should_have_data(geo):
data[section] = func(geo, session)
# Get profiles for province and/or country
for level, code in geo_summary_levels:
# merge summary profile into current geo profile
merge_dicts(data[section], func(code, level, session),
level)
for comp_geo in comparative_geos:
try:
merge_dicts(data[section], func(comp_geo, session), comp_geo.geo_level)
except KeyError as e:
msg = "Error merging data into %s for section '%s' from %s: KeyError: %s" % (
geo.geoid, section, comp_geo.geoid, e)
# log.fatal(msg, exc_info=e)
raise ValueError(msg)
else:
return {'area_has_no_data': True}
finally:
session.close()

if geo_level != 'vdc':
if geo.geo_level != 'vdc':
group_remainder(data['demographics']['language_distribution'], 10)
group_remainder(data['demographics']['ethnic_distribution'], 10)

return data


def get_demographics_profile(geo_code, geo_level, session):
return demographics.get_demographics_profile(geo_code, geo_level, session)
def get_demographics_profile(geo, session):
return demographics.get_demographics_profile(geo, session)


def get_agriculture_profile(geo_code, geo_level, session):
return agriculture.get_agriculture_profile(geo_code, geo_level, session)
def get_agriculture_profile(geo, session):
return agriculture.get_agriculture_profile(geo, session)


def get_households_profile(geo_code, geo_level, session):
return households.get_households_profile(geo_code, geo_level, session)
def get_households_profile(geo, session):
return households.get_households_profile(geo, session)


def get_education_profile(geo_code, geo_level, session):
return education.get_education_profile(geo_code, geo_level, session)
def get_education_profile(geo, session):
return education.get_education_profile(geo, session)
11 changes: 7 additions & 4 deletions wazimap_np/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
WAZIMAP['url'] = URL
WAZIMAP['country_code'] = 'NP'
WAZIMAP['profile_builder'] = 'wazimap_np.profiles.get_census_profile'
WAZIMAP['default_geo_version'] = '2016'
WAZIMAP['levels'] = {
'country': {
'plural': 'countries',
Expand All @@ -43,10 +44,12 @@
}
WAZIMAP['comparative_levels'] = ['country', 'province', 'district', 'local']
WAZIMAP['geometry_data'] = {
'country': 'geo/country.topojson',
'province': 'geo/province.topojson',
'district': 'geo/district.topojson',
'local': 'geo/local.topojson'
'2016': {
'country': 'geo/country.topojson',
'province': 'geo/province.topojson',
'district': 'geo/district.topojson',
'local': 'geo/local.topojson'
}
}

WAZIMAP['ga_tracking_id'] = os.environ.get('GA_TRACKING_ID')
Expand Down

0 comments on commit 458e6de

Please sign in to comment.