diff --git a/backend/condition/domain/asset_condition.py b/backend/condition/domain/asset_condition.py index dffbdf88..a489090f 100644 --- a/backend/condition/domain/asset_condition.py +++ b/backend/condition/domain/asset_condition.py @@ -2,13 +2,14 @@ from dataclasses import dataclass from typing import Optional from datetime import date -from backend.condition.domain.element import Element +from backend.condition.domain.lbwf_element import LbwfElement + @dataclass class AssetCondition: uprn: int - element: Element # TODO: should HHSRS elements be handled differently? - condition_description: str # TODO: this probably needs to be some sort of enum so it's searchable/filterable on the frontend. Could be hard to map from string though + element: LbwfElement # TODO: should HHSRS elements be handled differently? + condition_description: str # TODO: this probably needs to be some sort of enum so it's searchable/filterable on the frontend. Could be hard to map from string though quantity: int renewal_year: Optional[int] = None source: Optional[str] = None diff --git a/backend/condition/domain/element.py b/backend/condition/domain/lbwf_element.py similarity index 92% rename from backend/condition/domain/element.py rename to backend/condition/domain/lbwf_element.py index 021c8492..52928c72 100644 --- a/backend/condition/domain/element.py +++ b/backend/condition/domain/lbwf_element.py @@ -1,7 +1,7 @@ from enum import StrEnum -class Element(StrEnum): +class LbwfElement(StrEnum): AHR_CAT = "Accessible Housing Register Category" ASBESTOS = "Asbestos Present" ASSETSAREA = "Assets Area for Decent Homes and Investment" @@ -49,12 +49,20 @@ class Element(StrEnum): EXTWNDWS1 = "Windows 1 in External Area" EXTWNDWS2 = "Windows 2 in External Area" FFHHDAMP = "Fitness for Human Habitation - Serious problem with damp" - FFHHDRNWC = "Fitness for Human Habitation - Problems with the drainage or the lavatories" - FFHHHCWAT = "Fitness for Human Habitation - Problem with the supply of hot and cold water" - FFHHNEGLC = "Fitness for Human Habitation - Building neglected and is in a bad condition" + FFHHDRNWC = ( + "Fitness for Human Habitation - Problems with the drainage or the lavatories" + ) + FFHHHCWAT = ( + "Fitness for Human Habitation - Problem with the supply of hot and cold water" + ) + FFHHNEGLC = ( + "Fitness for Human Habitation - Building neglected and is in a bad condition" + ) FFHHNONAT = "Fitness for Human Habitation - Not enough natural light" FFHHNOVEN = "Fitness for Human Habitation - Not enough ventilation" - FFHHPRPCK = "Fitness for Human Habitation - Difficult to prepare and cook food or wash up" + FFHHPRPCK = ( + "Fitness for Human Habitation - Difficult to prepare and cook food or wash up" + ) FFHHUNLAY = "Fitness for Human Habitation - Unsafe layout" FFHHUNSTA = "Fitness for Human Habitation - Building is unstable" FRARISKRTG = "Fire Risk Assessment Rating" diff --git a/backend/condition/domain/mapping/lbwf_mapper.py b/backend/condition/domain/mapping/lbwf_mapper.py index 8b556284..dcd1d748 100644 --- a/backend/condition/domain/mapping/lbwf_mapper.py +++ b/backend/condition/domain/mapping/lbwf_mapper.py @@ -1,29 +1,37 @@ from typing import Any, List, Optional from backend.condition.domain.asset_condition import AssetCondition -from backend.condition.domain.element import Element +from backend.condition.domain.lbwf_element import LbwfElement 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_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 + + 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) + element: LbwfElement = LbwfMapper._map_element(raw_asset.element_code) except: - logger.warning(f"Unrecognised LBWF Asset Element Code: {raw_asset.element_code}. Skipping record") + logger.warning( + f"Unrecognised LBWF Asset Element Code: {raw_asset.element_code}. Skipping record" + ) continue - mapped_assets.append( AssetCondition( @@ -31,7 +39,9 @@ class LbwfMapper(Mapper): element=element, condition_description=raw_asset.attribute_code_description, quantity=raw_asset.quantity, - renewal_year=LbwfMapper._calculate_renewal_year(raw_asset, survey_year), + renewal_year=LbwfMapper._calculate_renewal_year( + raw_asset, survey_year + ), source=raw_asset.element_comments, install_date=raw_asset.install_date, ) @@ -39,23 +49,25 @@ class LbwfMapper(Mapper): return mapped_assets + @staticmethod + def _map_element(lbwf_element_code: LbwfAssetCondition) -> LbwfElement: + return LbwfElement[lbwf_element_code] - @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]: + 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 \ No newline at end of file + logger.debug( + f"Unable to map LBWF Asset remaining life {remaining_life_years} to renewal year, returning None" + ) + return None diff --git a/backend/condition/domain/mapping/peabody_mapper.py b/backend/condition/domain/mapping/peabody_mapper.py index 88d0a626..4c647380 100644 --- a/backend/condition/domain/mapping/peabody_mapper.py +++ b/backend/condition/domain/mapping/peabody_mapper.py @@ -1,14 +1,19 @@ from typing import Any, List, Optional from backend.condition.domain.asset_condition import AssetCondition -from backend.condition.domain.element import Element +from backend.condition.domain.lbwf_element import LbwfElement from backend.condition.domain.mapping.mapper import Mapper -from backend.condition.parsing.records.peabody.peabody_asset_condition import PeabodyAssetCondition +from backend.condition.parsing.records.peabody.peabody_asset_condition import ( + PeabodyAssetCondition, +) from backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty from utils.logger import setup_logger logger = setup_logger() + class PeabodyMapper(Mapper): - def map_asset_conditions_for_property(self, client_data: Any, survey_year: Optional[int]) -> List[AssetCondition]: - raise NotImplementedError \ No newline at end of file + def map_asset_conditions_for_property( + self, client_data: Any, survey_year: Optional[int] + ) -> List[AssetCondition]: + raise NotImplementedError diff --git a/backend/condition/tests/mapping/test_lbwf_mapper.py b/backend/condition/tests/mapping/test_lbwf_mapper.py index 151e5d19..c007b575 100644 --- a/backend/condition/tests/mapping/test_lbwf_mapper.py +++ b/backend/condition/tests/mapping/test_lbwf_mapper.py @@ -4,10 +4,13 @@ from datetime import date from backend.condition.domain.mapping.lbwf_mapper import LbwfMapper from backend.condition.parsing.records.lbwf.lbwf_house import LbwfHouse -from backend.condition.parsing.records.lbwf.lbwf_asset_condition import LbwfAssetCondition -from backend.condition.domain.element import Element +from backend.condition.parsing.records.lbwf.lbwf_asset_condition import ( + LbwfAssetCondition, +) +from backend.condition.domain.lbwf_element import LbwfElement from backend.condition.domain.asset_condition import AssetCondition + def test_lbwf_mapper_maps_house(): # arrange lbwf_house = LbwfHouse( @@ -162,11 +165,11 @@ def test_lbwf_mapper_maps_house(): element_numerical_value=None, element_text_value=None, quantity=1, - install_date=date(2009,4,1), + install_date=date(2009, 4, 1), remaining_life=26, element_comments="Source of Data = Codeman", ), - ] + ], ) mapper = LbwfMapper() @@ -175,7 +178,7 @@ def test_lbwf_mapper_maps_house(): expected_assets: List[AssetCondition] = [ AssetCondition( uprn=1, - element=Element.AHR_CAT, + element=LbwfElement.AHR_CAT, condition_description="General Needs", quantity=1, renewal_year=None, @@ -184,7 +187,7 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.FLVL, + element=LbwfElement.FLVL, condition_description="Ground Floor", quantity=1, renewal_year=None, @@ -193,7 +196,7 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.ASBESTOS, + element=LbwfElement.ASBESTOS, condition_description="Yes", quantity=None, renewal_year=None, @@ -202,7 +205,7 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.INTBTHRLOC, + element=LbwfElement.INTBTHRLOC, condition_description="Bathroom on Entrance Level in Property", quantity=1, renewal_year=None, @@ -211,7 +214,7 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.INTCHEXTNT, + element=LbwfElement.INTCHEXTNT, condition_description="No Central Heating in Property", quantity=1, renewal_year=None, @@ -220,7 +223,7 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.HHSRSFIRE, + element=LbwfElement.HHSRSFIRE, condition_description="Category 4 - Typical Risk", quantity=1, renewal_year=None, @@ -229,18 +232,19 @@ def test_lbwf_mapper_maps_house(): ), AssetCondition( uprn=1, - element=Element.EXTWALLFN1, + element=LbwfElement.EXTWALLFN1, condition_description="Render or Pebbledash Wall Finish 1 in External Area", quantity=1, renewal_year=2052, source="Source of Data = Codeman", - install_date=date(2009,4,1), + install_date=date(2009, 4, 1), ), - ] # act - actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property(lbwf_house, survey_year) + actual_assets: List[AssetCondition] = mapper.map_asset_conditions_for_property( + lbwf_house, survey_year + ) # assert - assert actual_assets == expected_assets \ No newline at end of file + assert actual_assets == expected_assets diff --git a/backend/condition/tests/mapping/test_peabody_mapper.py b/backend/condition/tests/mapping/test_peabody_mapper.py index fc70b015..2d2446e5 100644 --- a/backend/condition/tests/mapping/test_peabody_mapper.py +++ b/backend/condition/tests/mapping/test_peabody_mapper.py @@ -1,11 +1,14 @@ from datetime import datetime from backend.condition.domain.mapping.peabody_mapper import PeabodyMapper -from backend.condition.domain.element import Element -from backend.condition.parsing.records.peabody.peabody_asset_condition import PeabodyAssetCondition +from backend.condition.domain.lbwf_element import LbwfElement +from backend.condition.parsing.records.peabody.peabody_asset_condition import ( + PeabodyAssetCondition, +) from backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty from backend.condition.domain.asset_condition import AssetCondition + def test_peabody_mapper_maps_property(): # arrange peabody_property = PeabodyProperty( @@ -27,12 +30,12 @@ def test_peabody_mapper_maps_property(): renewal_cost=500, cloned="N", lo_type_code=1, - condition_survey_date=datetime(2024,2,15,0,0,0), + condition_survey_date=datetime(2024, 2, 15, 0, 0, 0), ) - ] + ], ) # act # assert - assert False #temp \ No newline at end of file + assert False # temp