Skip to content

Commit

Permalink
refactor string location for Ash Report
Browse files Browse the repository at this point in the history
  • Loading branch information
lucernae committed Nov 30, 2017
1 parent 51230c7 commit d144839
Show file tree
Hide file tree
Showing 13 changed files with 1,226 additions and 1,090 deletions.
136 changes: 24 additions & 112 deletions realtime/ash/ash_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
QgsRectangle)
from jinja2 import Template
from headless.tasks.utilities import download_file
from realtime.ash.report_text import ReportText
from realtime.exceptions import MapComposerError
from realtime.utilities import realtime_logger_name
from safe.common.exceptions import (
Expand Down Expand Up @@ -88,6 +89,9 @@ def __init__(
:param airport_path:
"""
QObject.__init__(self)

self.report_text = ReportText()

if event_time:
self.time = event_time
else:
Expand Down Expand Up @@ -258,48 +262,19 @@ def event_dict(self):
tzinfo=pytz.utc) - self.time
elapsed_hour = elapsed_time.seconds / 3600
elapsed_minute = (elapsed_time.seconds / 60) % 60
event = {
'report-title': self.tr('Volcanic Ash Impact'),
'report-timestamp': self.tr('Volcano: %s, %s') % (
self.volcano_name,
timestamp_string),
'report-province': self.tr('Province: %s') % (self.region,),
'report-alert-level': self.tr('Alert Level: %s') % (
self.alert_level.capitalize(), ),
'report-location': self.tr(
'Position: %s, %s;'
' Eruption Column Height (a.s.l) - %d m') % (
longitude_string, latitude_string, self.erupction_height),
'report-elapsed': self.tr(
'Elapsed time since event: %s hour(s) and %s minute(s)') % (
elapsed_hour, elapsed_minute),
'header-impact-table': self.tr(
'Potential impact at each fallout level'),
'header-nearby-table': self.tr('Nearby places'),
'header-landcover-table': self.tr('Land Cover Impact'),
'content-disclaimer': self.tr(
'The impact estimation is automatically generated and only '
'takes into account the population, cities and land cover '
'affected by different levels of volcanic ash fallout at '
'surface level. The estimate is based on volcanic ash '
'fallout data from Badan Geologi, population count data '
'derived by DMInnovation from worldpop.org.uk, place '
'information and land cover classification data provided by '
'Indonesian Geospatial Portal at http://portal.ina-sdi.or.id '
'and software developed by BNPB. Limitation in the estimates '
'of surface fallout, population and place names datasets may '
'result in a significant misrepresentation of the '
'on-the-surface situation in the figures shown here. '
'Consequently, decisions should not be made solely on the '
'information presented here and should always be verified '
'by ground truthing and other reliable information sources.'
),
'content-notes': self.tr(
'This report was created using InaSAFE version %s. Visit '
'http://inasafe.org for more information. ') % get_version(),
'content-support': self.tr(
'Supported by DMInnovation, Geoscience Australia and the World Bank-GFDRR')
}

event = self.report_text.qpt_token(
volcano_name=self.volcano_name,
timestamp_string=timestamp_string,
region=self.region,
alert_level=self.alert_level,
longitude_string=longitude_string,
latitude_string=latitude_string,
eruption_height=self.erupction_height,
elapsed_hour=elapsed_hour,
elapsed_minute=elapsed_minute,
version=get_version()
)
return event

@classmethod
Expand Down Expand Up @@ -347,47 +322,8 @@ def render_population_table(self):
population_template = self.ash_fixtures_dir(
'population-table.template.html')

table_header = [
{
'header': self.tr('Fallout Level')
},
{
'header': self.tr('Very Low'),
'class': 'lv1'
},
{
'header': self.tr('Low'),
'class': 'lv2'
},
{
'header': self.tr('Moderate'),
'class': 'lv3'
},
{
'header': self.tr('High'),
'class': 'lv4'
},
{
'header': self.tr('Very High'),
'class': 'lv5'
},
]

potential_impact_header = [
self.tr('Potential Impact'),
self.tr('Impact on health (respiration), livestock, and contamination of water supply.'),
self.tr('Damage to transportation routes (e.g. airports, roads, railways); damage to critical infrastructure (e.g. electricity supply); damage to more vulnerable agricultural crops (e.g. rice fields)'),
self.tr('Damage to less vulnerable agricultural crops (e.g. tea plantations) and destruction of more vulnerable crops; destruction of critical infrastructure; cosmetic (non-structural) damage to buildings'),
self.tr('Dry loading on buildings causing structural damage but not collapse; Wet loading on buildings (i.e. ash loading + heavy rainfall) causing structural collapse.'),
self.tr('Dry loading on buildings causing structural collapse.')
]

context = {
'table_header': table_header,
'affected_header': self.tr('Estimated People Affected'),
'potential_impact_header': potential_impact_header,
'ash_thickness_header': self.tr('Ash Thickness Range (cm)')
}
context = self.report_text.population_table_token()

context.update(population_dict)
with open(population_template) as f:
template = Template(f.read())
Expand Down Expand Up @@ -423,17 +359,7 @@ def render_landcover_table(self):
# 'type': 'Rice Field',
# 'area': 10
# },
# ]

# Landcover type localization for dynamic translations:
# noqa
landcover_types = [
self.tr('Forest'),
self.tr('Plantation'),
self.tr('Water Supply'),
self.tr('Settlement'),
self.tr('Rice Field')
]
#

landcover_list = []
for land_type, area in landcover_dict.iteritems():
Expand All @@ -447,11 +373,8 @@ def render_landcover_table(self):
landcover_template = self.ash_fixtures_dir(
'landcover-table.template.html')

context = {
'landcover_list': landcover_list,
'landcover_type_header': self.tr('Land Cover Type'),
'landcover_area_header': self.tr('Area affected (km<sup>2</sup>)')
}
context = self.report_text.landcover_table_token(
landcover_list=landcover_list)
with open(landcover_template) as f:
template = Template(f.read())
# generate table here
Expand All @@ -469,13 +392,7 @@ def render_nearby_table(self):
3: 'High',
4: 'Very High'
}
hazard_label = {
0: self.tr('Very Low'),
1: self.tr('Low'),
2: self.tr('Moderate'),
3: self.tr('High'),
4: self.tr('Very High')
}
hazard_label = self.report_text.hazard_label_token()

# load PLACES
keyword_io = KeywordIO()
Expand Down Expand Up @@ -598,12 +515,7 @@ def render_nearby_table(self):

nearby_template = self.ash_fixtures_dir(
'nearby-table.template.html')
context = {
'item_list': item_list,
'name_header': self.tr('Name'),
'affected_header': self.tr('People / Airport affected'),
'fallout_header': self.tr('Fallout Level')
}
context = self.report_text.nearby_table_token(item_list=item_list)
with open(nearby_template) as f:
template = Template(f.read())
# generate table here
Expand Down
2 changes: 1 addition & 1 deletion realtime/ash/fixtures/landcover-table.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{% else %}
<tr>
<td colspan="2" class="center">
No area affected
{{ empty_rows|safe }}
</td>
</tr>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion realtime/ash/fixtures/nearby-table.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
{% else %}
<tr>
<td colspan="3" class="center">
No nearby cities or airport affected
{{ empty_rows|safe }}
</td>
</tr>
{% endfor %}
Expand Down
149 changes: 149 additions & 0 deletions realtime/ash/report_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
# coding=utf-8

from PyQt4.QtCore import QObject

__author__ = 'Rizky Maulana Nugraha <lana.pcfre@gmail.com>'
__date__ = '2/11/2017'


class ReportText(QObject):
"""Placeholder class for texts in the report."""

def __init__(self):
QObject.__init__(self)

def qpt_token(
self,
volcano_name=None, timestamp_string=None, region=None,
alert_level=None, longitude_string=None, latitude_string=None,
eruption_height=None, elapsed_hour=None, elapsed_minute=None,
version=None):
"""Token string for QPT template"""
event = {
'report-title': self.tr('Volcanic Ash Impact'),
'report-timestamp': self.tr('Volcano: %s, %s') % (
volcano_name,
timestamp_string),
'report-province': self.tr('Province: %s') % (region,),
'report-alert-level': self.tr('Alert Level: %s') % (
alert_level.capitalize(),),
'report-location': self.tr(
'Position: %s, %s;'
' Eruption Column Height (a.s.l) - %d m') % (
longitude_string,
latitude_string,
eruption_height),
'report-elapsed': self.tr(
'Elapsed time since event: %s hour(s) and %s minute(s)') % (
elapsed_hour, elapsed_minute),
'header-impact-table': self.tr(
'Potential impact at each fallout level'),
'header-nearby-table': self.tr('Nearby places'),
'header-landcover-table': self.tr('Land Cover Impact'),
'content-disclaimer': self.tr(
'The impact estimation is automatically generated and only '
'takes into account the population, cities and land cover '
'affected by different levels of volcanic ash fallout at '
'surface level. The estimate is based on volcanic ash '
'fallout data from Badan Geologi, population count data '
'derived by DMInnovation from worldpop.org.uk, place '
'information and land cover classification data provided by '
'Indonesian Geospatial Portal at http://portal.ina-sdi.or.id '
'and software developed by BNPB. Limitation in the estimates '
'of surface fallout, population and place names datasets may '
'result in a significant misrepresentation of the '
'on-the-surface situation in the figures shown here. '
'Consequently, decisions should not be made solely on the '
'information presented here and should always be verified '
'by ground truthing and other reliable information sources.'
),
'content-notes': self.tr(
'This report was created using InaSAFE version %s. Visit '
'http://inasafe.org for more information. ') % version,
'content-support': self.tr(
'Supported by DMInnovation, Geoscience Australia and the World Bank-GFDRR')
}
return event

def population_table_token(self):
table_header = [
{
'header': self.tr('Fallout Level')
},
{
'header': self.tr('Very Low'),
'class': 'lv1'
},
{
'header': self.tr('Low'),
'class': 'lv2'
},
{
'header': self.tr('Moderate'),
'class': 'lv3'
},
{
'header': self.tr('High'),
'class': 'lv4'
},
{
'header': self.tr('Very High'),
'class': 'lv5'
},
]

potential_impact_header = [
self.tr('Potential Impact'),
self.tr('Impact on health (respiration), livestock, and contamination of water supply.'),
self.tr('Damage to transportation routes (e.g. airports, roads, railways); damage to critical infrastructure (e.g. electricity supply); damage to more vulnerable agricultural crops (e.g. rice fields)'),
self.tr('Damage to less vulnerable agricultural crops (e.g. tea plantations) and destruction of more vulnerable crops; destruction of critical infrastructure; cosmetic (non-structural) damage to buildings'),
self.tr('Dry loading on buildings causing structural damage but not collapse; Wet loading on buildings (i.e. ash loading + heavy rainfall) causing structural collapse.'),
self.tr('Dry loading on buildings causing structural collapse.')
]

context = {
'table_header': table_header,
'affected_header': self.tr('Estimated People Affected'),
'potential_impact_header': potential_impact_header,
'ash_thickness_header': self.tr('Ash Thickness Range (cm)')
}
return context

def landcover_table_token(self, landcover_list=None):
# Landcover type localization for dynamic translations:
# noqa
landcover_types = [
self.tr('Forest'),
self.tr('Plantation'),
self.tr('Water Supply'),
self.tr('Settlement'),
self.tr('Rice Field')
]

context = {
'landcover_list': landcover_list,
'landcover_type_header': self.tr('Land Cover Type'),
'landcover_area_header': self.tr('Area affected (km<sup>2</sup>)'),
'empty_rows': self.tr('No area affected')
}

return context

def hazard_label_token(self):
return {
0: self.tr('Very Low'),
1: self.tr('Low'),
2: self.tr('Moderate'),
3: self.tr('High'),
4: self.tr('Very High')
}

def nearby_table_token(self, item_list=None):
return {
'item_list': item_list,
'name_header': self.tr('Name'),
'affected_header': self.tr('People / Airport affected'),
'fallout_header': self.tr('Fallout Level'),
'empty_rows': self.tr('No nearby cities or airport affected')
}

Loading

0 comments on commit d144839

Please sign in to comment.