mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
import re
|
|
from typing import Tuple, Union, Dict
|
|
|
|
THERMAL_TRANSMITTENCE_STR = r"average thermal transmittance (-?\d+\.\d+)\s(w/m-¦k)"
|
|
THERMAL_TRANSMITTANCE_REGEX = re.compile(THERMAL_TRANSMITTENCE_STR)
|
|
|
|
|
|
def extract_thermal_transmittence(result: dict, description: str) -> Tuple[
|
|
Dict[str, Union[None, str, float]], str
|
|
]:
|
|
"""
|
|
Extracts thermal transmittance from the description.
|
|
|
|
:param result: Dictionary to store the result in.
|
|
:param description: Lowercase description.
|
|
:return: Tuple of r
|
|
"""
|
|
# thermal transmittance
|
|
match = THERMAL_TRANSMITTANCE_REGEX.search(description)
|
|
if match:
|
|
result['thermal_transmittance'] = float(match.group(1))
|
|
result['thermal_transmittance_unit'] = match.group(2)
|
|
# Remove the match from the description
|
|
description = re.sub(THERMAL_TRANSMITTENCE_STR, "", description)
|
|
else:
|
|
result['thermal_transmittance'] = None
|
|
result['thermal_transmittance_unit'] = None
|
|
|
|
return result, description
|
|
|
|
|
|
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) -> Tuple[
|
|
Dict[str, Union[None, str, float]], str
|
|
]:
|
|
"""
|
|
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
|