Skip to content

Commit

Permalink
Merge pull request GeoNode#102 from kartoza/geosafe
Browse files Browse the repository at this point in the history
Geosafe - Impact Summary
  • Loading branch information
lucernae authored Jun 14, 2016
2 parents f8b4cbb + 8adb733 commit a00ea0b
Show file tree
Hide file tree
Showing 30 changed files with 1,304 additions and 106 deletions.
14 changes: 14 additions & 0 deletions geonode/layers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,20 @@ def get_files(filename):
'distinct by spelling and not just case.') % filename
raise GeoNodeException(msg)

if 'geosafe' in settings.INSTALLED_APPS:
matches = glob.glob(glob_name + ".[jJ][sS][oO][nN]")
logger.debug('Checking JSON file')
logger.debug('Number of matches JSON file : %s' % len(matches))
logger.debug('glob name: %s' % glob_name)
if len(matches) == 1:
files['json'] =matches[0]
elif len(matches) > 1:
msg = ('Multiple impact summary report (json) for %s exist; '
'they need to be distinct by spelling and not just case.'
) % filename
raise GeoNodeException(msg)


return files


Expand Down
15 changes: 15 additions & 0 deletions geonode/static/geosafe/img/land_cover.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions geonode/static/geosafe/img/volcanic-ash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions geosafe/helpers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# coding=utf-8

__author__ = 'Rizky Maulana Nugraha <[email protected]>'

__date__ = '5/17/16'
5 changes: 5 additions & 0 deletions geosafe/helpers/impact_summary/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# coding=utf-8

__author__ = 'Rizky Maulana Nugraha <[email protected]>'

__date__ = '5/17/16'
48 changes: 48 additions & 0 deletions geosafe/helpers/impact_summary/landcover_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding=utf-8
from collections import OrderedDict

from geosafe.helpers.impact_summary.summary_base import ImpactSummary

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '5/18/16'


class StructureSummary(ImpactSummary):

def total(self):
return self.total_buildings()

def total_buildings(self):
return self.summary_dict().get('Total')

def total_affected(self):
if 'Affected buildings' in self.summary_dict().keys():
return self.summary_dict().get('Affected buildings')
elif 'Not affected buildings' in self.summary_dict().keys():
not_affected = self.summary_dict().get('Not affected buildings')
return int(self.total_buildings()) - int(not_affected)

def breakdown_dict(self):
ret_val = OrderedDict()
for key, value in self.summary_dict().iteritems():
contain_total = 'total' in key.lower()
contain_affected = 'affected' in key.lower()
contain_not = 'not' in key.lower()
if contain_total or (contain_affected and not contain_not):
continue

ret_val[key] = int(value)
return ret_val

def category_css_class(self, category):
css_class = ImpactSummary.category_css_class(category)
if not css_class:
if 'flood' in category.lower():
css_class = 'hazard-category-high'
elif 'dry' in category.lower():
css_class = 'hazard-category-low'
elif 'wet' in category.lower():
css_class = 'hazard-category-medium'
elif 'radius' in category.lower():
css_class = 'hazard-category-high'
return css_class
54 changes: 54 additions & 0 deletions geosafe/helpers/impact_summary/polygon_people_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding=utf-8
from collections import OrderedDict

from geosafe.helpers.impact_summary.summary_base import ImpactSummary

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '5/18/16'


class PolygonPeopleSummary(ImpactSummary):

def total(self):
return self.total_people()

def total_people(self):
return int(self.summary_dict().get('Total people'))

def total_affected(self):
if 'Total affected people' in self.summary_dict().keys():
return int(self.summary_dict().get('Total affected people'))
return 0

def breakdown_dict(self):
ret_val = OrderedDict()
for key, value in self.summary_dict().iteritems():
contain_total = 'total' in key.lower()
contain_affected = 'affected' in key.lower()
contain_not = 'not' in key.lower()
contain_unaffected = 'unaffected' in key.lower()
if (contain_total or
(contain_affected and
not contain_not and
not contain_unaffected)):
continue

ret_val[key] = int(value)
return ret_val

def category_css_class(self, category):
css_class = ImpactSummary.category_css_class(category)
if not css_class:
if 'people' in category.lower():
css_class = 'hazard-category-high'
elif 'fatalities' in category.lower():
css_class = 'hazard-category-high'
elif 'displaced' in category.lower():
css_class = 'hazard-category-high'
elif 'affected' in category.lower():
css_class = 'hazard-category-high'
elif 'floodprone' in category.lower():
css_class = 'hazard-category-high'
elif 'radius' in category.lower():
css_class = 'hazard-category-high'
return css_class
54 changes: 54 additions & 0 deletions geosafe/helpers/impact_summary/population_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# coding=utf-8
from collections import OrderedDict

