mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Map LbwfHouse to AssetCondition list 🟩
This commit is contained in:
parent
c8abc19e59
commit
fc08a7df4f
3 changed files with 50 additions and 6 deletions
|
|
@ -1,15 +1,59 @@
|
|||
from typing import Any, List, Optional
|
||||
from datetime import datetime, date
|
||||
|
||||
from backend.condition.domain.asset_condition import AssetCondition
|
||||
from backend.condition.domain.element import Element
|
||||
from backend.condition.domain.mapping.mapper import Mapper
|
||||
from backend.condition.parsing.records.lbwf.lbwf_asset_condition import LbwfAssetCondition
|
||||
from backend.condition.parsing.records.lbwf.lbwf_house import LbwfHouse
|
||||
from utils.logger import setup_logger
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
class LbwfMapper(Mapper):
|
||||
|
||||
def map_asset_conditions(self, client_data: List[Any]) -> List[AssetCondition]:
|
||||
raise NotImplementedError
|
||||
def map_asset_conditions_for_property(self, client_data: Any) -> List[AssetCondition]:
|
||||
assert isinstance(client_data, LbwfHouse) # TODO: think of a better way to do this
|
||||
|
||||
mapped_assets: List[AssetCondition] = []
|
||||
|
||||
uprn: int = client_data.uprn
|
||||
for raw_asset in client_data.assets:
|
||||
try:
|
||||
element: Element = LbwfMapper._map_element(raw_asset.element_code)
|
||||
except:
|
||||
logger.warning(f"Unrecognised LBWF Asset Element Code: {raw_asset.element_code}. Skipping record")
|
||||
continue
|
||||
|
||||
|
||||
mapped_assets.append(
|
||||
AssetCondition(
|
||||
uprn=uprn,
|
||||
element=element,
|
||||
condition_description=raw_asset.attribute_code_description,
|
||||
quantity=raw_asset.quantity,
|
||||
renewal_year=LbwfMapper._calculate_renewal_year(raw_asset),
|
||||
source=raw_asset.element_comments,
|
||||
)
|
||||
)
|
||||
|
||||
return mapped_assets
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def _map_element(lbwf_asset: LbwfAssetCondition) -> Optional[Element]:
|
||||
raise NotImplementedError
|
||||
def _map_element(lbwf_element_code: LbwfAssetCondition) -> Element:
|
||||
return Element[lbwf_element_code]
|
||||
|
||||
@staticmethod
|
||||
def _calculate_renewal_year(lbwf_asset: LbwfAssetCondition) -> Optional[int]:
|
||||
remaining_life_years: Optional[int] = lbwf_asset.remaining_life
|
||||
if not remaining_life_years:
|
||||
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")
|
||||
return None
|
||||
|
|
@ -6,6 +6,6 @@ from backend.condition.domain.asset_condition import AssetCondition
|
|||
class Mapper(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def map_asset_conditions(self, client_data: List[Any]) -> List[AssetCondition]:
|
||||
def map_asset_conditions_for_property(self, client_data: Any) -> List[AssetCondition]:
|
||||
#TODO: client_data should be properly typed
|
||||
pass
|
||||
|
|
@ -233,7 +233,7 @@ def test_lbwf_mapper_maps_house():
|
|||
]
|
||||
|
||||
# act
|
||||
actual_assets: List[AssetCondition] = mapper.map_asset_conditions(lbwf_house)
|
||||
actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property(lbwf_house)
|
||||
|
||||
# assert
|
||||
assert actual_assets == expected_assets
|
||||
Loading…
Add table
Reference in a new issue