mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
81 lines
3 KiB
Python
81 lines
3 KiB
Python
from typing import Any, List, Optional
|
|
|
|
from backend.condition.domain.element import Element
|
|
from backend.condition.domain.mapping.element_mapping import ElementMapping
|
|
from backend.condition.domain.mapping.lbwf.lbwf_element_map import LBWF_ELEMENT_MAP
|
|
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] = None
|
|
) -> List[Element]:
|
|
assert isinstance(
|
|
client_data, LbwfHouse
|
|
) # TODO: think of a better way to do this
|
|
|
|
mapped_assets: List[Element] = []
|
|
|
|
uprn: int = client_data.uprn
|
|
for raw_asset in client_data.assets:
|
|
# Ignore metadata rows
|
|
if raw_asset.element_code not in ["EICINSFREQ", "DECNTHMINC"]:
|
|
try:
|
|
element_mapping: ElementMapping = 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(
|
|
Element(
|
|
uprn=uprn,
|
|
element=element_mapping.element,
|
|
aspect_type=element_mapping.aspect_type,
|
|
value=raw_asset.attribute_code_description,
|
|
quantity=raw_asset.quantity,
|
|
install_date=raw_asset.install_date,
|
|
renewal_year=LbwfMapper._calculate_renewal_year(
|
|
raw_asset, survey_year
|
|
),
|
|
element_instance=element_mapping.element_instance,
|
|
source_system=None, # Once we know the system name we'll set it here
|
|
comments=raw_asset.element_comments,
|
|
)
|
|
)
|
|
|
|
return mapped_assets
|
|
|
|
@staticmethod
|
|
def _map_element(lbwf_element_code: str) -> ElementMapping:
|
|
return LBWF_ELEMENT_MAP[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
|