from geosafe.helpers.impact_summary.summary_base import ImpactSummary

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '5/18/16'


class PopulationSummary(ImpactSummary):

def total(self):
return self.total_populations()

def total_populations(self):
return self.summary_dict().get('Total population')

def total_affected(self):
if 'Total affected population' in self.summary_dict().keys():
return int(self.summary_dict().get('Total affected population'))
return 0

def breakdown_dict(self):
ret_val = OrderedDict()
for key, value in self.summary_dict().iteritems():
contain_total = 'total' in key.lower()
contain_affected = 'affected' in key.lower()
contain_not = 'not' in key.lower()
contain_unaffected = 'unaffected' in key.lower()
if (contain_total or
(contain_affected and
not contain_not and
not contain_unaffected)):
continue

ret_val[key] = int(value)
return ret_val

def category_css_class(self, category):
css_class = ImpactSummary.category_css_class(category)
if not css_class:
if 'people' in category.lower():
css_class = 'hazard-category-high'
elif 'fatalities' in category.lower():
css_class = 'hazard-category-high'
elif 'displaced' in category.lower():
css_class = 'hazard-category-high'
elif 'affected' in category.lower():
css_class = 'hazard-category-high'
elif 'floodprone' in category.lower():
css_class = 'hazard-category-high'
elif 'radius' in category.lower():
css_class = 'hazard-category-high'
return css_class
55 changes: 55 additions & 0 deletions geosafe/helpers/impact_summary/road_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# coding=utf-8
from collections import OrderedDict

from geosafe.helpers.impact_summary.summary_base import ImpactSummary

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '6/13/16'


class RoadSummary(ImpactSummary):

def total(self):
return self.total_roads()

def total_roads(self):
for idx, val in enumerate(self.summary_attributes()):
if 'total' in val.lower():
if self.is_summary_exists():
return int(self.impact_data.get('impact summary').get(
'fields')[0][idx])
return 0

def total_affected(self):
lowercase_keys = [k.lower() for k in self.summary_attributes()]
for idx, val in enumerate(lowercase_keys):
if 'flooded' in val or 'closed' in val:
return int(self.impact_data.get('impact summary').get(
'fields')[0][idx])
return 0

def breakdown_dict(self):
ret_val = OrderedDict()
for idx, key in enumerate(self.summary_attributes()):
contain_total = 'total' in key.lower()
contain_affected = 'affected' in key.lower()
contain_not = 'not' in key.lower()
contain_unaffected = 'unaffected' in key.lower()
if (contain_total or
(contain_affected and
not contain_not and
not contain_unaffected)):
continue

ret_val[key] = int(self.impact_data.get('impact summary').get(
'fields')[0][idx])
return ret_val

def category_css_class(self, category):
css_class = ImpactSummary.category_css_class(category)
if not css_class:
if 'closed' in category.lower():
css_class = 'hazard-category-high'
elif 'flooded' in category.lower():
css_class = 'hazard-category-high'
return css_class
48 changes: 48 additions & 0 deletions geosafe/helpers/impact_summary/structure_summary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# coding=utf-8
from collections import OrderedDict

from geosafe.helpers.impact_summary.summary_base import ImpactSummary

__author__ = 'Rizky Maulana Nugraha <[email protected]>'
__date__ = '5/18/16'


class StructureSummary(ImpactSummary):

def total(self):
return self.total_buildings()

def total_buildings(self):
return self.summary_dict().get('Total')

def total_affected(self):
if 'Affected buildings' in self.summary_dict().keys():
return self.summary_dict().get('Affected buildings')
elif 'Not affected buildings' in self.summary_dict().keys():
not_affected = self.summary_dict().get('Not affected buildings')
return int(self.total_buildings()) - int(not_affected)

def breakdown_dict(self):
ret_val = OrderedDict()
for key, value in self.summary_dict().iteritems():
contain_total = 'total' in key.lower()
contain_affected = 'affected' in key.lower()
contain_not = 'not' in key.lower()
if contain_total or (contain_affected and not contain_not):
continue

ret_val[key] = int(value)
return ret_val

def category_css_class(self, category):
css_class = ImpactSummary.category_css_class(category)
if not css_class:
if 'flood' in category.lower():
css_class = 'hazard-category-high'
elif 'dry' in category.lower():
css_class = 'hazard-category-low'
elif 'wet' in category.lower():
css_class = 'hazard-category-medium'
elif 'radius' in category.lower():
css_class = 'hazard-category-high'
return css_class
Loading

0 comments on commit a00ea0b

Please sign in to comment.