From a9850c13dfd7200f99bdd2e0934406e9d4090667 Mon Sep 17 00:00:00 2001 From: "Carles S. Soriano Perez" Date: Thu, 19 Oct 2023 16:30:09 +0200 Subject: [PATCH 1/5] chore: Created submodule reinforced_layers to contain all information related to how to determine layers geometries for a given reinforcement type. --- koswat/calculations/__init__.py | 4 +- .../io/reinforced_profile_plot_exporter.py | 7 +- .../outside_slope_reinforcement/__init__.py | 3 - ...ide_slope_reinforcement_profile_builder.py | 15 +- .../reinforcement_profile_builder_protocol.py | 4 +- .../reinforcement_profile_protocol.py | 2 +- .../reinforcement_layers/__init__.py | 0 ...pe_reinforcement_layers_wrapper_builder.py | 2 +- .../reinforcement_base_layer.py | 45 +++++ .../reinforcement_coating_layer.py | 69 ++++++++ .../reinforcement_layer_protocol.py | 10 ++ .../reinforcement_layers_wrapper.py | 57 +++++++ ...rd_reinforcement_layers_wrapper_builder.py | 2 +- .../reinforcement_layers_wrapper.py | 157 ------------------ .../reinforcement_profile_builder_factory.py | 6 +- .../standard_reinforcement/__init__.py | 3 - .../standard_reinforcement_profile_builder.py | 27 ++- .../cost_report/profile/layer_cost_report.py | 4 +- tests/calculations/__init__.py | 24 +-- ...pe_reinforcement_layers_wrapper_builder.py | 2 +- .../test_reinforcement_layers_wrapper.py | 2 +- ...t_reinforcement_profile_builder_factory.py | 16 +- .../test_volume_cost_parameters_builder.py | 3 +- 23 files changed, 237 insertions(+), 227 deletions(-) create mode 100644 koswat/calculations/reinforcement_layers/__init__.py rename koswat/calculations/{outside_slope_reinforcement => reinforcement_layers}/outside_slope_reinforcement_layers_wrapper_builder.py (98%) create mode 100644 koswat/calculations/reinforcement_layers/reinforcement_base_layer.py create mode 100644 koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py create mode 100644 koswat/calculations/reinforcement_layers/reinforcement_layer_protocol.py create mode 100644 koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py rename koswat/calculations/{standard_reinforcement => reinforcement_layers}/standard_reinforcement_layers_wrapper_builder.py (98%) delete mode 100644 koswat/calculations/reinforcement_layers_wrapper.py diff --git a/koswat/calculations/__init__.py b/koswat/calculations/__init__.py index b0700237..0040ab48 100644 --- a/koswat/calculations/__init__.py +++ b/koswat/calculations/__init__.py @@ -1,4 +1,6 @@ -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementLayersWrapper +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementLayersWrapper, +) from koswat.calculations.reinforcement_profile_builder_factory import ( ReinforcementProfileBuilderFactory, ) diff --git a/koswat/calculations/io/reinforced_profile_plot_exporter.py b/koswat/calculations/io/reinforced_profile_plot_exporter.py index d62d000f..7687adcf 100644 --- a/koswat/calculations/io/reinforced_profile_plot_exporter.py +++ b/koswat/calculations/io/reinforced_profile_plot_exporter.py @@ -1,8 +1,9 @@ from pathlib import Path -from typing import List from koswat.calculations.protocols import ReinforcementProfileProtocol -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementCoatingLayer +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementCoatingLayer, +) from koswat.dike.layers.koswat_layer_protocol import KoswatLayerProtocol from koswat.plots.dike.koswat_layers_wrapper_plot import KoswatLayersWrapperPlot from koswat.plots.geometries.highlight_geometry_plot import HighlightGeometryPlot @@ -44,7 +45,7 @@ def _export_layers( self, output_file: Path, layer_to_highlight, - layers_to_plot: List[KoswatLayerProtocol], + layers_to_plot: list[KoswatLayerProtocol], ): # Define canvas with KoswatFigureContextHandler( diff --git a/koswat/calculations/outside_slope_reinforcement/__init__.py b/koswat/calculations/outside_slope_reinforcement/__init__.py index 4d00973a..cba3229a 100644 --- a/koswat/calculations/outside_slope_reinforcement/__init__.py +++ b/koswat/calculations/outside_slope_reinforcement/__init__.py @@ -3,9 +3,6 @@ CofferdamReinforcementProfile, CofferdamReinforcementProfileCalculation, ) -from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_layers_wrapper_builder import ( - OutsideSlopeReinforcementLayersWrapperBuilder, -) from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_profile import ( OutsideSlopeReinforcementProfile, ) diff --git a/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_profile_builder.py b/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_profile_builder.py index 62c293db..05a77363 100644 --- a/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_profile_builder.py +++ b/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_profile_builder.py @@ -1,10 +1,8 @@ -from typing import Type - from koswat.calculations.outside_slope_reinforcement.cofferdam import ( CofferdamReinforcementProfile, CofferdamReinforcementProfileCalculation, ) -from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_layers_wrapper_builder import ( +from koswat.calculations.reinforcement_layers.outside_slope_reinforcement_layers_wrapper_builder import ( OutsideSlopeReinforcementLayersWrapperBuilder, ) from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_profile import ( @@ -15,7 +13,9 @@ ReinforcementInputProfileProtocol, ReinforcementProfileBuilderProtocol, ) -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementLayersWrapper +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementLayersWrapper, +) from koswat.configuration.settings import KoswatScenario from koswat.dike.characteristic_points.characteristic_points import CharacteristicPoints from koswat.dike.characteristic_points.characteristic_points_builder import ( @@ -27,16 +27,15 @@ class OutsideSlopeReinforcementProfileBuilder(ReinforcementProfileBuilderProtocol): base_profile: KoswatProfileBase scenario: KoswatScenario - reinforcement_profile_type: Type[OutsideSlopeReinforcementProfile] + reinforcement_profile_type: type[OutsideSlopeReinforcementProfile] @staticmethod def get_standard_reinforcement_calculator( - reinforcement_type: Type[OutsideSlopeReinforcementProfile], + reinforcement_type: type[OutsideSlopeReinforcementProfile], ): if issubclass(reinforcement_type, CofferdamReinforcementProfile): return CofferdamReinforcementProfileCalculation - else: - raise NotImplementedError(f"Type {reinforcement_type} not supported.") + raise NotImplementedError(f"Type {reinforcement_type} not supported.") def _get_reinforcement_profile_input( self, diff --git a/koswat/calculations/protocols/reinforcement_profile_builder_protocol.py b/koswat/calculations/protocols/reinforcement_profile_builder_protocol.py index 31905e8e..87aeaea4 100644 --- a/koswat/calculations/protocols/reinforcement_profile_builder_protocol.py +++ b/koswat/calculations/protocols/reinforcement_profile_builder_protocol.py @@ -1,4 +1,4 @@ -from typing import Protocol, Type, runtime_checkable +from typing import Protocol, runtime_checkable from koswat.calculations.protocols.reinforcement_profile_protocol import ( ReinforcementProfileProtocol, @@ -12,7 +12,7 @@ class ReinforcementProfileBuilderProtocol(BuilderProtocol, Protocol): base_profile: KoswatProfileBase scenario: KoswatScenario - reinforcement_profile_type: Type[ReinforcementProfileProtocol] + reinforcement_profile_type: type[ReinforcementProfileProtocol] def build(self) -> ReinforcementProfileProtocol: """ diff --git a/koswat/calculations/protocols/reinforcement_profile_protocol.py b/koswat/calculations/protocols/reinforcement_profile_protocol.py index 68b73fec..67d14681 100644 --- a/koswat/calculations/protocols/reinforcement_profile_protocol.py +++ b/koswat/calculations/protocols/reinforcement_profile_protocol.py @@ -3,7 +3,7 @@ from koswat.calculations.protocols.reinforcement_input_profile_protocol import ( ReinforcementInputProfileProtocol, ) -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementLayersWrapper +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ReinforcementLayersWrapper from koswat.dike.koswat_profile_protocol import KoswatProfileProtocol diff --git a/koswat/calculations/reinforcement_layers/__init__.py b/koswat/calculations/reinforcement_layers/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_layers_wrapper_builder.py b/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py similarity index 98% rename from koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_layers_wrapper_builder.py rename to koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py index a8bcdeee..c0cd924a 100644 --- a/koswat/calculations/outside_slope_reinforcement/outside_slope_reinforcement_layers_wrapper_builder.py +++ b/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py @@ -1,6 +1,6 @@ from shapely.geometry import Point, Polygon -from koswat.calculations.reinforcement_layers_wrapper import ( +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( ReinforcementBaseLayer, ReinforcementCoatingLayer, ReinforcementLayerProtocol, diff --git a/koswat/calculations/reinforcement_layers/reinforcement_base_layer.py b/koswat/calculations/reinforcement_layers/reinforcement_base_layer.py new file mode 100644 index 00000000..ce40565d --- /dev/null +++ b/koswat/calculations/reinforcement_layers/reinforcement_base_layer.py @@ -0,0 +1,45 @@ +from __future__ import annotations + + +from shapely.geometry import LineString, Polygon, MultiPolygon +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) +from koswat.core.geometries.calc_library import get_polygon_coordinates +from koswat.dike.layers.base_layer import KoswatBaseLayer + +from koswat.dike.material.koswat_material_type import KoswatMaterialType + + +class ReinforcementBaseLayer(ReinforcementLayerProtocol): + material_type: KoswatMaterialType + outer_geometry: Polygon + material_geometry: Polygon + upper_points: LineString + new_layer_geometry: Polygon | MultiPolygon + new_layer_surface: LineString + old_layer_geometry: Polygon + + def __init__(self) -> None: + self.material_type = None + self.outer_geometry = None + self.material_geometry = None + self.upper_points = None + self.new_layer_geometry = None + + def as_data_dict(self) -> dict: + _geometry = [] + if self.outer_geometry: + _geometry = list(get_polygon_coordinates(self.outer_geometry).coords) + return dict( + material=self.material_type.name, + geometry=_geometry, + ) + + @classmethod + def from_koswat_base_layer( + cls, base_layer: KoswatBaseLayer + ) -> ReinforcementBaseLayer: + _reinforced_base_layer = cls() + _reinforced_base_layer.__dict__ = base_layer.__dict__ + return _reinforced_base_layer diff --git a/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py b/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py new file mode 100644 index 00000000..bf1cebb8 --- /dev/null +++ b/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py @@ -0,0 +1,69 @@ +from __future__ import annotations + + +from shapely.geometry import LineString, Polygon, MultiPolygon +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ReinforcementLayerProtocol + +from koswat.core.geometries.calc_library import get_polygon_coordinates +from koswat.dike.layers.coating_layer import KoswatCoatingLayer +from koswat.dike.material.koswat_material_type import KoswatMaterialType + +class ReinforcementCoatingLayer(ReinforcementLayerProtocol): + material_type: KoswatMaterialType + outer_geometry: Polygon + material_geometry: Polygon + upper_points: LineString + old_layer_geometry: Polygon + new_layer_geometry: Polygon | MultiPolygon + new_layer_surface: LineString + removal_layer_geometry: Polygon + + def __init__(self) -> None: + self.material_type = None + self.outer_geometry = None + self.material_geometry = None + self.upper_points = None + self.new_layer_geometry = None + self.removal_layer_geometry = None + + def as_data_dict(self) -> dict: + _geometry = [] + if self.outer_geometry: + _geometry = list(get_polygon_coordinates(self.outer_geometry).coords) + return dict( + material=self.material_type.name, + depth=self.depth, + geometry=_geometry, + ) + + @classmethod + def from_koswat_coating_layer( + cls, coating_layer: KoswatCoatingLayer + ) -> ReinforcementCoatingLayer: + _reinforced_coating_layer = cls() + _reinforced_coating_layer.__dict__ = coating_layer.__dict__ + return _reinforced_coating_layer + + @classmethod + def with_same_outer_geometry( + cls, coating_layer: KoswatCoatingLayer + ) -> ReinforcementCoatingLayer: + """ + Creates a new reinforcement coating layer which does not differ + in geometry from the provided coating layer. This was found to + be needed in KOSWAT_82. + + Args: + coating_layer (KoswatCoatingLayer): Base coating layer. + + Returns: + ReinforcementCoatingLayer: Resulting coating layer with "empty" + polygons for added / removed (layer) geometries. + """ + _reinforced_coating_layer = cls.from_koswat_coating_layer(coating_layer) + _reinforced_coating_layer.old_layer_geometry = coating_layer.outer_geometry + _reinforced_coating_layer.removal_layer_geometry = Polygon() + _reinforced_coating_layer.new_layer_geometry = Polygon() + _reinforced_coating_layer.new_layer_surface = LineString() + return _reinforced_coating_layer + diff --git a/koswat/calculations/reinforcement_layers/reinforcement_layer_protocol.py b/koswat/calculations/reinforcement_layers/reinforcement_layer_protocol.py new file mode 100644 index 00000000..65a0ff88 --- /dev/null +++ b/koswat/calculations/reinforcement_layers/reinforcement_layer_protocol.py @@ -0,0 +1,10 @@ +from typing import Protocol, runtime_checkable +from koswat.dike.layers import KoswatLayerProtocol +from shapely.geometry import LineString, Polygon, MultiPolygon + + +@runtime_checkable +class ReinforcementLayerProtocol(KoswatLayerProtocol, Protocol): + new_layer_geometry: Polygon | MultiPolygon + new_layer_surface: LineString + old_layer_geometry: Polygon diff --git a/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py b/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py new file mode 100644 index 00000000..1e51ebec --- /dev/null +++ b/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py @@ -0,0 +1,57 @@ +from koswat.calculations.reinforcement_layers.reinforcement_base_layer import ( + ReinforcementBaseLayer, +) +from koswat.calculations.reinforcement_layers.reinforcement_coating_layer import ( + ReinforcementCoatingLayer, +) +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) + + +from koswat.dike.layers.layers_wrapper import KoswatLayersWrapperProtocol +from koswat.dike.material.koswat_material_type import KoswatMaterialType + + +class ReinforcementLayersWrapper(KoswatLayersWrapperProtocol): + base_layer: ReinforcementBaseLayer + coating_layers: list[ReinforcementCoatingLayer] + + def __init__(self) -> None: + self.base_layer = None + self.coating_layers = [] + + def as_data_dict(self) -> dict: + return dict( + base_layer=self.base_layer.as_data_dict(), + coating_layers=[c_l.as_data_dict() for c_l in self.coating_layers], + ) + + def get_layer(self, material_type: KoswatMaterialType) -> ReinforcementCoatingLayer: + _found_layer = next( + ( + _layer + for _layer in self.coating_layers + if _layer.material_type == material_type + ), + None, + ) + if not _found_layer: + raise ValueError( + "Material {} not present in the layers.".format(material_type.name) + ) + return _found_layer + + @property + def layers(self) -> list[ReinforcementLayerProtocol]: + """ + All the stored layers being the `KoswatBaseLayer` the latest one in the collection. + + Returns: + List[KoswatLayerProtocol]: Ordered list of `KoswatLayerProtocol`. + """ + _layers = [] + _layers.extend(self.coating_layers) + if self.base_layer: + _layers.append(self.base_layer) + return _layers diff --git a/koswat/calculations/standard_reinforcement/standard_reinforcement_layers_wrapper_builder.py b/koswat/calculations/reinforcement_layers/standard_reinforcement_layers_wrapper_builder.py similarity index 98% rename from koswat/calculations/standard_reinforcement/standard_reinforcement_layers_wrapper_builder.py rename to koswat/calculations/reinforcement_layers/standard_reinforcement_layers_wrapper_builder.py index 1180d6e2..d7af072d 100644 --- a/koswat/calculations/standard_reinforcement/standard_reinforcement_layers_wrapper_builder.py +++ b/koswat/calculations/reinforcement_layers/standard_reinforcement_layers_wrapper_builder.py @@ -1,6 +1,6 @@ from shapely.geometry import Point, Polygon -from koswat.calculations.reinforcement_layers_wrapper import ( +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( ReinforcementBaseLayer, ReinforcementCoatingLayer, ReinforcementLayersWrapper, diff --git a/koswat/calculations/reinforcement_layers_wrapper.py b/koswat/calculations/reinforcement_layers_wrapper.py deleted file mode 100644 index abc06cec..00000000 --- a/koswat/calculations/reinforcement_layers_wrapper.py +++ /dev/null @@ -1,157 +0,0 @@ -from __future__ import annotations - -from typing import Protocol, runtime_checkable - -from shapely.geometry import LineString, Polygon, MultiPolygon - -from koswat.core.geometries.calc_library import get_polygon_coordinates -from koswat.dike.layers import KoswatLayerProtocol -from koswat.dike.layers.base_layer import KoswatBaseLayer -from koswat.dike.layers.coating_layer import KoswatCoatingLayer -from koswat.dike.layers.layers_wrapper import KoswatLayersWrapperProtocol -from koswat.dike.material.koswat_material_type import KoswatMaterialType - - -@runtime_checkable -class ReinforcementLayerProtocol(KoswatLayerProtocol, Protocol): - new_layer_geometry: Polygon | MultiPolygon - new_layer_surface: LineString - old_layer_geometry: Polygon - - -class ReinforcementCoatingLayer(ReinforcementLayerProtocol): - material_type: KoswatMaterialType - outer_geometry: Polygon - material_geometry: Polygon - upper_points: LineString - old_layer_geometry: Polygon - new_layer_geometry: Polygon | MultiPolygon - new_layer_surface: LineString - removal_layer_geometry: Polygon - - def __init__(self) -> None: - self.material_type = None - self.outer_geometry = None - self.material_geometry = None - self.upper_points = None - self.new_layer_geometry = None - self.removal_layer_geometry = None - - def as_data_dict(self) -> dict: - _geometry = [] - if self.outer_geometry: - _geometry = list(get_polygon_coordinates(self.outer_geometry).coords) - return dict( - material=self.material_type.name, - depth=self.depth, - geometry=_geometry, - ) - - @classmethod - def from_koswat_coating_layer( - cls, coating_layer: KoswatCoatingLayer - ) -> ReinforcementCoatingLayer: - _reinforced_coating_layer = cls() - _reinforced_coating_layer.__dict__ = coating_layer.__dict__ - return _reinforced_coating_layer - - @classmethod - def with_same_outer_geometry( - cls, coating_layer: KoswatCoatingLayer - ) -> ReinforcementCoatingLayer: - """ - Creates a new reinforcement coating layer which does not differ - in geometry from the provided coating layer. This was found to - be needed in KOSWAT_82. - - Args: - coating_layer (KoswatCoatingLayer): Base coating layer. - - Returns: - ReinforcementCoatingLayer: Resulting coating layer with "empty" - polygons for added / removed (layer) geometries. - """ - _reinforced_coating_layer = cls.from_koswat_coating_layer(coating_layer) - _reinforced_coating_layer.old_layer_geometry = coating_layer.outer_geometry - _reinforced_coating_layer.removal_layer_geometry = Polygon() - _reinforced_coating_layer.new_layer_geometry = Polygon() - _reinforced_coating_layer.new_layer_surface = LineString() - return _reinforced_coating_layer - - -class ReinforcementBaseLayer(ReinforcementLayerProtocol): - material_type: KoswatMaterialType - outer_geometry: Polygon - material_geometry: Polygon - upper_points: LineString - new_layer_geometry: Polygon | MultiPolygon - new_layer_surface: LineString - old_layer_geometry: Polygon - - def __init__(self) -> None: - self.material_type = None - self.outer_geometry = None - self.material_geometry = None - self.upper_points = None - self.new_layer_geometry = None - - def as_data_dict(self) -> dict: - _geometry = [] - if self.outer_geometry: - _geometry = list(get_polygon_coordinates(self.outer_geometry).coords) - return dict( - material=self.material_type.name, - geometry=_geometry, - ) - - @classmethod - def from_koswat_base_layer( - cls, base_layer: KoswatBaseLayer - ) -> ReinforcementBaseLayer: - _reinforced_base_layer = cls() - _reinforced_base_layer.__dict__ = base_layer.__dict__ - return _reinforced_base_layer - - -class ReinforcementLayersWrapper(KoswatLayersWrapperProtocol): - base_layer: ReinforcementBaseLayer - coating_layers: list[ReinforcementCoatingLayer] - - def __init__(self) -> None: - self.base_layer = None - self.coating_layers = [] - - def as_data_dict(self) -> dict: - return dict( - base_layer=self.base_layer.as_data_dict(), - coating_layers=[c_l.as_data_dict() for c_l in self.coating_layers], - ) - - def get_layer(self, material_type: KoswatMaterialType) -> ReinforcementCoatingLayer: - _found_layer = next( - ( - _layer - for _layer in self.coating_layers - if _layer.material_type == material_type - ), - None, - ) - if not _found_layer: - raise ValueError( - "Material {} not present in the layers.".format(material_type.name) - ) - return _found_layer - - @property - def layers(self) -> list[ReinforcementLayerProtocol]: - """ - All the stored layers being the `KoswatBaseLayer` the latest one in the collection. - - Returns: - List[KoswatLayerProtocol]: Ordered list of `KoswatLayerProtocol`. - """ - _layers = [] - _layers.extend(self.coating_layers) - if self.base_layer: - _layers.append(self.base_layer) - return _layers diff --git a/koswat/calculations/reinforcement_profile_builder_factory.py b/koswat/calculations/reinforcement_profile_builder_factory.py index bd315a34..76725b7b 100644 --- a/koswat/calculations/reinforcement_profile_builder_factory.py +++ b/koswat/calculations/reinforcement_profile_builder_factory.py @@ -1,5 +1,3 @@ -from typing import List, Type - from koswat.calculations.outside_slope_reinforcement import ( CofferDamInputProfile, CofferdamReinforcementProfile, @@ -32,7 +30,7 @@ class ReinforcementProfileBuilderFactory: @staticmethod - def get_available_reinforcements() -> List[ReinforcementProfileProtocol]: + def get_available_reinforcements() -> list[ReinforcementProfileProtocol]: """ Gets all available reinforcements defined in Koswat. @@ -66,7 +64,7 @@ def get_reinforcement_input_profile( @staticmethod def get_builder( - reinforcement_profile_type: Type[ReinforcementProfileProtocol], + reinforcement_profile_type: type[ReinforcementProfileProtocol], ) -> ReinforcementProfileBuilderProtocol: """ Gets a valid reinforcement profile `builder` instance (`ReinforcementProfileBuilderProtocol`). diff --git a/koswat/calculations/standard_reinforcement/__init__.py b/koswat/calculations/standard_reinforcement/__init__.py index fc531704..f9db27f8 100644 --- a/koswat/calculations/standard_reinforcement/__init__.py +++ b/koswat/calculations/standard_reinforcement/__init__.py @@ -13,9 +13,6 @@ StabilityWallReinforcementProfile, StabilityWallReinforcementProfileCalculation, ) -from koswat.calculations.standard_reinforcement.standard_reinforcement_layers_wrapper_builder import ( - StandardReinforcementLayersWrapperBuilder, -) from koswat.calculations.standard_reinforcement.standard_reinforcement_profile import ( StandardReinforcementProfile, ) diff --git a/koswat/calculations/standard_reinforcement/standard_reinforcement_profile_builder.py b/koswat/calculations/standard_reinforcement/standard_reinforcement_profile_builder.py index 49090e3c..c66e7c24 100644 --- a/koswat/calculations/standard_reinforcement/standard_reinforcement_profile_builder.py +++ b/koswat/calculations/standard_reinforcement/standard_reinforcement_profile_builder.py @@ -1,14 +1,17 @@ from __future__ import annotations import logging -import math -from typing import Type +from koswat.calculations.reinforcement_layers.outside_slope_reinforcement_layers_wrapper_builder import ( + OutsideSlopeReinforcementLayersWrapperBuilder, +) from koswat.calculations.protocols import ( ReinforcementInputProfileProtocol, ReinforcementProfileBuilderProtocol, ) -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementLayersWrapper +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementLayersWrapper, +) from koswat.calculations.standard_reinforcement import ( PipingWallReinforcementProfile, PipingWallReinforcementProfileCalculation, @@ -17,7 +20,7 @@ StabilityWallReinforcementProfile, StabilityWallReinforcementProfileCalculation, ) -from koswat.calculations.standard_reinforcement.standard_reinforcement_layers_wrapper_builder import ( +from koswat.calculations.reinforcement_layers.standard_reinforcement_layers_wrapper_builder import ( StandardReinforcementLayersWrapperBuilder, ) from koswat.calculations.standard_reinforcement.standard_reinforcement_profile import ( @@ -34,11 +37,11 @@ class StandardReinforcementProfileBuilder(ReinforcementProfileBuilderProtocol): base_profile: KoswatProfileBase scenario: KoswatScenario - reinforcement_profile_type: Type[StandardReinforcementProfile] + reinforcement_profile_type: type[StandardReinforcementProfile] @staticmethod def get_standard_reinforcement_calculator( - reinforcement_type: Type[StandardReinforcementProfile], + reinforcement_type: type[StandardReinforcementProfile], ): if issubclass(reinforcement_type, PipingWallReinforcementProfile): return PipingWallReinforcementProfileCalculation @@ -46,8 +49,7 @@ def get_standard_reinforcement_calculator( return SoilReinforcementProfileCalculation elif issubclass(reinforcement_type, StabilityWallReinforcementProfile): return StabilityWallReinforcementProfileCalculation - else: - raise NotImplementedError(f"Type {reinforcement_type} not supported.") + raise NotImplementedError(f"Type {reinforcement_type} not supported.") def _get_reinforcement_profile_input(self) -> ReinforcementInputProfileProtocol: _calculator = self.get_standard_reinforcement_calculator( @@ -71,7 +73,14 @@ def _get_characteristic_points( def _get_reinforcement_layers_wrapper( self, profile_points: CharacteristicPoints ) -> ReinforcementLayersWrapper: - _layers_builder = StandardReinforcementLayersWrapperBuilder() + _unchanged_outside_slope = ( + self.scenario.buiten_talud == self.base_profile.input_data.buiten_talud + ) + _layers_builder = ( + StandardReinforcementLayersWrapperBuilder() + if _unchanged_outside_slope + else OutsideSlopeReinforcementLayersWrapperBuilder() + ) _layers_builder.layers_data = self.base_profile.layers_wrapper.as_data_dict() _layers_builder.profile_points = profile_points.points return _layers_builder.build() diff --git a/koswat/cost_report/profile/layer_cost_report.py b/koswat/cost_report/profile/layer_cost_report.py index 83d5d32e..8fac2f4e 100644 --- a/koswat/cost_report/profile/layer_cost_report.py +++ b/koswat/cost_report/profile/layer_cost_report.py @@ -2,7 +2,9 @@ import math -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementLayerProtocol +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementLayerProtocol, +) from koswat.cost_report.cost_report_protocol import CostReportProtocol diff --git a/tests/calculations/__init__.py b/tests/calculations/__init__.py index ea6d4843..b88cda11 100644 --- a/tests/calculations/__init__.py +++ b/tests/calculations/__init__.py @@ -1,34 +1,16 @@ -from typing import List, Type - import pytest from shapely.geometry import Point, Polygon from koswat.calculations import ReinforcementLayersWrapper -from koswat.calculations.outside_slope_reinforcement import ( - OutsideSlopeReinforcementLayersWrapperBuilder, - OutsideSlopeReinforcementProfile, -) from koswat.calculations.protocols import ReinforcementProfileProtocol -from koswat.calculations.standard_reinforcement import ( - StandardReinforcementLayersWrapperBuilder, - StandardReinforcementProfile, -) -from koswat.dike.characteristic_points.characteristic_points_builder import ( - CharacteristicPointsBuilder, -) from koswat.dike.koswat_input_profile_protocol import KoswatInputProfileProtocol -from koswat.dike.layers.layers_wrapper import ( - KoswatLayersWrapperBuilder, - KoswatLayersWrapperBuilderProtocol, - KoswatLayersWrapperProtocol, -) def almost_equal(left_value: float, right_value: float) -> bool: return abs(left_value - right_value) <= 0.01 -def _compare_points(new_points: List[Point], expected_points: List[Point]) -> List[str]: +def _compare_points(new_points: list[Point], expected_points: list[Point]) -> list[str]: _new_points = [(p.x, p.y) for p in new_points] _expected_points = [(p.x, p.y) for p in expected_points] _wrong_points = [] @@ -44,7 +26,7 @@ def _compare_points(new_points: List[Point], expected_points: List[Point]) -> Li def _compare_koswat_input_profile( reinforced_input_profile: KoswatInputProfileProtocol, expected_input_profile: KoswatInputProfileProtocol, -) -> List[str]: +) -> list[str]: _new_data_dict = reinforced_input_profile.__dict__ _exp_data_dict = expected_input_profile.__dict__ assert len(_new_data_dict) >= 10 @@ -58,7 +40,7 @@ def _compare_koswat_input_profile( def _compare_koswat_layers( new_layers: ReinforcementLayersWrapper, expected_layers: ReinforcementLayersWrapper -) -> List[str]: +) -> list[str]: _tolerance = 0.001 if not new_layers.base_layer.outer_geometry.almost_equals( expected_layers.base_layer.outer_geometry, _tolerance diff --git a/tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py b/tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py index 01efb9dc..1acaa8a1 100644 --- a/tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py +++ b/tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py @@ -1,4 +1,4 @@ -from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_layers_wrapper_builder import ( +from koswat.calculations.reinforcement_layers.outside_slope_reinforcement_layers_wrapper_builder import ( OutsideSlopeReinforcementLayersWrapperBuilder, ) from koswat.dike.layers.layers_wrapper.koswat_layers_wrapper_builder_protocol import ( diff --git a/tests/calculations/test_reinforcement_layers_wrapper.py b/tests/calculations/test_reinforcement_layers_wrapper.py index 591312b0..ea052f0c 100644 --- a/tests/calculations/test_reinforcement_layers_wrapper.py +++ b/tests/calculations/test_reinforcement_layers_wrapper.py @@ -1,7 +1,7 @@ import pytest from shapely.geometry import LineString, Polygon -from koswat.calculations.reinforcement_layers_wrapper import ReinforcementCoatingLayer +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ReinforcementCoatingLayer from koswat.dike.layers.coating_layer.koswat_coating_layer import KoswatCoatingLayer from koswat.dike.material.koswat_material_type import KoswatMaterialType diff --git a/tests/calculations/test_reinforcement_profile_builder_factory.py b/tests/calculations/test_reinforcement_profile_builder_factory.py index 3b440086..b139ecfe 100644 --- a/tests/calculations/test_reinforcement_profile_builder_factory.py +++ b/tests/calculations/test_reinforcement_profile_builder_factory.py @@ -2,7 +2,7 @@ import math from pathlib import Path -from typing import Iterable, List, Type +from typing import Iterable import pytest @@ -13,7 +13,7 @@ from koswat.calculations.outside_slope_reinforcement.cofferdam.cofferdam_input_profile import ( CofferDamInputProfile, ) -from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_layers_wrapper_builder import ( +from koswat.calculations.reinforcement_layers.outside_slope_reinforcement_layers_wrapper_builder import ( OutsideSlopeReinforcementLayersWrapperBuilder, ) from koswat.calculations.outside_slope_reinforcement.outside_slope_reinforcement_profile import ( @@ -41,7 +41,7 @@ from koswat.calculations.standard_reinforcement.stability_wall.stability_wall_input_profile import ( StabilityWallInputProfile, ) -from koswat.calculations.standard_reinforcement.standard_reinforcement_layers_wrapper_builder import ( +from koswat.calculations.reinforcement_layers.standard_reinforcement_layers_wrapper_builder import ( StandardReinforcementLayersWrapperBuilder, ) from koswat.calculations.standard_reinforcement.standard_reinforcement_profile import ( @@ -89,7 +89,7 @@ ) -def scenario_ini_file() -> List[pytest.param]: +def scenario_ini_file() -> list[pytest.param]: scenarios_dir = test_data / "acceptance" / "scenarios" def _to_koswat_scenario( @@ -122,7 +122,7 @@ def _to_pytest_param(scenario: KoswatScenario) -> pytest.param: return list(map(_to_pytest_param, _scenarios)) -def input_profile_data_csv_file() -> List[pytest.param]: +def input_profile_data_csv_file() -> list[pytest.param]: _csv_file = test_data / "acceptance" / "csv" / "dike_input_profiles.csv" def _to_pytest_param(input_profile: KoswatInputProfileBase) -> pytest.param: @@ -187,7 +187,7 @@ def test_get_reinforcement_input_profile_unknown_reinforcement(self): ) def test_get_reinforcement_input_profile( self, - reinforcement_profile_type: Type[ReinforcementProfileProtocol], + reinforcement_profile_type: type[ReinforcementProfileProtocol], expected_input_profile_type: type[SoilInputProfile] | type[PipingWallInputProfile] | type[StabilityWallInputProfile] @@ -227,7 +227,7 @@ def test_get_reinforcement_input_profile( ) def test_get_builder( self, - reinforcement_profile_type: Type[ReinforcementProfileProtocol], + reinforcement_profile_type: type[ReinforcementProfileProtocol], expected_builder: ReinforcementProfileBuilderProtocol, ): _builder = ReinforcementProfileBuilderFactory.get_builder( @@ -369,7 +369,7 @@ def test_given_profile_and_scenario_calculate_new_geometry_without_layers( @pytest.mark.parametrize("scenario", _scenarios) def test_generate_reinforcement_profiles_from_acceptance_data( self, - profile_type: Type[ReinforcementProfileProtocol], + profile_type: type[ReinforcementProfileProtocol], input_profile: KoswatInputProfileProtocol, scenario: KoswatScenario, request: pytest.FixtureRequest, diff --git a/tests/cost_report/profile/test_volume_cost_parameters_builder.py b/tests/cost_report/profile/test_volume_cost_parameters_builder.py index b958ee42..c582b555 100644 --- a/tests/cost_report/profile/test_volume_cost_parameters_builder.py +++ b/tests/cost_report/profile/test_volume_cost_parameters_builder.py @@ -3,8 +3,7 @@ from koswat.calculations.protocols.reinforcement_profile_protocol import ( ReinforcementProfileProtocol, ) -from koswat.calculations.reinforcement_layers_wrapper import ( - ReinforcementBaseLayer, +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( ReinforcementCoatingLayer, ReinforcementLayersWrapper, ) From 783b1848085aacd133c6646acda4ebc457b024ff Mon Sep 17 00:00:00 2001 From: "Carles S. Soriano Perez" Date: Thu, 19 Oct 2023 16:34:32 +0200 Subject: [PATCH 2/5] test: Moved tests into submodules mirroring src directory --- tests/calculations/{soil => reinforcement_layers}/__init__.py | 0 .../test_outside_slope_reinforcement_layers_wrapper_builder.py | 0 .../test_reinforcement_coating_layer.py} | 0 tests/calculations/standard_reinforcement/__init__.py | 0 .../piping_wall/test_piping_wall_input_profile.py | 0 .../piping_wall/test_piping_wall_reinforcement_profile.py | 0 .../test_piping_wall_reinforcement_profile_calculation.py | 0 tests/calculations/standard_reinforcement/soil/__init__.py | 0 .../soil/test_soil_reinforcement_profile.py | 0 .../soil/test_soil_reinforcement_profile_calculation.py | 0 .../stability_wall/test_stability_wall_input_profile.py | 0 .../stability_wall/test_stability_wall_reinforcement_profile.py | 0 .../test_stability_wall_reinforcement_profile_calculation.py | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename tests/calculations/{soil => reinforcement_layers}/__init__.py (100%) rename tests/calculations/{oustide_slope_reinforcement => reinforcement_layers}/test_outside_slope_reinforcement_layers_wrapper_builder.py (100%) rename tests/calculations/{test_reinforcement_layers_wrapper.py => reinforcement_layers/test_reinforcement_coating_layer.py} (100%) create mode 100644 tests/calculations/standard_reinforcement/__init__.py rename tests/calculations/{ => standard_reinforcement}/piping_wall/test_piping_wall_input_profile.py (100%) rename tests/calculations/{ => standard_reinforcement}/piping_wall/test_piping_wall_reinforcement_profile.py (100%) rename tests/calculations/{ => standard_reinforcement}/piping_wall/test_piping_wall_reinforcement_profile_calculation.py (100%) create mode 100644 tests/calculations/standard_reinforcement/soil/__init__.py rename tests/calculations/{ => standard_reinforcement}/soil/test_soil_reinforcement_profile.py (100%) rename tests/calculations/{ => standard_reinforcement}/soil/test_soil_reinforcement_profile_calculation.py (100%) rename tests/calculations/{ => standard_reinforcement}/stability_wall/test_stability_wall_input_profile.py (100%) rename tests/calculations/{ => standard_reinforcement}/stability_wall/test_stability_wall_reinforcement_profile.py (100%) rename tests/calculations/{ => standard_reinforcement}/stability_wall/test_stability_wall_reinforcement_profile_calculation.py (100%) diff --git a/tests/calculations/soil/__init__.py b/tests/calculations/reinforcement_layers/__init__.py similarity index 100% rename from tests/calculations/soil/__init__.py rename to tests/calculations/reinforcement_layers/__init__.py diff --git a/tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py b/tests/calculations/reinforcement_layers/test_outside_slope_reinforcement_layers_wrapper_builder.py similarity index 100% rename from tests/calculations/oustide_slope_reinforcement/test_outside_slope_reinforcement_layers_wrapper_builder.py rename to tests/calculations/reinforcement_layers/test_outside_slope_reinforcement_layers_wrapper_builder.py diff --git a/tests/calculations/test_reinforcement_layers_wrapper.py b/tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py similarity index 100% rename from tests/calculations/test_reinforcement_layers_wrapper.py rename to tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py diff --git a/tests/calculations/standard_reinforcement/__init__.py b/tests/calculations/standard_reinforcement/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/calculations/piping_wall/test_piping_wall_input_profile.py b/tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_input_profile.py similarity index 100% rename from tests/calculations/piping_wall/test_piping_wall_input_profile.py rename to tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_input_profile.py diff --git a/tests/calculations/piping_wall/test_piping_wall_reinforcement_profile.py b/tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_reinforcement_profile.py similarity index 100% rename from tests/calculations/piping_wall/test_piping_wall_reinforcement_profile.py rename to tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_reinforcement_profile.py diff --git a/tests/calculations/piping_wall/test_piping_wall_reinforcement_profile_calculation.py b/tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_reinforcement_profile_calculation.py similarity index 100% rename from tests/calculations/piping_wall/test_piping_wall_reinforcement_profile_calculation.py rename to tests/calculations/standard_reinforcement/piping_wall/test_piping_wall_reinforcement_profile_calculation.py diff --git a/tests/calculations/standard_reinforcement/soil/__init__.py b/tests/calculations/standard_reinforcement/soil/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/calculations/soil/test_soil_reinforcement_profile.py b/tests/calculations/standard_reinforcement/soil/test_soil_reinforcement_profile.py similarity index 100% rename from tests/calculations/soil/test_soil_reinforcement_profile.py rename to tests/calculations/standard_reinforcement/soil/test_soil_reinforcement_profile.py diff --git a/tests/calculations/soil/test_soil_reinforcement_profile_calculation.py b/tests/calculations/standard_reinforcement/soil/test_soil_reinforcement_profile_calculation.py similarity index 100% rename from tests/calculations/soil/test_soil_reinforcement_profile_calculation.py rename to tests/calculations/standard_reinforcement/soil/test_soil_reinforcement_profile_calculation.py diff --git a/tests/calculations/stability_wall/test_stability_wall_input_profile.py b/tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_input_profile.py similarity index 100% rename from tests/calculations/stability_wall/test_stability_wall_input_profile.py rename to tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_input_profile.py diff --git a/tests/calculations/stability_wall/test_stability_wall_reinforcement_profile.py b/tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_reinforcement_profile.py similarity index 100% rename from tests/calculations/stability_wall/test_stability_wall_reinforcement_profile.py rename to tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_reinforcement_profile.py diff --git a/tests/calculations/stability_wall/test_stability_wall_reinforcement_profile_calculation.py b/tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_reinforcement_profile_calculation.py similarity index 100% rename from tests/calculations/stability_wall/test_stability_wall_reinforcement_profile_calculation.py rename to tests/calculations/standard_reinforcement/stability_wall/test_stability_wall_reinforcement_profile_calculation.py From 0f51a305e55f2478442963ea6d016dd67cd280d1 Mon Sep 17 00:00:00 2001 From: "Carles S. Soriano Perez" Date: Thu, 19 Oct 2023 16:38:20 +0200 Subject: [PATCH 3/5] docs: Updated documentation --- .../calculations/reinforcement_layers.md | 11 +++++++++++ .../calculations/reinforcement_layers_wrapper.md | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 docs/reference/koswat_docstrings/calculations/reinforcement_layers.md delete mode 100644 docs/reference/koswat_docstrings/calculations/reinforcement_layers_wrapper.md diff --git a/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md new file mode 100644 index 00000000..b1d685c9 --- /dev/null +++ b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md @@ -0,0 +1,11 @@ +# Reinforcement Layers Wrapper + +::: koswat.calculations.reinforcement_layers.reinforcement_layer_protocol +::: koswat.calculations.reinforcement_layers.reinforcement_base_layer +::: koswat.calculations.reinforcement_layers.reinforcement_coating_layer +::: koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper + +# Reinforcement Layers Wrapper builders + +::: koswat.calculations.reinforcement_layers.outside_slop_reinforcement_layers_wrapper_builder +::: koswat.calculations.reinforcement_layers.standard_reinforcement_layers_wrapper_builder diff --git a/docs/reference/koswat_docstrings/calculations/reinforcement_layers_wrapper.md b/docs/reference/koswat_docstrings/calculations/reinforcement_layers_wrapper.md deleted file mode 100644 index dbad20d7..00000000 --- a/docs/reference/koswat_docstrings/calculations/reinforcement_layers_wrapper.md +++ /dev/null @@ -1,2 +0,0 @@ -# Reinforcement Layers Wrapper -::: koswat.calculations.reinforcement_layers_wrapper From 90f4cada3f31c37ebe91b05b63f76ac6198c56fe Mon Sep 17 00:00:00 2001 From: "Carles S. Soriano Perez" Date: Thu, 19 Oct 2023 17:08:21 +0200 Subject: [PATCH 4/5] chore: Refactored imports and updated documentation --- .../koswat_docstrings/calculations/protocols.md | 1 + .../calculations/reinforcement_layers.md | 1 - koswat/calculations/README.md | 15 +++++++++++---- koswat/calculations/protocols/README.md | 4 +++- koswat/calculations/protocols/__init__.py | 3 +++ ..._slope_reinforcement_layers_wrapper_builder.py | 11 ++++++++--- .../reinforcement_coating_layer.py | 6 ++++-- .../reinforcement_layers_wrapper.py | 8 +++----- koswat/cost_report/profile/layer_cost_report.py | 2 +- koswat/plots/dike/koswat_layer_plot.py | 6 +++--- .../test_reinforcement_coating_layer.py | 6 ++++-- 11 files changed, 41 insertions(+), 22 deletions(-) diff --git a/docs/reference/koswat_docstrings/calculations/protocols.md b/docs/reference/koswat_docstrings/calculations/protocols.md index 5144cdb2..0f69b581 100644 --- a/docs/reference/koswat_docstrings/calculations/protocols.md +++ b/docs/reference/koswat_docstrings/calculations/protocols.md @@ -4,3 +4,4 @@ ::: koswat.calculations.protocols.reinforcement_profile_builder_protocol ::: koswat.calculations.protocols.reinforcement_profile_calculation_protocol ::: koswat.calculations.protocols.reinforcement_profile_protocol +::: koswat.calculations.reinforcement_layers.reinforcement_layer_protocol diff --git a/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md index b1d685c9..91efd028 100644 --- a/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md +++ b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md @@ -1,6 +1,5 @@ # Reinforcement Layers Wrapper -::: koswat.calculations.reinforcement_layers.reinforcement_layer_protocol ::: koswat.calculations.reinforcement_layers.reinforcement_base_layer ::: koswat.calculations.reinforcement_layers.reinforcement_coating_layer ::: koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper diff --git a/koswat/calculations/README.md b/koswat/calculations/README.md index 5e678da2..053352bc 100644 --- a/koswat/calculations/README.md +++ b/koswat/calculations/README.md @@ -4,15 +4,22 @@ This module contains the information on calculating a reinforcement (`Reinforcem The module is divided as: - __io__: Input / output module containing the concrete importers and exporters for the models here defined. -- __outside_slope_reinforcement__: Module containing the definition of all `OutsideSlopeReinforcementProfile` implementations. -- __standard_reinforcement__: Module containing the definition of all `StandardReinforcementProfile` implementations. +- __reinforcement_layers__: Module containing the definition of all `ReinforcementLayerProtocol` implementations and their builders. +- __outside_slope_reinforcement__: Module containing the definition of all `OutsideSlopeReinforcementProfile` implementations and their builders. +- __standard_reinforcement__: Module containing the definition of all `StandardReinforcementProfile` implementations and their builders. - __protocols__: Module where the `typing.Protocol` concrete definitions used across the whole calculation modules are saved. At the same time we expose directly the -- `ReinforcementLayersWrapper`: Concrete implementation of `KoswatLayersWrapperProtocol` which uses `ReinforcementBaseLayer` and `ReinforcementCoatingLayer` instead (both from instances of `ReinforcementLayerProtocol`). - `ReinforcementProfileBuilderFactory`: Factory to retrieve the correct instances of a `ReinforcementProfileBuilderProtocol`. ## Design decisions. It could be argued that some of the code could be reduced by using abstractions or simple inheritance. However I opted for 'duplicating' methods logic in order to reduce the dependency between classes thus making them totally independent. Alas the usage of protocols over abstractions. -A reinforcement calculation will naturally be found in its respective `*_profile_calculation.py` file. This way we isolate the logic to get each one of the values that compose a specific reinforcement profile, allowing us for better maintainability and verification. \ No newline at end of file +A reinforcement calculation will naturally be found in its respective `*_profile_calculation.py` file. This way we isolate the logic to get each one of the values that compose a specific reinforcement profile, allowing us for better maintainability and verification. + +## Future work. +After a few iterations of adding / modifying how a reinforcement is calculated, it is preferred to refactor the process by splitting the process into two steps: +1. Calculate the new reinforced profile. +2. Calculate the added / removed / reused materials based on the geometries / layers of point 1. + +This work implies the introduction and modification of existing `ReinforcementProfileProtocol` classes, as well as how the builders in the `reinforcement_layers` module function, because they will no longer require to calculate "on the fly" geometries related to added / removed / reused material. \ No newline at end of file diff --git a/koswat/calculations/protocols/README.md b/koswat/calculations/protocols/README.md index bcf20d89..fc99a289 100644 --- a/koswat/calculations/protocols/README.md +++ b/koswat/calculations/protocols/README.md @@ -1,5 +1,5 @@ # Calculations protocols -The following protocols can be found here: +The following protocols __regarding creation of input profiles__ can be found here: - `ReinforcementInputProfileProtocol`: An extension of `KoswatInputProfileProtocol`. - `ReinforcementProfileCalculationProtocol`: Extension of the `BuilderProtocol` to define the required calculations that will return the input data required to create a `ReinforcementInputProfileProtocol`. @@ -7,3 +7,5 @@ The following protocols can be found here: - `ReinforcementProfileProtocol`: An extension of `KoswatProfileProtocol` which uses `ReinforcementLayersWrapper` instead. - `ReinforcementProfileBuilderProtocol`: Extension of the `BuilderProtocol` to specify the required data needed to generate a `ReinforcementProfileProtocol`. + +How to define "layers" is specified in the `koswat.calculations.reinforcement_layers` module. \ No newline at end of file diff --git a/koswat/calculations/protocols/__init__.py b/koswat/calculations/protocols/__init__.py index 9ee4c84c..62273f7c 100644 --- a/koswat/calculations/protocols/__init__.py +++ b/koswat/calculations/protocols/__init__.py @@ -10,3 +10,6 @@ from koswat.calculations.protocols.reinforcement_profile_protocol import ( ReinforcementProfileProtocol, ) + +# NOTE! ReinforcementLayerProtocol is not included here due to a circular dependency +# created with all the protocols declared on this module and ReinforcementLayersWrapper. diff --git a/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py b/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py index c0cd924a..b2a57c2f 100644 --- a/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py +++ b/koswat/calculations/reinforcement_layers/outside_slope_reinforcement_layers_wrapper_builder.py @@ -1,9 +1,14 @@ from shapely.geometry import Point, Polygon - -from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) +from koswat.calculations.reinforcement_layers.reinforcement_base_layer import ( ReinforcementBaseLayer, +) +from koswat.calculations.reinforcement_layers.reinforcement_coating_layer import ( ReinforcementCoatingLayer, - ReinforcementLayerProtocol, +) +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( ReinforcementLayersWrapper, ) from koswat.core.geometries.calc_library import get_polygon_surface_points diff --git a/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py b/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py index bf1cebb8..47be0ba5 100644 --- a/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py +++ b/koswat/calculations/reinforcement_layers/reinforcement_coating_layer.py @@ -2,12 +2,15 @@ from shapely.geometry import LineString, Polygon, MultiPolygon -from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ReinforcementLayerProtocol +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) from koswat.core.geometries.calc_library import get_polygon_coordinates from koswat.dike.layers.coating_layer import KoswatCoatingLayer from koswat.dike.material.koswat_material_type import KoswatMaterialType + class ReinforcementCoatingLayer(ReinforcementLayerProtocol): material_type: KoswatMaterialType outer_geometry: Polygon @@ -66,4 +69,3 @@ def with_same_outer_geometry( _reinforced_coating_layer.new_layer_geometry = Polygon() _reinforced_coating_layer.new_layer_surface = LineString() return _reinforced_coating_layer - diff --git a/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py b/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py index 1e51ebec..22ab116f 100644 --- a/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py +++ b/koswat/calculations/reinforcement_layers/reinforcement_layers_wrapper.py @@ -1,14 +1,12 @@ +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) from koswat.calculations.reinforcement_layers.reinforcement_base_layer import ( ReinforcementBaseLayer, ) from koswat.calculations.reinforcement_layers.reinforcement_coating_layer import ( ReinforcementCoatingLayer, ) -from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( - ReinforcementLayerProtocol, -) - - from koswat.dike.layers.layers_wrapper import KoswatLayersWrapperProtocol from koswat.dike.material.koswat_material_type import KoswatMaterialType diff --git a/koswat/cost_report/profile/layer_cost_report.py b/koswat/cost_report/profile/layer_cost_report.py index 8fac2f4e..b131a080 100644 --- a/koswat/cost_report/profile/layer_cost_report.py +++ b/koswat/cost_report/profile/layer_cost_report.py @@ -2,7 +2,7 @@ import math -from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( ReinforcementLayerProtocol, ) from koswat.cost_report.cost_report_protocol import CostReportProtocol diff --git a/koswat/plots/dike/koswat_layer_plot.py b/koswat/plots/dike/koswat_layer_plot.py index ac19f549..6dec9268 100644 --- a/koswat/plots/dike/koswat_layer_plot.py +++ b/koswat/plots/dike/koswat_layer_plot.py @@ -5,6 +5,9 @@ from koswat.plots.koswat_plot_protocol import KoswatPlotProtocol from shapely import geometry from numpy import concatenate +from koswat.calculations.reinforcement_layers.reinforcement_layer_protocol import ( + ReinforcementLayerProtocol, +) class KoswatLayerPlot(KoswatPlotProtocol): @@ -36,9 +39,6 @@ def plot(self, color: str) -> None: self.subplot.plot(_x_coords, y_coords, **dict_values) _x_points, _y_points = list(zip(*self.koswat_object.upper_points.coords)) self.subplot.scatter(_x_points, _y_points) - from koswat.calculations.reinforcement_layers_wrapper import ( - ReinforcementLayerProtocol, - ) if isinstance(self.koswat_object, ReinforcementLayerProtocol): if isinstance(self.koswat_object.new_layer_surface, geometry.Polygon): diff --git a/tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py b/tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py index ea052f0c..78d91899 100644 --- a/tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py +++ b/tests/calculations/reinforcement_layers/test_reinforcement_coating_layer.py @@ -1,12 +1,14 @@ import pytest from shapely.geometry import LineString, Polygon -from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ReinforcementCoatingLayer +from koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper import ( + ReinforcementCoatingLayer, +) from koswat.dike.layers.coating_layer.koswat_coating_layer import KoswatCoatingLayer from koswat.dike.material.koswat_material_type import KoswatMaterialType -class TestReinforcementLayersWrapper: +class TestReinforcementCoatingLayer: @pytest.fixture def dummy_coating_layer(self) -> KoswatCoatingLayer: _test_coating_layer = KoswatCoatingLayer() From 954b14575e206e56699a767fa4572f7de540f488 Mon Sep 17 00:00:00 2001 From: "Carles S. Soriano Perez" Date: Thu, 19 Oct 2023 17:18:47 +0200 Subject: [PATCH 5/5] docs: Fixed documentation --- docs/reference/koswat_docstrings/calculations/protocols.md | 1 - .../koswat_docstrings/calculations/reinforcement_layers.md | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/koswat_docstrings/calculations/protocols.md b/docs/reference/koswat_docstrings/calculations/protocols.md index 0f69b581..5144cdb2 100644 --- a/docs/reference/koswat_docstrings/calculations/protocols.md +++ b/docs/reference/koswat_docstrings/calculations/protocols.md @@ -4,4 +4,3 @@ ::: koswat.calculations.protocols.reinforcement_profile_builder_protocol ::: koswat.calculations.protocols.reinforcement_profile_calculation_protocol ::: koswat.calculations.protocols.reinforcement_profile_protocol -::: koswat.calculations.reinforcement_layers.reinforcement_layer_protocol diff --git a/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md index 91efd028..025bb95e 100644 --- a/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md +++ b/docs/reference/koswat_docstrings/calculations/reinforcement_layers.md @@ -1,10 +1,11 @@ # Reinforcement Layers Wrapper +::: koswat.calculations.reinforcement_layers.reinforcement_layer_protocol ::: koswat.calculations.reinforcement_layers.reinforcement_base_layer ::: koswat.calculations.reinforcement_layers.reinforcement_coating_layer ::: koswat.calculations.reinforcement_layers.reinforcement_layers_wrapper # Reinforcement Layers Wrapper builders -::: koswat.calculations.reinforcement_layers.outside_slop_reinforcement_layers_wrapper_builder +::: koswat.calculations.reinforcement_layers.outside_slope_reinforcement_layers_wrapper_builder ::: koswat.calculations.reinforcement_layers.standard_reinforcement_layers_wrapper_builder