Skip to content

Commit

Permalink
Add and refine:
Browse files Browse the repository at this point in the history
- Road Impact Summary
- Structure Impact Summary
- Population Impact Summary
- Polygon People Impact Summary

Hide first:
- Landcover Impact Summary
  • Loading branch information
lucernae committed Jun 13, 2016
1 parent 467259c commit 1ebf6f3
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 49 deletions.
48 changes: 48 additions & 0 deletions 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 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 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
2 changes: 1 addition & 1 deletion helpers/impact_summary/structure_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def breakdown_dict(self):
if contain_total or (contain_affected and not contain_not):
continue

ret_val[key] = value
ret_val[key] = int(value)
return ret_val

def category_css_class(self, category):
Expand Down
5 changes: 0 additions & 5 deletions helpers/impact_summary/structures/__init__.py

This file was deleted.

3 changes: 3 additions & 0 deletions helpers/impact_summary/summary_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ def category_list(self):
if self.is_summary_exists():
return [f.get('category') for f in self.summary_fields()]

def exposure_type(self):
return self.impact_data.get('exposure')

@classmethod
def category_css_class(cls, category):
"""Get css-class from a given category
Expand Down
25 changes: 22 additions & 3 deletions static/geosafe/css/impact_summary.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,51 @@
border-bottom: none;
border-left: none;
border-right: none;
display: flex;
}
.summary{
padding-right: 0px;
display: flex;
flex-direction: column;
border-right: 1px solid #606060;
}
.summary .highlight{
margin-left: -15px;
padding: 15px;
border-bottom: 1px solid #606060;
border-right: 1px solid #606060;
}

.summary .highlight:last-child{
border-bottom: none;
}

.summary .highlight div{
padding-left: 0;
padding-right: 0;
}

.summary .highlight .svg{
width: 100%;
height: 100%;
}

.summary .highlight .number{
font-size: 30pt;
}

.category-breakdown{
padding: 15px;
display: flex;
flex-direction: column;
}
.category-breakdown .title{
padding-bottom: 15px;
}

.breakdown{
display: flex;
flex-direction: row;
border-top: 1px solid #606060;
padding-top: 5px;
padding-bottom: 5px;
}
.breakdown .value svg{
fill: #606060;
Expand Down
2 changes: 1 addition & 1 deletion tasks/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def process_impact_result(analysis_id, impact_url_result):
if os.path.exists(report_table_path):
analysis.assign_report_table(report_table_path)

analysis.task_state = analysis.get_task_result().state
analysis.task_state = 'SUCCESS'
analysis.save()

if current_impact:
Expand Down
4 changes: 2 additions & 2 deletions templates/geosafe/analysis/create.html
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@
update_hazard_layer({{ analysis.hazard_layer_id }});
update_exposure_layer({{ analysis.exposure_layer_id }});
{# check if impact process is done #}
{% if analysis.get_task_result.successful %}
{% if analysis.get_task_state == 'SUCCESS' %}
update_impact_layer({{ analysis.impact_layer_id }});
{% else %}
{# impact not yet processed #}
Expand All @@ -914,7 +914,7 @@
{% endif %}

{% if analysis.get_task_result %}
{% if not analysis.get_task_result.successful and not analysis.get_task_result.failed %}
{% if not analysis.get_task_state == 'SUCCESS' and not analysis.get_task_state == 'FAILURE' %}
{# Automatic check in 30 sec #}
function check_analysis(){
var check_analysis_url = '{% url 'geosafe:check-analysis' analysis_id=analysis.id %}';
Expand Down
2 changes: 1 addition & 1 deletion templates/geosafe/analysis/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h1>List of Analysis</h1>
<td>
{% if not analysis.get_task_result %}
Analysis not yet running
{% elif analysis.get_task_result.successful or analysis.get_task_state == 'SUCCESS' %}
{% elif analysis.get_task_state == 'SUCCESS' %}
<a href="{% url 'layer_detail' layername=analysis.impact_layer.typename %}">{{ analysis.impact_layer }}</a>
{% else %}
<div>Task Status: <span class="label label-{{ analysis.get_label_class }}">{{ analysis.get_task_state }}</span></div>
Expand Down
8 changes: 0 additions & 8 deletions templates/geosafe/analysis/modal/impact_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,6 @@
<h4 class="modal-title" id="impact_card_label">Analysis Result</h4>
</div>
<div class="modal-body">
<p class="impact-icons">
{% with analysis.exposure_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
{% with analysis.hazard_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
</p>
<p class="impact-questions">
In the event of {{ analysis.hazard_layer.title }}, how many {{ analysis.exposure_layer.title }} will be affected
</p>
Expand Down
48 changes: 48 additions & 0 deletions templates/geosafe/analysis/summary/polygon_people_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% load geosafe_impact_summary %}
{% load staticfiles %}
<div class="impact-summary row">
<div class="summary col-xs-6">
<div class="row highlight">
<div class="col-xs-8">
<div class="number">{{ summary.total }}</div>
<div class="category">Total Population</div>
</div>
<div class="col-xs-4">
{% with analysis.exposure_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
</div>
</div>
<div class="row highlight">
<div class="col-xs-8">
<div class="number">{{ summary.total_affected }}</div>
<div class="category">Population Affected</div>
</div>
<div class="col-xs-4">
{% with analysis.hazard_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
</div>
</div>
</div>
<div class="category-breakdown col-xs-6">
<div class="title text-center">Hazard areas</div>
<div class="content">
{% for category, value in summary.breakdown_dict.iteritems %}
<div class="breakdown row {{ summary|category_css_class:category }}">
<div class="category col-xs-4 text-right">{{ category|lower|safe }}</div>
<div class="value col-xs-4 text-right">
<div style="width: 100%">{{ value }}</div>
</div>
<div class="value col-xs-4 text-left">
{% with 84.5 as total_width %}
<svg width="{{ total_width }}" height="20">
<rect x="0" rx="10" ry="10" height="20" width="{% widthratio value summary.total total_width %}"></rect>
</svg>
{% endwith %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
48 changes: 48 additions & 0 deletions templates/geosafe/analysis/summary/population_report.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% load geosafe_impact_summary %}
{% load staticfiles %}
<div class="impact-summary row">
<div class="summary col-xs-6">
<div class="row highlight">
<div class="col-xs-8">
<div class="number">{{ summary.total }}</div>
<div class="category">Total Population</div>
</div>
<div class="col-xs-4">
{% with analysis.exposure_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
</div>
</div>
<div class="row highlight">
<div class="col-xs-8">
<div class="number">{{ summary.total_affected }}</div>
<div class="category">Population Affected</div>
</div>
<div class="col-xs-4">
{% with analysis.hazard_layer.metadata.category as c %}
<img src="{% static "geosafe/img/"|add:c|add:".svg" %}" alt="{{ c }}" class="svg"/>
{% endwith %}
</div>
</div>
</div>
<div class="category-breakdown col-xs-6">
<div class="title text-center">Hazard areas</div>
<div class="content">
{% for category, value in summary.breakdown_dict.iteritems %}
<div class="breakdown row {{ summary|category_css_class:category }}">
<div class="category col-xs-4 text-right">{{ category|lower|safe }}</div>
<div class="value col-xs-4 text-right">
<div style="width: 100%">{{ value }}</div>
</div>
<div class="value col-xs-4 text-left">
{% with 84.5 as total_width %}
<svg width="{{ total_width }}" height="20">
<rect x="0" rx="10" ry="10" height="20" width="{% widthratio value summary.total total_width %}"></rect>
</svg>
{% endwith %}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
Loading

0 comments on commit 1ebf6f3

Please sign in to comment.