mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-12 13:29:04 +00:00
Rename Element to LbwfElement
This commit is contained in:
parent
b73f6297eb
commit
3289dc226d
6 changed files with 84 additions and 51 deletions
|
|
@ -2,13 +2,14 @@ from dataclasses import dataclass
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from backend.condition.domain.element import Element
|
from backend.condition.domain.lbwf_element import LbwfElement
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AssetCondition:
|
class AssetCondition:
|
||||||
uprn: int
|
uprn: int
|
||||||
element: Element # TODO: should HHSRS elements be handled differently?
|
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
|
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
|
quantity: int
|
||||||
renewal_year: Optional[int] = None
|
renewal_year: Optional[int] = None
|
||||||
source: Optional[str] = None
|
source: Optional[str] = None
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
|
|
||||||
|
|
||||||
class Element(StrEnum):
|
class LbwfElement(StrEnum):
|
||||||
AHR_CAT = "Accessible Housing Register Category"
|
AHR_CAT = "Accessible Housing Register Category"
|
||||||
ASBESTOS = "Asbestos Present"
|
ASBESTOS = "Asbestos Present"
|
||||||
ASSETSAREA = "Assets Area for Decent Homes and Investment"
|
ASSETSAREA = "Assets Area for Decent Homes and Investment"
|
||||||
|
|
@ -49,12 +49,20 @@ class Element(StrEnum):
|
||||||
EXTWNDWS1 = "Windows 1 in External Area"
|
EXTWNDWS1 = "Windows 1 in External Area"
|
||||||
EXTWNDWS2 = "Windows 2 in External Area"
|
EXTWNDWS2 = "Windows 2 in External Area"
|
||||||
FFHHDAMP = "Fitness for Human Habitation - Serious problem with damp"
|
FFHHDAMP = "Fitness for Human Habitation - Serious problem with damp"
|
||||||
FFHHDRNWC = "Fitness for Human Habitation - Problems with the drainage or the lavatories"
|
FFHHDRNWC = (
|
||||||
FFHHHCWAT = "Fitness for Human Habitation - Problem with the supply of hot and cold water"
|
"Fitness for Human Habitation - Problems with the drainage or the lavatories"
|
||||||
FFHHNEGLC = "Fitness for Human Habitation - Building neglected and is in a bad condition"
|
)
|
||||||
|
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"
|
FFHHNONAT = "Fitness for Human Habitation - Not enough natural light"
|
||||||
FFHHNOVEN = "Fitness for Human Habitation - Not enough ventilation"
|
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"
|
FFHHUNLAY = "Fitness for Human Habitation - Unsafe layout"
|
||||||
FFHHUNSTA = "Fitness for Human Habitation - Building is unstable"
|
FFHHUNSTA = "Fitness for Human Habitation - Building is unstable"
|
||||||
FRARISKRTG = "Fire Risk Assessment Rating"
|
FRARISKRTG = "Fire Risk Assessment Rating"
|
||||||
|
|
@ -1,29 +1,37 @@
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
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.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 backend.condition.parsing.records.lbwf.lbwf_house import LbwfHouse
|
||||||
from utils.logger import setup_logger
|
from utils.logger import setup_logger
|
||||||
|
|
||||||
logger = setup_logger()
|
logger = setup_logger()
|
||||||
|
|
||||||
|
|
||||||
class LbwfMapper(Mapper):
|
class LbwfMapper(Mapper):
|
||||||
|
|
||||||
def map_asset_conditions_for_property(self, client_data: Any, survey_year: Optional[int]) -> List[AssetCondition]:
|
def map_asset_conditions_for_property(
|
||||||
assert isinstance(client_data, LbwfHouse) # TODO: think of a better way to do this
|
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] = []
|
mapped_assets: List[AssetCondition] = []
|
||||||
|
|
||||||
uprn: int = client_data.uprn
|
uprn: int = client_data.uprn
|
||||||
for raw_asset in client_data.assets:
|
for raw_asset in client_data.assets:
|
||||||
try:
|
try:
|
||||||
element: Element = LbwfMapper._map_element(raw_asset.element_code)
|
element: LbwfElement = LbwfMapper._map_element(raw_asset.element_code)
|
||||||
except:
|
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
|
continue
|
||||||
|
|
||||||
|
|
||||||
mapped_assets.append(
|
mapped_assets.append(
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
|
|
@ -31,7 +39,9 @@ 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, survey_year),
|
renewal_year=LbwfMapper._calculate_renewal_year(
|
||||||
|
raw_asset, survey_year
|
||||||
|
),
|
||||||
source=raw_asset.element_comments,
|
source=raw_asset.element_comments,
|
||||||
install_date=raw_asset.install_date,
|
install_date=raw_asset.install_date,
|
||||||
)
|
)
|
||||||
|
|
@ -39,23 +49,25 @@ class LbwfMapper(Mapper):
|
||||||
|
|
||||||
return mapped_assets
|
return mapped_assets
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _map_element(lbwf_element_code: LbwfAssetCondition) -> LbwfElement:
|
||||||
|
return LbwfElement[lbwf_element_code]
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _map_element(lbwf_element_code: LbwfAssetCondition) -> Element:
|
def _calculate_renewal_year(
|
||||||
return Element[lbwf_element_code]
|
lbwf_asset: LbwfAssetCondition, survey_year: Optional[int]
|
||||||
|
) -> Optional[int]:
|
||||||
@staticmethod
|
|
||||||
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:
|
if not survey_year:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
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(
|
||||||
return None
|
f"Unable to map LBWF Asset remaining life {remaining_life_years} to renewal year, returning None"
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,19 @@
|
||||||
from typing import Any, List, Optional
|
from typing import Any, List, Optional
|
||||||
|
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
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.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 backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty
|
||||||
from utils.logger import setup_logger
|
from utils.logger import setup_logger
|
||||||
|
|
||||||
logger = setup_logger()
|
logger = setup_logger()
|
||||||
|
|
||||||
|
|
||||||
class PeabodyMapper(Mapper):
|
class PeabodyMapper(Mapper):
|
||||||
def map_asset_conditions_for_property(self, client_data: Any, survey_year: Optional[int]) -> List[AssetCondition]:
|
def map_asset_conditions_for_property(
|
||||||
raise NotImplementedError
|
self, client_data: Any, survey_year: Optional[int]
|
||||||
|
) -> List[AssetCondition]:
|
||||||
|
raise NotImplementedError
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,13 @@ from datetime import date
|
||||||
|
|
||||||
from backend.condition.domain.mapping.lbwf_mapper import LbwfMapper
|
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_house import LbwfHouse
|
||||||
from backend.condition.parsing.records.lbwf.lbwf_asset_condition import LbwfAssetCondition
|
from backend.condition.parsing.records.lbwf.lbwf_asset_condition import (
|
||||||
from backend.condition.domain.element import Element
|
LbwfAssetCondition,
|
||||||
|
)
|
||||||
|
from backend.condition.domain.lbwf_element import LbwfElement
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
from backend.condition.domain.asset_condition import AssetCondition
|
||||||
|
|
||||||
|
|
||||||
def test_lbwf_mapper_maps_house():
|
def test_lbwf_mapper_maps_house():
|
||||||
# arrange
|
# arrange
|
||||||
lbwf_house = LbwfHouse(
|
lbwf_house = LbwfHouse(
|
||||||
|
|
@ -162,11 +165,11 @@ def test_lbwf_mapper_maps_house():
|
||||||
element_numerical_value=None,
|
element_numerical_value=None,
|
||||||
element_text_value=None,
|
element_text_value=None,
|
||||||
quantity=1,
|
quantity=1,
|
||||||
install_date=date(2009,4,1),
|
install_date=date(2009, 4, 1),
|
||||||
remaining_life=26,
|
remaining_life=26,
|
||||||
element_comments="Source of Data = Codeman",
|
element_comments="Source of Data = Codeman",
|
||||||
),
|
),
|
||||||
]
|
],
|
||||||
)
|
)
|
||||||
mapper = LbwfMapper()
|
mapper = LbwfMapper()
|
||||||
|
|
||||||
|
|
@ -175,7 +178,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
expected_assets: List[AssetCondition] = [
|
expected_assets: List[AssetCondition] = [
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.AHR_CAT,
|
element=LbwfElement.AHR_CAT,
|
||||||
condition_description="General Needs",
|
condition_description="General Needs",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -184,7 +187,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.FLVL,
|
element=LbwfElement.FLVL,
|
||||||
condition_description="Ground Floor",
|
condition_description="Ground Floor",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -193,7 +196,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.ASBESTOS,
|
element=LbwfElement.ASBESTOS,
|
||||||
condition_description="Yes",
|
condition_description="Yes",
|
||||||
quantity=None,
|
quantity=None,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -202,7 +205,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.INTBTHRLOC,
|
element=LbwfElement.INTBTHRLOC,
|
||||||
condition_description="Bathroom on Entrance Level in Property",
|
condition_description="Bathroom on Entrance Level in Property",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -211,7 +214,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.INTCHEXTNT,
|
element=LbwfElement.INTCHEXTNT,
|
||||||
condition_description="No Central Heating in Property",
|
condition_description="No Central Heating in Property",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -220,7 +223,7 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.HHSRSFIRE,
|
element=LbwfElement.HHSRSFIRE,
|
||||||
condition_description="Category 4 - Typical Risk",
|
condition_description="Category 4 - Typical Risk",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=None,
|
renewal_year=None,
|
||||||
|
|
@ -229,18 +232,19 @@ def test_lbwf_mapper_maps_house():
|
||||||
),
|
),
|
||||||
AssetCondition(
|
AssetCondition(
|
||||||
uprn=1,
|
uprn=1,
|
||||||
element=Element.EXTWALLFN1,
|
element=LbwfElement.EXTWALLFN1,
|
||||||
condition_description="Render or Pebbledash Wall Finish 1 in External Area",
|
condition_description="Render or Pebbledash Wall Finish 1 in External Area",
|
||||||
quantity=1,
|
quantity=1,
|
||||||
renewal_year=2052,
|
renewal_year=2052,
|
||||||
source="Source of Data = Codeman",
|
source="Source of Data = Codeman",
|
||||||
install_date=date(2009,4,1),
|
install_date=date(2009, 4, 1),
|
||||||
),
|
),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# act
|
# 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
|
||||||
assert actual_assets == expected_assets
|
assert actual_assets == expected_assets
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from backend.condition.domain.mapping.peabody_mapper import PeabodyMapper
|
from backend.condition.domain.mapping.peabody_mapper import PeabodyMapper
|
||||||
from backend.condition.domain.element import Element
|
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_asset_condition import (
|
||||||
|
PeabodyAssetCondition,
|
||||||
|
)
|
||||||
from backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty
|
from backend.condition.parsing.records.peabody.peabody_property import PeabodyProperty
|
||||||
from backend.condition.domain.asset_condition import AssetCondition
|
from backend.condition.domain.asset_condition import AssetCondition
|
||||||
|
|
||||||
|
|
||||||
def test_peabody_mapper_maps_property():
|
def test_peabody_mapper_maps_property():
|
||||||
# arrange
|
# arrange
|
||||||
peabody_property = PeabodyProperty(
|
peabody_property = PeabodyProperty(
|
||||||
|
|
@ -27,12 +30,12 @@ def test_peabody_mapper_maps_property():
|
||||||
renewal_cost=500,
|
renewal_cost=500,
|
||||||
cloned="N",
|
cloned="N",
|
||||||
lo_type_code=1,
|
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
|
# act
|
||||||
|
|
||||||
# assert
|
# assert
|
||||||
assert False #temp
|
assert False # temp
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue