mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
52 lines
2.6 KiB
Python
52 lines
2.6 KiB
Python
from typing import Dict, Union, Optional
|
|
from epc_data.attributes.attribute_utils import extract_thermal_transmittence, search_split_description
|
|
|
|
|
|
class FloorAttributes:
|
|
INSULATION_TERMS = ["insulation", "insulated"]
|
|
FLOOR_TYPES = ["suspended", "solid"]
|
|
EXPOSURE_TYPES = ["to unheated space", "to external air"]
|
|
DWELLING_BELOW_TYPES = ["another dwelling below", "other premises below"]
|
|
|
|
def __init__(self, description: str):
|
|
if not description or not any(term in description.lower() for term in
|
|
self.FLOOR_TYPES + self.INSULATION_TERMS + self.EXPOSURE_TYPES +
|
|
self.DWELLING_BELOW_TYPES):
|
|
raise ValueError('Invalid description')
|
|
self.description = description.lower().strip()
|
|
|
|
def process(self) -> Dict[str, Union[str, bool, int, None]]:
|
|
description = self.description
|
|
is_suspended = any(ft in description for ft in self.FLOOR_TYPES)
|
|
is_solid = "solid" in description
|
|
to_unheated_space = "to unheated space" in description
|
|
to_external_air = "to external air" in description
|
|
assumed = "assumed" in description
|
|
has_dwelling_below = any(db in description for db in self.DWELLING_BELOW_TYPES)
|
|
is_valid = "invalid" not in description
|
|
|
|
insulation_thickness = self._find_insulation_thickness(description) if any(
|
|
it in description for it in self.INSULATION_TERMS) else None
|
|
thermal_transmittence, thermal_transmittence_unit = extract_thermal_transmittence(
|
|
description) if "thermal transmittance" in description else (None, None)
|
|
|
|
return {
|
|
"is_valid": is_valid,
|
|
"has_dwelling_below": has_dwelling_below,
|
|
"thermal_transmittence": thermal_transmittence,
|
|
"thermal_transmittence_unit": thermal_transmittence_unit,
|
|
"to_unheated_space": to_unheated_space,
|
|
"to_external_air": to_external_air,
|
|
"is_suspended": is_suspended,
|
|
"is_solid": is_solid,
|
|
"assumed": assumed,
|
|
"insulation_thickness": insulation_thickness
|
|
}
|
|
|
|
def _find_insulation_thickness(self, description) -> str:
|
|
split_term = next((ex for ex in self.EXPOSURE_TYPES if ex in description), None) or \
|
|
next((ft for ft in self.FLOOR_TYPES if ft in description), None)
|
|
if split_term is not None:
|
|
desc_split = description.split(f"{split_term},")[-1].strip().split("(assumed)")[0].strip()
|
|
return search_split_description(desc_split)
|
|
raise NotImplementedError("Insulation thickness handling for this description is not implemented")
|