Model/epc_data/attributes/attribute_utils.py
2023-06-13 12:12:30 +01:00

67 lines
1.9 KiB
Python

import re
from typing import Tuple, Union
THERMAL_TRANSMITTANCE_U_VALUE_REGEX = re.compile(r"(\d+\.\d+)")
THERMAL_TRANSMITTANCE_UNIT_REGEX = re.compile(r"(w/m-¦k)")
def extract_thermal_transmittence(description_lower: str) -> Tuple[Union[float, None], Union[str, None]]:
"""
Extracts thermal transmittance from the description.
:param description_lower: Lowercase description.
:return: Tuple containing U-value and unit.
"""
# Find U-value
u_value = re.search(THERMAL_TRANSMITTANCE_U_VALUE_REGEX, description_lower)
if u_value is not None:
u_value = float(u_value.group(1))
else:
u_value = None
# Find unit
unit = re.search(THERMAL_TRANSMITTANCE_UNIT_REGEX, description_lower)
if unit is not None:
unit = unit.group(1)
else:
unit = None
return u_value, unit
def search_split_description(desc: str) -> str:
"""
Searches split descriptions and looks for key words, determining a description about the roof's/floor's insulation.
:param desc: Description to be searched.
:return: Result of the search.
"""
outputs = {
"insulated": "average",
"limited": "below average",
"no insulation": "none",
"limited insulation": "below average",
}
out = outputs.get(desc, None)
if out:
return out
raise NotImplementedError("Handle me")
def extract_component_types(result: dict, description: str, list_of_components: list) -> list:
"""
Extracts component types from the description.
:param result:
:param description:
:param list_of_components:
:return:
"""
for component in list_of_components:
result[f'is_{component.replace(" ", "_")}'] = component in description
# Remove the roof type from the description
description = description.replace(component, "")
return result, description