Skip to content

Commit

Permalink
feat: add hazard cost to the configuration (#406)
Browse files Browse the repository at this point in the history
* chore: add scenario_cost to the network config

* chore: add scenario_cost to the network config

* chore: correct hazard_field_name from list[str] to str

* chore: small cleanup/corrections

* chore: process review comments
  • Loading branch information
ArdtK authored Apr 8, 2024
1 parent fb3d54e commit 3a9f80e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
class HazardIntersectBuilderForGpkg(HazardIntersectBuilderBase):
hazard_field_name: str = ""
hazard_aggregate_wl: str = ""
hazard_names: list[str] = field(default_factory=list)
ra2ce_names: list[str] = field(default_factory=list)
hazard_gpkg_files: list[str] = field(default_factory=list)
hazard_gpkg_files: list[Path] = field(default_factory=list)

def _from_networkx(self, hazard_overlay: Graph) -> Graph:
"""Overlays the hazard `gpkg` file over the road segments NetworkX graph.
Expand Down
1 change: 0 additions & 1 deletion ra2ce/network/hazard/hazard_overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def hazard_intersect(
return HazardIntersectBuilderForGpkg(
hazard_field_name=self._hazard_field_name,
hazard_aggregate_wl=self._hazard_aggregate_wl,
hazard_names=self.hazard_names,
ra2ce_names=self.ra2ce_names,
hazard_gpkg_files=self.hazard_files.gpkg,
).get_intersection(to_overlay)
Expand Down
1 change: 1 addition & 0 deletions ra2ce/network/network_config_data/network_config_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class HazardSection:
hazard_field_name: list[str] = field(default_factory=list)
aggregate_wl: AggregateWlEnum = field(default_factory=lambda: AggregateWlEnum.NONE)
hazard_crs: str = ""
scenario_cost: list[float] = field(default_factory=list)


@dataclass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from configparser import ConfigParser
from pathlib import Path
from typing import Any, Union
Expand Down Expand Up @@ -26,7 +27,7 @@ class NetworkConfigDataReader(ConfigDataReaderProtocol):
def __init__(self) -> None:
self._parser = ConfigParser(
inline_comment_prefixes="#",
converters={"list": lambda x: [x.strip() for x in x.split(",")]},
converters={"list": lambda x: [x.strip() for x in re.split("[,|;]", x)]},
)

def read(self, ini_file: Path) -> NetworkConfigData:
Expand Down Expand Up @@ -213,6 +214,11 @@ def get_hazard_section(self) -> HazardSection:
_hazard_section.aggregate_wl = AggregateWlEnum.get_enum(
self._parser.get(_section, "aggregate_wl", fallback=None)
)
_hazard_section.scenario_cost = list(
self._parser.getlist(
_section, "scenario_cost", fallback=_hazard_section.scenario_cost
)
)
return _hazard_section

def get_cleanup_section(self) -> CleanupSection:
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/acceptance_test_data/network.ini
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ hazard_id = None
hazard_field_name = waterdepth
aggregate_wl = max
hazard_crs = EPSG:4326
scenario_cost = 0.00;168789.00

[cleanup]
snapping_threshold = None
Expand Down

0 comments on commit 3a9f80e

Please sign in to comment.