From 28dd4eaf0c8029f9fe2fc97dd779f318d8e9c16d Mon Sep 17 00:00:00 2001 From: Ardt Klapwijk Date: Wed, 13 Nov 2024 12:38:50 +0100 Subject: [PATCH] chore: use costs_with_surtax in infra strategy --- .../koswat_summary_location_matrix_builder.py | 4 +--- koswat/strategies/strategy_location_input.py | 11 +++++++---- .../strategies/strategy_location_reinforcement.py | 4 ++-- koswat/strategies/strategy_reinforcement_input.py | 1 - .../strategy_reinforcement_type_costs.py | 10 +++++----- tests/strategies/conftest.py | 10 +++++++--- .../test_infra_priority_strategy.py | 15 ++++++++++----- 7 files changed, 32 insertions(+), 23 deletions(-) diff --git a/koswat/cost_report/summary/koswat_summary_location_matrix_builder.py b/koswat/cost_report/summary/koswat_summary_location_matrix_builder.py index 2a07da89..94843240 100644 --- a/koswat/cost_report/summary/koswat_summary_location_matrix_builder.py +++ b/koswat/cost_report/summary/koswat_summary_location_matrix_builder.py @@ -39,7 +39,6 @@ def create_strategy_location_reinforcement_costs(): reinforcement_type=type( locations_profile.profile_cost_report.reinforced_profile ), - base_costs=locations_profile.profile_cost_report.total_cost, base_costs_with_surtax=locations_profile.profile_cost_report.total_cost_with_surtax, ) @@ -85,8 +84,7 @@ def get_reinforcement( ) return StrategyReinforcementInput( reinforcement_type=reinforcement_cost.reinforcement_type, - base_costs=reinforcement_cost.base_costs, - base_costs_with_surtax=reinforcement_cost.base_costs, + base_costs_with_surtax=reinforcement_cost.base_costs_with_surtax, ground_level_surface=_reinforcement.new_ground_level_surface, ) diff --git a/koswat/strategies/strategy_location_input.py b/koswat/strategies/strategy_location_input.py index b3d4a3ef..d45d0022 100644 --- a/koswat/strategies/strategy_location_input.py +++ b/koswat/strategies/strategy_location_input.py @@ -19,12 +19,15 @@ class StrategyLocationInput: @property def cheapest_reinforcement(self) -> StrategyReinforcementTypeCosts: """ - Gets the `StrategyLocationReinforcementCosts` with the lowest `total_costs` value. + Gets the `StrategyLocationReinforcementCosts` with the lowest `total_costs_with_surtax` value. Returns: StrategyLocationReinforcementCosts: The cheapest reinforcement for this location. """ - return min(self.strategy_reinforcement_type_costs, key=lambda x: x.total_costs) + return min( + self.strategy_reinforcement_type_costs, + key=lambda x: x.total_costs_with_surtax, + ) @property def available_measures(self) -> list[type[ReinforcementProfileProtocol]]: @@ -53,11 +56,11 @@ def get_reinforcement_costs( ValueError: The reinforcement type is not available. Returns: - float: The reinforcement costs. + float: The reinforcement costs with surtax. """ for _srtc in self.strategy_reinforcement_type_costs: if _srtc.reinforcement_type == reinforcement_type: - return _srtc.total_costs + return _srtc.total_costs_with_surtax raise ValueError( f"Reinforcement {reinforcement_type.output_name} not available, costs cannot be computed." ) diff --git a/koswat/strategies/strategy_location_reinforcement.py b/koswat/strategies/strategy_location_reinforcement.py index 3aa7c227..1d59898d 100644 --- a/koswat/strategies/strategy_location_reinforcement.py +++ b/koswat/strategies/strategy_location_reinforcement.py @@ -57,13 +57,13 @@ def current_selected_measure(self) -> type[ReinforcementProfileProtocol]: @property def current_cost(self) -> float: """ - Estimates the costs at this location for the given `current_selected_measure`. + Estimates the costs with surtax at this location for the given `current_selected_measure`. """ if not self.current_selected_measure or not self.strategy_location_input: return 0.0 for _srtc in self.strategy_location_input.strategy_reinforcement_type_costs: if _srtc.reinforcement_type == self.current_selected_measure: - return _srtc.total_costs + return _srtc.total_costs_with_surtax return 0.0 @property diff --git a/koswat/strategies/strategy_reinforcement_input.py b/koswat/strategies/strategy_reinforcement_input.py index d9ef2a5c..1c70612d 100644 --- a/koswat/strategies/strategy_reinforcement_input.py +++ b/koswat/strategies/strategy_reinforcement_input.py @@ -8,6 +8,5 @@ @dataclass class StrategyReinforcementInput: reinforcement_type: type[ReinforcementProfileProtocol] - base_costs: float = 0.0 base_costs_with_surtax: float = 0.0 ground_level_surface: float = 0.0 diff --git a/koswat/strategies/strategy_reinforcement_type_costs.py b/koswat/strategies/strategy_reinforcement_type_costs.py index b28aa13f..fd754ff4 100644 --- a/koswat/strategies/strategy_reinforcement_type_costs.py +++ b/koswat/strategies/strategy_reinforcement_type_costs.py @@ -8,17 +8,17 @@ @dataclass class StrategyReinforcementTypeCosts: reinforcement_type: type[ReinforcementProfileProtocol] - base_costs: float = 0.0 base_costs_with_surtax: float = 0.0 infrastructure_costs: float = 0.0 infrastructure_costs_with_surtax: float = 0.0 @property - def total_costs(self) -> float: + def total_costs_with_surtax(self) -> float: """ The simple addition of the base costs and the possible - related infrastructure costs. + related infrastructure costs, both including surtax. + Returns: - float: The total costs when applying this reinforcement. + float: The total costs with surtax when applying this reinforcement. """ - return self.base_costs + self.infrastructure_costs + return self.base_costs_with_surtax + self.infrastructure_costs_with_surtax diff --git a/tests/strategies/conftest.py b/tests/strategies/conftest.py index 744172d7..84dce0c2 100644 --- a/tests/strategies/conftest.py +++ b/tests/strategies/conftest.py @@ -44,10 +44,13 @@ def _get_example_strategy_input() -> Iterator[StrategyInput]: _levels_data = [ StrategyReinforcementTypeCosts( reinforcement_type=_reinforcement, - base_costs=(10**_idx) * 42.0, base_costs_with_surtax=(10**_idx) * 42.0 * 2, infrastructure_costs=(10 ** (len(_reinforcement_type_default_order) - 1)) - * 42.0 + * 42.0, + infrastructure_costs_with_surtax=( + 10 ** (len(_reinforcement_type_default_order) - 1) + ) + * 84.0 if _idx in [0, 1, 3] else 0.0, # Dramatic infra costs so they move to where we want ) @@ -69,7 +72,6 @@ def _get_example_strategy_input() -> Iterator[StrategyInput]: _strategy_reinforcements = [ StrategyReinforcementInput( reinforcement_type=_rtc.reinforcement_type, - base_costs=_rtc.base_costs, base_costs_with_surtax=_rtc.base_costs_with_surtax, ground_level_surface=10.0 * (len(_reinforcement_type_default_order) - _idx), ) @@ -157,6 +159,7 @@ def _get_example_location_reinforcements_with_selected_subclustering( for _sl in example_strategy_input.strategy_locations: for _cost in _sl.strategy_reinforcement_type_costs: _cost.infrastructure_costs = 0 + _cost.infrastructure_costs_with_surtax = 0 def modify_costs_to( location: StrategyLocationInput, @@ -173,6 +176,7 @@ def modify_costs_to( _costs.infrastructure_costs = ( 10 ** len(_reinforcement_type_default_order) ) * 42 + _costs.infrastructure_costs_with_surtax = _costs.infrastructure_costs * 2 # We force the first cluster from index 0 to index 2 modify_costs_to(example_strategy_input.strategy_locations[0], 2) diff --git a/tests/strategies/infra_priority_stratregy/test_infra_priority_strategy.py b/tests/strategies/infra_priority_stratregy/test_infra_priority_strategy.py index eb78d31f..f1485abf 100644 --- a/tests/strategies/infra_priority_stratregy/test_infra_priority_strategy.py +++ b/tests/strategies/infra_priority_stratregy/test_infra_priority_strategy.py @@ -171,31 +171,36 @@ def _get_infra_cluster_for_subclusters_fixture(self) -> Iterator[InfraCluster]: strategy_reinforcement_type_costs=[ StrategyReinforcementTypeCosts( SoilReinforcementProfile, - base_costs=42, + base_costs_with_surtax=42, infrastructure_costs=420000, + infrastructure_costs_with_surtax=420000, ), StrategyReinforcementTypeCosts( PipingWallReinforcementProfile, - base_costs=4200, + base_costs_with_surtax=4200, infrastructure_costs=420, + infrastructure_costs_with_surtax=420, ), # Costs are too big, it won't be considered StrategyReinforcementTypeCosts( VPSReinforcementProfile, - base_costs=42000000, + base_costs_with_surtax=42000000, infrastructure_costs=4200000, + infrastructure_costs_with_surtax=4200000, ), # Not present at all locations. StrategyReinforcementTypeCosts( StabilityWallReinforcementProfile, - base_costs=42, + base_costs_with_surtax=42, infrastructure_costs=42, + infrastructure_costs_with_surtax=42, ), # Cheapest of all, but only present at one location. StrategyReinforcementTypeCosts( CofferdamReinforcementProfile, - base_costs=42, + base_costs_with_surtax=42, infrastructure_costs=0, + infrastructure_costs_with_surtax=0, ), ], )