Skip to content

Commit

Permalink
Merge pull request #20 from amitness/dev
Browse files Browse the repository at this point in the history
Present total population and population by gender
  • Loading branch information
cliftonmcintosh authored Oct 30, 2018
2 parents c4fabab + 8420e99 commit 2ee965e
Show file tree
Hide file tree
Showing 8 changed files with 1,797 additions and 11 deletions.
1,702 changes: 1,702 additions & 0 deletions sql/population.sql

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions wazimap_np/demographics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from collections import OrderedDict


from wazimap.data.tables import get_datatable, get_model_from_fields
from wazimap.data.utils import get_stat_data, get_objects_by_geo, \
calculate_median


def get_demographics_profile(geo_code, geo_level, session):
demographic_data = {
"is_vdc": True,
"has_data": True
}
pop_data, total_pop = get_stat_data(
'sex', geo_level, geo_code, session,
table_fields=['sex'],
table_name='population')
demographic_data['pop_dist'] = pop_data
demographic_data['total_population'] = {
"name": "People",
"values": {"this": total_pop}
}
return demographic_data
34 changes: 23 additions & 11 deletions wazimap_np/profiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from wazimap.data.utils import get_session, merge_dicts, group_remainder
from wazimap.geo import geo_data


from wazimap_np import (
demographics,
)

# ensure tables are loaded

# TODO: keeping this tuple because it is referenced in function code, may be needed to bring back
Expand All @@ -17,6 +22,9 @@
# 'households'
# )

PROFILE_SECTIONS = (
'demographics',
)

def get_census_profile(geo_code, geo_level, profile_name=None):
session = get_session()
Expand All @@ -26,23 +34,27 @@ def get_census_profile(geo_code, geo_level, profile_name=None):
data = {}

# TODO: commented out because all the other dependent functions are removed, take action if needed
# for section in PROFILE_SECTIONS:
# function_name = 'get_%s_profile' % section
# if function_name in globals():
# func = globals()[function_name]
# data[section] = func(geo_code, geo_level, session)
for section in PROFILE_SECTIONS:
function_name = 'get_%s_profile' % section
if function_name in globals():
func = globals()[function_name]
data[section] = func(geo_code, geo_level, session)
#
# # get profiles for province and/or country
# for level, code in geo_summary_levels:
for level, code in geo_summary_levels:
# # merge summary profile into current geo profile
# merge_dicts(data[section], func(code, level, session),
# level)
merge_dicts(data[section], func(code, level, session),
level)

finally:
session.close()

if geo_level != 'vdc':
group_remainder(data['demographics']['language_distribution'], 10)
group_remainder(data['demographics']['ethnic_distribution'], 10)
# if 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)
2 changes: 2 additions & 0 deletions wazimap_np/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@
WAZIMAP['tagline'] = 'Explore and understand Nepal using data'
WAZIMAP['facebook'] = 'codefornepal'
WAZIMAP['twittercard'] = True

ROOT_URLCONF = 'wazimap_np.urls'
9 changes: 9 additions & 0 deletions wazimap_np/tables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from wazimap.data.tables import FieldTable, SimpleTable

FieldTable(['sex'],
id='population',
universe='Population',
description='Total Population',
dataset='National Population and Housing Census 2011',
year='2011',
table_per_level=False)
1 change: 1 addition & 0 deletions wazimap_np/templates/profile/profile_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

{% block profile_detail %}
<!-- TODO: do we keep the block? needs something here? -->
{% include 'profile/sections/demographics.html' %}
{% endblock %}
20 changes: 20 additions & 0 deletions wazimap_np/templates/profile/sections/demographics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<article id="demographics" class="clearfix">
{% if demographics.area_has_data == False %}
<h2>No data available for this area</h2>
{% else %}
<header class="section-contents">
<h1>Demographics</h1>
</header>
<div class="section-container">
<section class="clearfix stat-row">
<h2><a class="permalink" href="#demographics">Population <i
class="fa fa-link"></i></a></h2>
<div class="column-quarter">
{% include 'profile/_blocks/_stat_list.html' with stat=demographics.total_population stat_type='number' %}
</div>
<div class="column-three-quarters" id="chart-pie-demographics-pop_dist" data-stat-type="percentage" data-chart-title="Sex"></div>
</section>

</div>
{% endif %}
</article>
17 changes: 17 additions & 0 deletions wazimap_np/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from wazimap.urls import urlpatterns, STANDARD_CACHE_TIME
from django.conf.urls import url
from wazimap.views import GeographyDetailView
from django.views.decorators.cache import cache_page

profile_url_index = 3

urlpatterns.pop(profile_url_index)

urlpatterns.append(
url(
regex = '^profiles/(?P<geography_id>\w+-\w+-\w+)(-(?P<slug>[\w-]+))?/$',
view = cache_page(STANDARD_CACHE_TIME)(GeographyDetailView.as_view()),
kwargs = {},
name = 'geography_detail_country',
)
)

0 comments on commit 2ee965e

Please sign in to comment.