from typing import Dict, Union from model_data.BaseUtility import Definitions from model_data.epc_attributes.attribute_utils import extract_thermal_transmittance, extract_component_types class FloorAttributes(Definitions): DWELLING_BELOW = ["another dwelling below", "other premises below"] FLOOR_TYPES = ["assumed", "to unheated space", "to external air", "suspended", "solid"] # For the short term, while we are still exploring the data, we maintain a list of error cases which # we want to ignore and consider as no data. OBSERVED_ERRORS = ["Conservatory"] WELSH_TEXT = { "(anheddiad arall islaw)": "(another dwelling below)", } def __init__(self, description: str): self.description: str = description.lower() self.nodata = (not description) or (description in self.DATA_ANOMALY_MATCHES) or ( description in self.OBSERVED_ERRORS) # Try and perform a translation, incase it's in welsh translation = self.WELSH_TEXT.get(self.description) if translation: self.nodata = False self.description = translation if not self.nodata and not any( rt in self.description for rt in self.FLOOR_TYPES + self.DWELLING_BELOW + ["average thermal transmittance"] ): raise ValueError('Invalid description') def process(self) -> Dict[str, Union[str, bool, int, None]]: if self.nodata: return {"no_data": True} result: Dict[str, Union[float, str, bool, None]] = {} description = self.description # thermal transmittance result, description = extract_thermal_transmittance(result, description) # floor type result, description = extract_component_types(result, description, list_of_components=self.FLOOR_TYPES) # check if there is another dwelling below result['another_property_below'] = "(another dwelling below)" in description or "(other premises below)" in \ description thickness_map = { "external insulation": "average", "internal insulation": "average", "limited insulation": "below average", "partial insulation": "below average", "no insulation": "none", "additional insulation": "above average", "insulated": "average" } for key, value in thickness_map.items(): if key in description: result['insulation_thickness'] = value break else: result['insulation_thickness'] = None return result