mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
47 lines
1.5 KiB
Python
47 lines
1.5 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 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 component from the description
|
|
description = description.replace(component, "")
|
|
|
|
return result, description
|