Skip to content

Commit

Permalink
Implemented ability to run buildings flood risk analysis (#36).
Browse files Browse the repository at this point in the history
  • Loading branch information
ldebek committed Oct 16, 2024
1 parent 8a46a47 commit a509fcd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ History
-------------------

- Fixes/enhancements: #35, #37
- Implemented ability to run buildings flood risk analysis (#36).


0.3.5 (2024-9-12)
Expand Down
13 changes: 13 additions & 0 deletions lizard_qgis_plugin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,19 @@ def get_capabilities_layer_uris(wms_url):
return wms_uris


def get_scenario_instance_results(lizard_url, scenario_instance, subendpoint=None, results_limit=100):
"""Get the scenario instance results, either from basic endpoint, or specific subendpoint."""
scenario_uuid = scenario_instance["uuid"]
if subendpoint:
url = f"{lizard_url}scenarios/{scenario_uuid}/results/{subendpoint}"
else:
url = f"{lizard_url}scenarios/{scenario_uuid}/results"
r = requests.get(url=url, auth=("__key__", get_api_key_auth_manager()), params={"limit": results_limit})
r.raise_for_status()
available_results = r.json()["results"]
return available_results


def get_available_rasters_list(lizard_url):
"""List all available rasters."""
url = f"{lizard_url}rasters/"
Expand Down
4 changes: 3 additions & 1 deletion lizard_qgis_plugin/widgets/lizard_archive_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
create_tree_group,
find_rasters,
get_capabilities_layer_uris,
get_scenario_instance_results,
get_url_raster_instance,
layer_to_gpkg,
reproject_geometry,
Expand Down Expand Up @@ -357,7 +358,7 @@ def fetch_results(self):
scenario_uuid_item = self.scenario_model.item(current_row, self.SCENARIO_UUID_COLUMN_IDX)
scenario_uuid = scenario_uuid_item.text()
scenario_instance = self.current_scenario_instances[scenario_uuid]
scenario_results = self.plugin.downloader.get_scenario_instance_results(scenario_uuid)
scenario_results = get_scenario_instance_results(self.plugin.downloader.LIZARD_URL, scenario_instance)
self.current_scenario_results.clear()
self.scenario_results_model.clear()
self.current_scenario_flood_risk_methods.clear()
Expand Down Expand Up @@ -580,6 +581,7 @@ def on_flood_risk_analysis_finished(self, scenario_instance, message):
self.plugin.communication.clear_message_bar()
self.plugin.communication.bar_info(message)
self.log_feedback(message)
self.fetch_results()

def on_flood_risk_analysis_failed(self, scenario_instance, error_message):
"""Feedback on flood risk analysis failed signal."""
Expand Down
8 changes: 6 additions & 2 deletions lizard_qgis_plugin/workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def __init__(
self.output_format = output_format
self.total_progress = 100
self.current_step = 0
self.number_of_steps = 5
self.number_of_steps = 6
self.percentage_per_step = self.total_progress / self.number_of_steps
self.signals = LizardFloodRiskAnalysisSignals()

Expand All @@ -411,6 +411,7 @@ def analyze_buildings_flood_risk(self):
self.report_progress(progress_msg)
vulnerable_buildings_result = create_vulnerable_buildings_result(lizard_url, api_key, self.scenario_instance)
result_id = vulnerable_buildings_result["id"]
time.sleep(self.TASK_CHECK_SLEEP_TIME)
progress_msg = f'Spawn processing of the "vulnerable buildings" result task...'
self.report_progress(progress_msg)
process_task = create_buildings_flood_risk_task(
Expand Down Expand Up @@ -442,7 +443,10 @@ def run(self):
except LizardFloodRiskAnalysisError as e:
self.report_failure(str(e))
except Exception as e:
error_msg = f"Buildings flood risk analysis failed due to the following error: {e}"
try:
error_msg = f"Buildings flood risk analysis failed due to the following error: {e.response.text}"
except AttributeError:
error_msg = f"Buildings flood risk analysis failed due to the following error: {e}"
self.report_failure(error_msg)

def report_progress(self, progress_message=None, increase_current_step=True):
Expand Down

0 comments on commit a509fcd

Please sign in to comment.