Skip to content

Commit

Permalink
Better place for the code per #263.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Oct 4, 2012
1 parent b4b3cdb commit 32a10c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
23 changes: 23 additions & 0 deletions safe/engine/core.py
Expand Up @@ -9,6 +9,9 @@
from safe.storage.projection import DEFAULT_PROJECTION
from safe.common.utilities import unique_filename, verify
from utilities import REQUIRED_KEYWORDS
from datetime import datetime
from socket import gethostname
import getpass

# The LOGGER is intialised in utilities.py by init
import logging
Expand Down Expand Up @@ -44,9 +47,29 @@ def calculate_impact(layers, impact_fcn):
# Get an instance of the passed impact_fcn
impact_function = impact_fcn()

# start time
start_time = datetime.now()
# Pass input layers to plugin
F = impact_function.run(layers)

# end time
end_time = datetime.now()
# elapsed time
elapsed_time = end_time - start_time
elapsed_time_sec = elapsed_time.total_seconds()
# get current time stamp
# need to change : to _ because : is forbidden in keywords
time_stamp = end_time.isoformat('_')
# get user
user = getpass.getuser().replace(' ', '_')
# get host
host_name = gethostname()

F.keywords['elapsed_time'] = elapsed_time_sec
F.keywords['time_stamp'] = time_stamp
F.keywords['host_name'] = host_name
F.keywords['user'] = user

msg = 'Impact function %s returned None' % str(impact_function)
verify(F is not None, msg)

Expand Down
25 changes: 2 additions & 23 deletions safe/impact_functions/inundation/flood_OSM_building_impact.py
Expand Up @@ -6,9 +6,6 @@
from safe.common.tables import Table, TableRow
from safe.common.dynamic_translations import names as internationalised_values
from safe.engine.interpolation import assign_hazard_values_to_exposure_data
from datetime import datetime
from socket import gethostname
import getpass


class FloodBuildingImpactFunction(FunctionProvider):
Expand Down Expand Up @@ -48,8 +45,6 @@ def run(self, layers):
"""Flood impact to buildings (e.g. from Open Street Map)
"""

# start time
start_time = datetime.now()
threshold = 1.0 # Flood threshold [m]

# Extract data
Expand Down Expand Up @@ -250,30 +245,14 @@ def run(self, layers):
style_info = dict(target_field=self.target_field,
style_classes=style_classes)

# end time
end_time = datetime.now()
# elapsed time
elapsed_time = end_time - start_time
elapsed_time_sec = elapsed_time.total_seconds()
# get current time stamp
# need to change : to _ because : is forbidden in keywords
time_stamp = end_time.isoformat(' ').replace(':', '_')
# get user
user = getpass.getuser().replace(' ', '_')
# get host
host_name = gethostname()

# Create vector layer and return
V = Vector(data=attributes,
projection=I.get_projection(),
geometry=I.get_geometry(),
name=_('Estimated buildings affected'),
keywords={'impact_summary': impact_summary,
'impact_table': impact_table,
'map_title': map_title,
'elapsed_time': elapsed_time_sec,
'time_stamp': time_stamp,
'user': user,
'host_name': host_name},
'map_title': map_title
},
style_info=style_info)
return V

0 comments on commit 32a10c9

Please sign in to comment.