mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +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):
|
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
|
assert isinstance(client_data, LbwfHouse) # TODO: think of a better way to do this
|
||||||
|
|
||||||
mapped_assets: List[AssetCondition] = []
|
mapped_assets: List[AssetCondition] = []
|
||||||
|
|
@ -32,7 +32,7 @@ class LbwfMapper(Mapper):
|
||||||
element=element,
|
element=element,
|
||||||
condition_description=raw_asset.attribute_code_description,
|
condition_description=raw_asset.attribute_code_description,
|
||||||
quantity=raw_asset.quantity,
|
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,
|
source=raw_asset.element_comments,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
@ -46,13 +46,15 @@ class LbwfMapper(Mapper):
|
||||||
return Element[lbwf_element_code]
|
return Element[lbwf_element_code]
|
||||||
|
|
||||||
@staticmethod
|
@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
|
remaining_life_years: Optional[int] = lbwf_asset.remaining_life
|
||||||
if not remaining_life_years:
|
if not remaining_life_years:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
if not survey_year:
|
||||||
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
survey_year: int = datetime.now().year # TODO: get survey year from filename or elsewhere
|
|
||||||
return survey_year + remaining_life_years
|
return survey_year + remaining_life_years
|
||||||
except:
|
except:
|
||||||
logger.debug(f"Unable to map LBWF Asset remaining life {remaining_life_years} to renewal year, returning None")
|
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 abc import ABC, abstractmethod
|
||||||
from typing import Any, List
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
from backend.condition.domain.asset_condition import AssetCondition
|
||||||
|
|
||||||
class Mapper(ABC):
|
class Mapper(ABC):
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
#TODO: client_data should be properly typed
|
||||||
pass
|
pass
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from typing import Any, BinaryIO, List
|
from typing import Any, BinaryIO, List
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
from backend.condition.domain.asset_condition import AssetCondition
|
||||||
from backend.condition.domain.mapping.mapper import Mapper
|
from backend.condition.domain.mapping.mapper import Mapper
|
||||||
|
|
@ -18,8 +19,10 @@ def process_file(file_stream: BinaryIO, source_key: str) -> None:
|
||||||
# Orchestration
|
# Orchestration
|
||||||
raw_properties: List[Any] = parser.parse(file_stream)
|
raw_properties: List[Any] = parser.parse(file_stream)
|
||||||
|
|
||||||
|
survey_year = datetime.now().year # TODO: get this from filepath or elsewhere
|
||||||
|
|
||||||
assets: List[AssetCondition] = []
|
assets: List[AssetCondition] = []
|
||||||
for p in raw_properties:
|
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
|
print(assets) # temp
|
||||||
|
|
@ -170,7 +170,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
)
|
)
|
||||||
mapper = LbwfMapper()
|
mapper = LbwfMapper()
|
||||||
|
|
||||||
current_year = 2026
|
survey_year = 2026
|
||||||
|
|
||||||
expected_assets: List[AssetCondition] = [
|
expected_assets: List[AssetCondition] = [
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
|
|
@ -233,7 +233,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
]
|
]
|
||||||
|
|
||||||
# act
|
# 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
|
||||||
assert actual_assets == expected_assets
|
assert actual_assets == expected_assets
|
||||||
Loading…
Add table
Reference in a new issue