Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated the wazimap version 1.1.1 #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ coverage.xml

# Django stuff:
*.log
local_settings.py
#local_settings.py

# Flask stuff:
instance/
Expand Down Expand Up @@ -92,7 +92,7 @@ data/pandas-refrence
.idea
.vscode

static
#static
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
Expand Down
74 changes: 38 additions & 36 deletions janaganana/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,32 @@ def sort_stats_result(ip,key=None):
rv['metadata'] = metadata
return rv

def get_census_profile(geo_code, geo_level, profile_name=None):
def get_census_profile(geo, profile_name, request):

logger.info('Begin of transaction for {}: {}'.format(geo_level, geo_code))
#logger.info('Begin of transaction for {}: {}'.format(geo_level, geo_code))

session = get_session()
try:
geo_summary_levels = geo_data.get_summary_geo_info(geo_code, geo_level)
geo_summary_levels = 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]
data[section] = func(geo_code, geo_level, session)
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)
return data

for comp_geo in geo_summary_levels:
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)
logger.fatal(msg, exc_info=e)
raise ValueError(msg)
finally:
logger.info('End of transaction for {}: {}'.format(geo_level, geo_code))
session.close()
return data


SEX_RECODES = OrderedDict([
Expand All @@ -82,41 +84,41 @@ def get_census_profile(geo_code, geo_level, profile_name=None):
('SIKH', 'Sikh')
])

def get_demographics_profile(geo_code, geo_level, session):
def get_demographics_profile(geo , session):

population_by_area_dist_data, total_population_by_area = get_stat_data(
'area', geo_level, geo_code, session,
'area', geo , session,
recode=dict(AREA_RECODES),
key_order=AREA_RECODES.values(),
table_fields=['area', 'sex'])

population_by_area_dist_data = sort_stats_result(population_by_area_dist_data)

population_by_sex_dist_data, _ = get_stat_data(
'sex', geo_level, geo_code, session,
'sex', geo , session,
recode=dict(SEX_RECODES),
key_order=SEX_RECODES.values(),
table_fields=['area', 'sex'])

population_by_sex_dist_data = sort_stats_result(population_by_sex_dist_data)

literacy_dist_data, _ = get_stat_data(
'literacy', geo_level, geo_code, session,
'literacy', geo , session,
recode=dict(LITERACY_RECODES),
key_order=LITERACY_RECODES.values(),
table_fields=['area', 'literacy', 'sex'])

literacy_dist_data = sort_stats_result(literacy_dist_data)

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

literacy_by_area, t_lit = get_stat_data(
['area', 'literacy'], geo_level, geo_code, session,
['area', 'literacy'], geo , session,
table_fields=['area', 'literacy', 'sex'],
recode={'literacy': dict(LITERACY_RECODES)},
key_order={'literacy': LITERACY_RECODES.values()},
Expand Down Expand Up @@ -144,7 +146,7 @@ def get_demographics_profile(geo_code, geo_level, session):
return final_data


def get_religion_profile(geo_code, geo_level, session):
def get_religion_profile(geo , session):

def religion_category_recode(f, x):
if x in ('Hindu', 'Muslim', 'Christian', 'Sikh'):
Expand Down Expand Up @@ -190,14 +192,14 @@ def sort_religion_stats_result(ip, key=None):
return rv

religion_dist_data, _ = get_stat_data(
'religion', geo_level, geo_code, session,
'religion', geo , session,
recode=religion_category_recode,
table_fields=['area', 'religion', 'sex'])

religion_dist_data = sort_stats_result(religion_dist_data)

religion_by_sex, t_lit = get_stat_data(
['religion', 'sex'], geo_level, geo_code, session,
['religion', 'sex'], geo , session,
table_fields=['area', 'religion', 'sex'],
recode=religion_recode,
key_order={'sex': SEX_RECODES.values()},
Expand All @@ -206,7 +208,7 @@ def sort_religion_stats_result(ip, key=None):
religion_by_sex = sort_religion_stats_result(religion_by_sex, 'Female')

religion_by_area, t_lit = get_stat_data(
['religion', 'area'], geo_level, geo_code, session,
['religion', 'area'], geo , session,
table_fields=['area', 'religion', 'sex'],
recode=religion_recode,
key_order={'area': AREA_RECODES.values()},
Expand All @@ -227,7 +229,7 @@ def sort_religion_stats_result(ip, key=None):

return final_data

def get_age_profile(geo_code, geo_level, session):
def get_age_profile(geo , session):

# age category
def age_cat_recode(f, x):
Expand Down Expand Up @@ -269,22 +271,22 @@ def age_recode(f, x):
try:

age_dist_data, _ = get_stat_data(
'age', geo_level, geo_code, session,
'age', geo , session,
table_fields=['area', 'age', 'sex'],
recode=age_cat_recode)

age_dist_data = sort_stats_result(age_dist_data)


age_by_sex, t_lit = get_stat_data(
['age', 'sex'], geo_level, geo_code, session,
['age', 'sex'], geo , session,
table_fields=['area', 'age', 'sex'],
recode=age_recode,
key_order={'sex': SEX_RECODES.values()},
percent_grouping=['sex'])

age_by_area, t_lit = get_stat_data(
['age', 'area'], geo_level, geo_code, session,
['age', 'area'], geo , session,
table_fields=['area', 'age', 'sex'],
recode=age_recode,
key_order={'area': AREA_RECODES.values()},
Expand All @@ -305,7 +307,7 @@ def age_recode(f, x):

return final_data

def get_education_profile(geo_code, geo_level, session):
def get_education_profile(geo , session):

def get_education_category(key):
if key in ('Below Primary', 'Primary', 'Middle', 'Secondary Matric','Intermediate Puc', 'Graduate Above'):
Expand Down Expand Up @@ -352,15 +354,15 @@ def sort_edu_stats_result(ip, key=None):
return rv

education_dist_data, _ = get_stat_data(
'education', geo_level, geo_code, session,
'education', geo , session,
recode=education_category_recode,
# key_order=education_RECODES.values(),
table_fields=['area', 'education', 'sex'])

education_dist_data = sort_stats_result(education_dist_data)

education_by_sex, t_lit = get_stat_data(
['education', 'sex'], geo_level, geo_code, session,
['education', 'sex'], geo , session,
table_fields=['area', 'education', 'sex'],
recode=education_recode,
# key_order={'education': education_RECODES.values()},
Expand All @@ -370,7 +372,7 @@ def sort_edu_stats_result(ip, key=None):
education_by_sex = sort_edu_stats_result(education_by_sex, 'Female')

education_by_area, t_lit = get_stat_data(
['education', 'area'], geo_level, geo_code, session,
['education', 'area'], geo , session,
table_fields=['area', 'education', 'sex'],
recode=education_recode,
key_order={'area': AREA_RECODES.values()},
Expand All @@ -391,7 +393,7 @@ def sort_edu_stats_result(ip, key=None):

return final_data

def get_maritalstatus_profile(geo_code, geo_level, session):
def get_maritalstatus_profile(geo , session):

def get_maritalstatu(x):
if x in ('never married', 'currently married', 'widowed', 'separated', 'divorced'):
Expand All @@ -410,15 +412,15 @@ def maritalstatus_recode(f, x):
return get_maritalstatu(x)

maritalstatus_dist_data, _ = get_stat_data(
'maritalstatus', geo_level, geo_code, session,
'maritalstatus', geo , session,
recode=maritalstatus_category_recode,
# key_order=education_RECODES.values(),
table_fields=['area', 'maritalstatus', 'sex'])

maritalstatus_dist_data = sort_stats_result(maritalstatus_dist_data)

maritalstatus_by_sex, t_lit = get_stat_data(
['maritalstatus', 'sex'], geo_level, geo_code, session,
['maritalstatus', 'sex'], geo , session,
table_fields=['area', 'maritalstatus', 'sex'],
recode=maritalstatus_recode,
# key_order={'sex': SEX_RECODES.values()},
Expand All @@ -427,7 +429,7 @@ def maritalstatus_recode(f, x):
maritalstatus_by_sex = sort_stats_result(maritalstatus_by_sex, 'Female')

maritalstatus_by_area, t_lit = get_stat_data(
['maritalstatus', 'area'], geo_level, geo_code, session,
['maritalstatus', 'area'], geo , session,
table_fields=['area', 'maritalstatus', 'sex'],
recode=maritalstatus_recode,
key_order={'area': AREA_RECODES.values()},
Expand All @@ -449,7 +451,7 @@ def maritalstatus_recode(f, x):
return final_data


def get_workers_profile(geo_code, geo_level, session):
def get_workers_profile(geo , session):

# sum of different category of workers exceeds total population because of
# the way they are classified. Some of the classes get accounted twice causing
Expand Down Expand Up @@ -477,14 +479,14 @@ def worker_recode(f, x):
return get_worker_status(x)

workers_dist_data, _ = get_stat_data(
'workers', geo_level, geo_code, session,
'workers', geo , session,
recode=worker_category_recode,
table_fields=['area', 'workers', 'workerssex'])

workers_dist_data = sort_stats_result(workers_dist_data)

workers_by_sex, t_lit = get_stat_data(
['workers', 'workerssex'], geo_level, geo_code, session,
['workers', 'workerssex'], geo , session,
table_fields=['area', 'workers', 'workerssex'],
recode=worker_recode,
key_order={'workerssex': SEX_RECODES.values()},
Expand All @@ -493,7 +495,7 @@ def worker_recode(f, x):
workers_by_sex = sort_stats_result(workers_by_sex, 'Female')

workers_by_area, t_lit = get_stat_data(
['workers', 'area'], geo_level, geo_code, session,
['workers', 'area'], geo , session,
table_fields=['area', 'workers', 'workerssex'],
recode=worker_recode,
key_order={'area': AREA_RECODES.values()},
Expand Down
42 changes: 26 additions & 16 deletions janaganana/settings.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
# pull in the default wazimap settings
from wazimap.settings import * # noqa
import os
from decouple import config

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

DEBUG = config('DJANGO_DEBUG', default=True, cast=bool)
TEMPLATE_DEBUG = DEBUG

SECRET_KEY = config('SECRET_KEY')

# DJANGO_SETTINGS_MODULE = config('DJANGO_SETTINGS_MODULE')

# install this app before Wazimap
INSTALLED_APPS = ['janaganana', 'django.contrib.sitemaps'] + INSTALLED_APPS
# INSTALLED_APPS = ['janaganana', 'pipeline'] + INSTALLED_APPS
INSTALLED_APPS = ['janaganana', 'django.contrib.sitemaps','django.contrib.auth'] + INSTALLED_APPS

ROOT_URLCONF = 'janaganana.urls'

DATABASE_URL = config(
'DATABASE_URL', default='postgresql://factlyin:factlyin@ci-db/factlyin')
DATABASE_URL = config('DATABASE_URL', default='postgresql://factlyin:factlyin@/factlyin')
DATABASES['default'] = dj_database_url.parse(DATABASE_URL)
DATABASES['default']['ATOMIC_REQUESTS'] = True

Expand Down Expand Up @@ -42,12 +46,14 @@
}
}

WAZIMAP['default_geo_version'] = '2011'
WAZIMAP['comparative_levels'] = ['country', 'state', 'district']
WAZIMAP['geometry_data'] = {
'country': 'geo/country.topojson',
'state': 'geo/state.topojson',
'district': 'geo/district.topojson',
}

WAZIMAP['geometry_data'] = {'2011': {
'country': 'geo/country.topojson',
'state': 'geo/state.topojson',
'district': 'geo/district.topojson',
}}

WAZIMAP['ga_tracking_id'] = 'UA-91398887-1'
WAZIMAP['twitter'] = '@factlydotin'
Expand All @@ -63,20 +69,24 @@
WAZIMAP['github'] = 'https://github.com/factly/janaganana'
WAZIMAP['tagline'] = 'Make sense of Indian census data'

SECRET_KEY = config('DJANGO_SECRET_KEY')
WSGI_APPLICATION = 'janaganana.wsgi.application'

#SECRET_KEY = config('DJANGO_SECRET_KEY')

# STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static-root')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]

STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'pipeline.finders.PipelineFinder',
)

# STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

STATICFILES_DIRS = (
os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static'),
)

MIDDLEWARE_CLASSES = [
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
Expand Down
Loading