diff --git a/backend/condition/domain/mapping/lbwf_mapper.py b/backend/condition/domain/mapping/lbwf_mapper.py index 63434240..bc44e4c3 100644 --- a/backend/condition/domain/mapping/lbwf_mapper.py +++ b/backend/condition/domain/mapping/lbwf_mapper.py @@ -12,7 +12,7 @@ logger = setup_logger() class LbwfMapper(Mapper): - def map_asset_conditions_for_property(self, client_data: Any) -> List[AssetCondition]: + def map_asset_conditions_for_property(self, client_data: Any, survey_year: Optional[int]) -> List[AssetCondition]: assert isinstance(client_data, LbwfHouse) # TODO: think of a better way to do this mapped_assets: List[AssetCondition] = [] @@ -32,7 +32,7 @@ class LbwfMapper(Mapper): element=element, condition_description=raw_asset.attribute_code_description, quantity=raw_asset.quantity, - renewal_year=LbwfMapper._calculate_renewal_year(raw_asset), + renewal_year=LbwfMapper._calculate_renewal_year(raw_asset, survey_year), source=raw_asset.element_comments, ) ) @@ -46,13 +46,15 @@ class LbwfMapper(Mapper): return Element[lbwf_element_code] @staticmethod - def _calculate_renewal_year(lbwf_asset: LbwfAssetCondition) -> Optional[int]: + def _calculate_renewal_year(lbwf_asset: LbwfAssetCondition, survey_year: Optional[int]) -> Optional[int]: remaining_life_years: Optional[int] = lbwf_asset.remaining_life if not remaining_life_years: return None + if not survey_year: + return None + try: - survey_year: int = datetime.now().year # TODO: get survey year from filename or elsewhere return survey_year + remaining_life_years except: logger.debug(f"Unable to map LBWF Asset remaining life {remaining_life_years} to renewal year, returning None") diff --git a/backend/condition/domain/mapping/mapper.py b/backend/condition/domain/mapping/mapper.py index f08fa4e1..4e51d46b 100644 --- a/backend/condition/domain/mapping/mapper.py +++ b/backend/condition/domain/mapping/mapper.py @@ -1,11 +1,11 @@ from abc import ABC, abstractmethod -from typing import Any, List +from typing import Any, List, Optional from backend.condition.domain.asset_condition import AssetCondition class Mapper(ABC): @abstractmethod - def map_asset_conditions_for_property(self, client_data: Any) -> List[AssetCondition]: + def map_asset_conditions_for_property(self, client_data: Any, survey_year: Optional[int]) -> List[AssetCondition]: #TODO: client_data should be properly typed pass \ No newline at end of file diff --git a/backend/condition/processor.py b/backend/condition/processor.py index 4f379b23..cc44e38a 100644 --- a/backend/condition/processor.py +++ b/backend/condition/processor.py @@ -1,4 +1,5 @@ from typing import Any, BinaryIO, List +from datetime import datetime from backend.condition.domain.asset_condition import AssetCondition from backend.condition.domain.mapping.mapper import Mapper @@ -18,8 +19,10 @@ def process_file(file_stream: BinaryIO, source_key: str) -> None: # Orchestration raw_properties: List[Any] = parser.parse(file_stream) + survey_year = datetime.now().year # TODO: get this from filepath or elsewhere + assets: List[AssetCondition] = [] for p in raw_properties: - assets.extend(mapper.map_asset_conditions_for_property(p)) + assets.extend(mapper.map_asset_conditions_for_property(p, survey_year)) print(assets) # temp \ No newline at end of file diff --git a/backend/condition/tests/mapping/test_lbwf_mapper.py b/backend/condition/tests/mapping/test_lbwf_mapper.py index 3e066d27..926e34c1 100644 --- a/backend/condition/tests/mapping/test_lbwf_mapper.py +++ b/backend/condition/tests/mapping/test_lbwf_mapper.py @@ -170,7 +170,7 @@ def test_lbwf_mapper_maps_house(): ) mapper = LbwfMapper() - current_year = 2026 + survey_year = 2026 expected_assets: List[AssetCondition] = [ AssetCondition( @@ -233,7 +233,7 @@ def test_lbwf_mapper_maps_house(): ] # act - actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property(lbwf_house) + actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property(lbwf_house, survey_year) # assert assert actual_assets == expected_assets \ No newline at end of file