Model/epc_data/attributes/FloorAttributes.py
Khalim Conn-Kowlessar 3d395ed5bb refactored floor class
2023-06-13 12:57:40 +01:00

43 lines
1.6 KiB
Python

from typing import Dict, Union, Optional
from epc_data.attributes.attribute_utils import extract_thermal_transmittance, extract_component_types
class FloorAttributes:
DWELLING_BELOW = ["another dwelling below", "other premises below"]
FLOOR_TYPES = ["assumed", "to unheated space", "to external air", "suspended", "solid"]
def __init__(self, description: str):
self.description: str = description.lower()
if not description or 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]]:
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)
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