Model/model_data/epc_attributes/FloorAttributes.py
2023-07-01 17:00:05 +01:00

60 lines
2.3 KiB
Python

from typing import Dict, Union
from model_data.BaseUtility import BaseUtility
from model_data.epc_attributes.attribute_utils import extract_thermal_transmittance, extract_component_types
class FloorAttributes(BaseUtility):
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"]
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
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