mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Pass survey year to mapper rather than using today's year
This commit is contained in:
parent
25923cbc9f
commit
dfe0460155
4 changed files with 14 additions and 9 deletions
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue