Model/backend/condition/domain/mapping/lbwf_mapper.py
2026-01-21 12:37:23 +00:00

62 lines
No EOL
2.3 KiB
Python

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_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] = []
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, survey_year),
source=raw_asset.element_comments,
install_date=raw_asset.install_date,
)
)
return mapped_assets
@staticmethod
def _map_element(lbwf_element_code: LbwfAssetCondition) -> Element:
return Element[lbwf_element_code]
@staticmethod
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:
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