Skip to content

Commit

Permalink
Merge pull request #88 from Deltares/test/81-definition-of-testcases
Browse files Browse the repository at this point in the history
Test/81 definition of testcases
  • Loading branch information
Carsopre authored Oct 18, 2023
2 parents 5d4b641 + fef60e3 commit 77aa61e
Show file tree
Hide file tree
Showing 87 changed files with 83,057 additions and 451 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
from dataclasses import dataclass
import math

from koswat.calculations.protocols import ReinforcementProfileProtocol
from koswat.dike.profile.koswat_input_profile_base import KoswatInputProfileBase


@dataclass
class CofferDamInputProfile(KoswatInputProfileBase, ReinforcementProfileProtocol):
length_coffer_dam: float
length_coffer_dam: float = math.nan
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
from dataclasses import dataclass
import math

from koswat.calculations.protocols import ReinforcementInputProfileProtocol
from koswat.dike.profile.koswat_input_profile_base import KoswatInputProfileBase


@dataclass
class PipingWallInputProfile(KoswatInputProfileBase, ReinforcementInputProfileProtocol):
length_piping_wall: float
length_piping_wall: float = math.nan
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from dataclasses import dataclass
from koswat.calculations.protocols import ReinforcementInputProfileProtocol
from koswat.dike.profile.koswat_input_profile_base import KoswatInputProfileBase


@dataclass
class SoilInputProfile(KoswatInputProfileBase, ReinforcementInputProfileProtocol):
pass
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from __future__ import annotations
from dataclasses import dataclass
import math

from koswat.calculations.protocols import ReinforcementProfileProtocol
from koswat.dike.profile.koswat_input_profile_base import KoswatInputProfileBase


@dataclass
class StabilityWallInputProfile(KoswatInputProfileBase, ReinforcementProfileProtocol):
length_stability_wall: float
length_stability_wall: float = math.nan
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import logging
import math
from typing import Type

from koswat.calculations.protocols import (
Expand Down Expand Up @@ -57,7 +58,8 @@ def _get_reinforcement_profile_input(self) -> ReinforcementInputProfileProtocol:
return _calculator.build()

def _get_characteristic_points(
self, input_profile: ReinforcementInputProfileProtocol
self,
input_profile: ReinforcementInputProfileProtocol,
) -> CharacteristicPoints:
_char_points_builder = CharacteristicPointsBuilder()
_char_points_builder.input_profile = input_profile
Expand Down
19 changes: 6 additions & 13 deletions koswat/configuration/settings/koswat_scenario.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
from __future__ import annotations
from dataclasses import dataclass

import math

from koswat.configuration.koswat_config_protocol import KoswatConfigProtocol


@dataclass
class KoswatScenario(KoswatConfigProtocol):
scenario_name: str
scenario_section: str
d_h: float
d_s: float
d_p: float
kruin_breedte: float
buiten_talud: float

def __init__(self) -> None:
self.scenario_name = ""
self.scenario_section = ""
self.d_h = math.nan
self.d_s = math.nan
self.d_p = math.nan
self.kruin_breedte = math.nan
self.buiten_talud = math.nan
scenario_name: str = ""
scenario_section: str = ""
kruin_breedte: float = math.nan
buiten_talud: float = math.nan

def is_valid(self) -> bool:
return (
Expand Down
4 changes: 4 additions & 0 deletions koswat/cost_report/io/csv/summary_matrix_csv_fom_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def location_as_row(
_location_as_row.extend(_m_values)
return _location_as_row

if not any(available_locations):
logging.warning("No locations specified for the report.")
return [[]]

# Initiate locations matrix.
# Note: Not the most efficient way, but I want to keep the reports with only
# the locations that support one (or more) profile reinforcements.
Expand Down
32 changes: 31 additions & 1 deletion koswat/cost_report/summary/koswat_summary_builder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import logging
import math
from typing import List

from koswat.calculations import ReinforcementProfileBuilderFactory
from koswat.calculations.protocols import ReinforcementProfileProtocol
from koswat.configuration.settings.koswat_run_scenario_settings import (
KoswatRunScenarioSettings,
)
from koswat.configuration.settings.koswat_scenario import KoswatScenario
from koswat.core.protocols import BuilderProtocol
from koswat.cost_report.multi_location_profile import (
MultiLocationProfileCostReportBuilder,
)
from koswat.cost_report.summary.koswat_summary import KoswatSummary
from koswat.dike.profile.koswat_input_profile_base import KoswatInputProfileBase


class KoswatSummaryBuilder(BuilderProtocol):
Expand All @@ -19,18 +22,45 @@ class KoswatSummaryBuilder(BuilderProtocol):
def __init__(self) -> None:
self.run_scenario_settings = None

@staticmethod
def _get_corrected_koswat_scenario(
orignial_scenario: KoswatScenario, input_profile_base: KoswatInputProfileBase
) -> KoswatScenario:
"""
Get a koswat scenario (`KoswatScenario`) whose values are not `math.nan`.
In practice this means that when a `KoswatScenario` value has not been set
the corresponding one from `KoswatProfileBase` will be used instead.
By having this code here we *guarantee* that a summary can be built with only
the mandatory values of a `KoswatScenario`.
Returns:
KoswatScenario: Valid scenario to be used in reinforcements.
"""
_new_koswat_scenario = KoswatScenario(**orignial_scenario.__dict__)
if math.isnan(_new_koswat_scenario.kruin_breedte):
_new_koswat_scenario.kruin_breedte = input_profile_base.kruin_breedte
if math.isnan(_new_koswat_scenario.buiten_talud):
_new_koswat_scenario.buiten_talud = input_profile_base.buiten_talud

return _new_koswat_scenario

def _get_calculated_profile_list(self) -> List[ReinforcementProfileProtocol]:
_available_reinforcements = (
ReinforcementProfileBuilderFactory.get_available_reinforcements()
)
_calculated_profiles = []
_corrected_scenario = self._get_corrected_koswat_scenario(
self.run_scenario_settings.scenario,
self.run_scenario_settings.input_profile_case.input_data,
)
for _reinforcement_type in _available_reinforcements:
try:
_builder = ReinforcementProfileBuilderFactory.get_builder(
_reinforcement_type
)
_builder.base_profile = self.run_scenario_settings.input_profile_case
_builder.scenario = self.run_scenario_settings.scenario
_builder.scenario = _corrected_scenario
_calc_profile = _builder.build()
_calculated_profiles.append(_calc_profile)
except Exception as e_info:
Expand Down
25 changes: 14 additions & 11 deletions koswat/dike/profile/koswat_input_profile_base.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
from __future__ import annotations
from dataclasses import dataclass
import math

from koswat.dike.koswat_input_profile_protocol import KoswatInputProfileProtocol


@dataclass
class KoswatInputProfileBase(KoswatInputProfileProtocol):
dike_section: str
buiten_maaiveld: float
buiten_talud: float
buiten_berm_hoogte: float
buiten_berm_breedte: float
kruin_hoogte: float
kruin_breedte: float
binnen_talud: float
binnen_berm_hoogte: float
binnen_berm_breedte: float
binnen_maaiveld: float
dike_section: str = ""
buiten_maaiveld: float = math.nan
buiten_talud: float = math.nan
buiten_berm_hoogte: float = math.nan
buiten_berm_breedte: float = math.nan
kruin_hoogte: float = math.nan
kruin_breedte: float = math.nan
binnen_talud: float = math.nan
binnen_berm_hoogte: float = math.nan
binnen_berm_breedte: float = math.nan
binnen_maaiveld: float = math.nan
9 changes: 5 additions & 4 deletions koswat/dike/surroundings/wrapper/surroundings_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import List

from shapely.geometry import Point

from koswat.dike.surroundings.buildings_polderside.koswat_buildings_polderside import (
Expand Down Expand Up @@ -60,7 +58,7 @@ def __init__(self) -> None:
self.roads_class_unknown_dikeside = None

@property
def locations(self) -> List[PointSurroundings]:
def locations(self) -> list[PointSurroundings]:
"""
Each location represents 1 meter in a real scale map.
Expand All @@ -71,7 +69,7 @@ def locations(self) -> List[PointSurroundings]:
return []
return self.buldings_polderside.points

def get_locations_after_distance(self, distance: float) -> List[Point]:
def get_locations_after_distance(self, distance: float) -> list[Point]:
"""
Gets all locations which are safe from buildings in a radius of `distance`.
Expand All @@ -87,4 +85,7 @@ def is_at_safe_distance(point_surroundings: PointSurroundings) -> bool:
return True
return distance < point_surroundings.distance_to_buildings[0]

if not self.buldings_polderside:
return []

return list(filter(is_at_safe_distance, self.buldings_polderside.points))
29 changes: 28 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pytest = "^7.2.1"
pytest-cov = "^3.0.0"
coverage = "^6.4.4"
teamcity-messages = "^1.32"
opencv-python = "^4.8.1.78"

[tool.poetry.group.dev.dependencies]
black = "^22.8.0"
Expand Down
Empty file.
29 changes: 29 additions & 0 deletions tests/acceptance_scenarios/acceptance_test_scenario_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from tests.acceptance_scenarios.acceptance_test_scenario_dataclasses import (
AcceptanceTestScenarioCombinations,
)
from tests.acceptance_scenarios.koswat_input_profile_base_cases import (
AcceptanceTestInputProfileCases,
)
from tests.acceptance_scenarios.koswat_scenario_test_cases import (
ScenarioCasesAB,
ScenarioCasesC,
)
from tests.acceptance_scenarios.layers_cases import LayersCases

acceptance_test_combinations = [
AcceptanceTestScenarioCombinations(
profile_case=AcceptanceTestInputProfileCases.profile_dijk1,
layers_cases=[LayersCases.with_acceptance_criteria],
scenario_cases=ScenarioCasesAB.cases,
),
AcceptanceTestScenarioCombinations(
profile_case=AcceptanceTestInputProfileCases.profile_dijk2,
layers_cases=[LayersCases.with_acceptance_criteria],
scenario_cases=ScenarioCasesAB.cases,
),
AcceptanceTestScenarioCombinations(
profile_case=AcceptanceTestInputProfileCases.profile_dijk3,
layers_cases=[LayersCases.with_acceptance_criteria],
scenario_cases=ScenarioCasesC.cases,
),
]
Loading

0 comments on commit 77aa61e

Please sign in to comment.