diff --git a/helpers/impact_summary/landcover_summary.py b/helpers/impact_summary/landcover_summary.py new file mode 100644 index 0000000..7635909 --- /dev/null +++ b/helpers/impact_summary/landcover_summary.py @@ -0,0 +1,48 @@ +# coding=utf-8 +from collections import OrderedDict + +from geosafe.helpers.impact_summary.summary_base import ImpactSummary + +__author__ = 'Rizky Maulana Nugraha ' +__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 diff --git a/helpers/impact_summary/polygon_people_summary.py b/helpers/impact_summary/polygon_people_summary.py new file mode 100644 index 0000000..6bdb216 --- /dev/null +++ b/helpers/impact_summary/polygon_people_summary.py @@ -0,0 +1,54 @@ +# coding=utf-8 +from collections import OrderedDict + +from geosafe.helpers.impact_summary.summary_base import ImpactSummary + +__author__ = 'Rizky Maulana Nugraha ' +__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 diff --git a/helpers/impact_summary/population_summary.py b/helpers/impact_summary/population_summary.py new file mode 100644 index 0000000..1b7f02a --- /dev/null +++ b/helpers/impact_summary/population_summary.py @@ -0,0 +1,54 @@ +# coding=utf-8 +from collections import OrderedDict + +from geosafe.helpers.impact_summary.summary_base import ImpactSummary + +__author__ = 'Rizky Maulana Nugraha ' +__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 diff --git a/helpers/impact_summary/structure_summary.py b/helpers/impact_summary/structure_summary.py index 3b5a917..7635909 100644 --- a/helpers/impact_summary/structure_summary.py +++ b/helpers/impact_summary/structure_summary.py @@ -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): diff --git a/helpers/impact_summary/structures/__init__.py b/helpers/impact_summary/structures/__init__.py deleted file mode 100644 index 7c316a2..0000000 --- a/helpers/impact_summary/structures/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -# coding=utf-8 - -__author__ = 'Rizky Maulana Nugraha ' - -__date__ = '6/13/16' diff --git a/helpers/impact_summary/summary_base.py b/helpers/impact_summary/summary_base.py index 44a8786..bff1bb6 100644 --- a/helpers/impact_summary/summary_base.py +++ b/helpers/impact_summary/summary_base.py @@ -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 diff --git a/static/geosafe/css/impact_summary.css b/static/geosafe/css/impact_summary.css index 2e257a6..c948a6a 100644 --- a/static/geosafe/css/impact_summary.css +++ b/static/geosafe/css/impact_summary.css @@ -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; diff --git a/tasks/analysis.py b/tasks/analysis.py index 467da4a..ac092a4 100644 --- a/tasks/analysis.py +++ b/tasks/analysis.py @@ -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: diff --git a/templates/geosafe/analysis/create.html b/templates/geosafe/analysis/create.html index 4e21195..f2dd707 100644 --- a/templates/geosafe/analysis/create.html +++ b/templates/geosafe/analysis/create.html @@ -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 #} @@ -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 %}'; diff --git a/templates/geosafe/analysis/list.html b/templates/geosafe/analysis/list.html index 7d9a710..0b17d5a 100644 --- a/templates/geosafe/analysis/list.html +++ b/templates/geosafe/analysis/list.html @@ -119,7 +119,7 @@

List of Analysis

{% 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' %} {{ analysis.impact_layer }} {% else %}
Task Status: {{ analysis.get_task_state }}
diff --git a/templates/geosafe/analysis/modal/impact_card.html b/templates/geosafe/analysis/modal/impact_card.html index 65f5128..d288623 100644 --- a/templates/geosafe/analysis/modal/impact_card.html +++ b/templates/geosafe/analysis/modal/impact_card.html @@ -13,14 +13,6 @@