mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
working on heating controls
This commit is contained in:
parent
8d6cc5a3e1
commit
02fce2e163
3 changed files with 39 additions and 4 deletions
|
|
@ -56,7 +56,7 @@ def handler():
|
||||||
df = df.reset_index(drop=True)
|
df = df.reset_index(drop=True)
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
idx = 5
|
idx = 3
|
||||||
record = df[df.index == idx].to_dict("records")[0]
|
record = df[df.index == idx].to_dict("records")[0]
|
||||||
record = {k: v for k, v in record.items() if v not in [None, np.nan, False]}
|
record = {k: v for k, v in record.items() if v not in [None, np.nan, False]}
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
from typing import Dict, Union
|
from typing import Dict, Union
|
||||||
from epc_data.attributes.attribute_utils import clean_description
|
from epc_data.attributes.attribute_utils import clean_description, remove_punctuation
|
||||||
|
|
||||||
|
|
||||||
class MainheatControlAttributes:
|
class MainheatControlAttributes:
|
||||||
|
|
@ -46,6 +46,11 @@ class MainheatControlAttributes:
|
||||||
'use of community heating'
|
'use of community heating'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MULTIPLE_ROOM_THERMOSTATS_PHRASES = [
|
||||||
|
'at least two room stats',
|
||||||
|
'at least two room thermostats'
|
||||||
|
]
|
||||||
|
|
||||||
def __init__(self, description: str):
|
def __init__(self, description: str):
|
||||||
self.description: str = clean_description(description.lower())
|
self.description: str = clean_description(description.lower())
|
||||||
|
|
||||||
|
|
@ -57,7 +62,8 @@ class MainheatControlAttributes:
|
||||||
self.THERMOSTATIC_CONTROL_KEYWORDS,
|
self.THERMOSTATIC_CONTROL_KEYWORDS,
|
||||||
self.CHARGING_SYSTEM_KEYWORDS,
|
self.CHARGING_SYSTEM_KEYWORDS,
|
||||||
self.SWITCH_SYSTEM_KEYWORDS,
|
self.SWITCH_SYSTEM_KEYWORDS,
|
||||||
self.DHW_CONTROL_KEYWORDS
|
self.DHW_CONTROL_KEYWORDS,
|
||||||
|
self.COMMUNITY_HEATING_KEYWORDS
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
raise ValueError('Invalid description')
|
raise ValueError('Invalid description')
|
||||||
|
|
@ -73,13 +79,31 @@ class MainheatControlAttributes:
|
||||||
"no_control": self._find_keyword(self.NO_CONTROL_SYSTEM_KEYWORDS),
|
"no_control": self._find_keyword(self.NO_CONTROL_SYSTEM_KEYWORDS),
|
||||||
"dhw_control": self._find_keyword(self.DHW_CONTROL_KEYWORDS),
|
"dhw_control": self._find_keyword(self.DHW_CONTROL_KEYWORDS),
|
||||||
"community_heating": self._find_keyword(self.COMMUNITY_HEATING_KEYWORDS),
|
"community_heating": self._find_keyword(self.COMMUNITY_HEATING_KEYWORDS),
|
||||||
|
"multiple_room_thermostats": any(
|
||||||
|
phrase in self.description for phrase in self.MULTIPLE_ROOM_THERMOSTATS_PHRASES),
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _find_keyword(self, keywords):
|
def _find_keyword(self, keywords):
|
||||||
|
description_words = set(self.description.split())
|
||||||
|
|
||||||
|
# Sort keywords by length, longest first. This ensures that 'time and temperature zone control'
|
||||||
|
# will be checked before 'temperature zone control' if both are present in the keywords list
|
||||||
|
keywords.sort(key=len, reverse=True)
|
||||||
|
|
||||||
for keyword in keywords:
|
for keyword in keywords:
|
||||||
if keyword in self.description:
|
keyword_words = set(keyword.split())
|
||||||
|
if keyword_words.issubset(description_words):
|
||||||
|
return keyword
|
||||||
|
|
||||||
|
# If no keyword is found, try again after removing punctuation
|
||||||
|
description_without_punct = remove_punctuation(self.description)
|
||||||
|
description_words_without_punct = set(description_without_punct.split())
|
||||||
|
|
||||||
|
for keyword in keywords:
|
||||||
|
keyword_words = set(keyword.split())
|
||||||
|
if keyword_words.issubset(description_words_without_punct):
|
||||||
return keyword
|
return keyword
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import re
|
import re
|
||||||
|
import string
|
||||||
from typing import Tuple, Union, Dict, List
|
from typing import Tuple, Union, Dict, List
|
||||||
|
|
||||||
THERMAL_TRANSMITTENCE_STR = r"average thermal transmittance (-?\d+\.\d+)\s(w/m-¦k)"
|
THERMAL_TRANSMITTENCE_STR = r"average thermal transmittance (-?\d+\.\d+)\s(w/m-¦k)"
|
||||||
|
|
@ -93,3 +94,13 @@ def process_part(result: Dict[str, Union[str, bool]], part: str, attr_list: List
|
||||||
raise ValueError("No attribute matches found")
|
raise ValueError("No attribute matches found")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def remove_punctuation(text: str) -> str:
|
||||||
|
# Create a translation table using the string.punctuation string
|
||||||
|
translation_table = str.maketrans("", "", string.punctuation)
|
||||||
|
|
||||||
|
# Use the translation table to remove punctuation from the text
|
||||||
|
text_without_punctuation = text.translate(translation_table)
|
||||||
|
|
||||||
|
return text_without_punctuation
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue