From a39367474cd5eb1d9b62f3be0a983493e4c13cc7 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 14 Jun 2023 14:31:36 +0100 Subject: [PATCH] outline of epc_data/attributes/MainheatControlAttributes.py --- epc_data/app.py | 6 +-- .../attributes/MainheatControlAttributes.py | 53 +++++++++++++++++++ epc_data/attributes/RoofAttributes.py | 2 +- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 epc_data/attributes/MainheatControlAttributes.py diff --git a/epc_data/app.py b/epc_data/app.py index 78232a7a..b2d9be49 100644 --- a/epc_data/app.py +++ b/epc_data/app.py @@ -40,11 +40,11 @@ def handler(): cleaner.clean() # For testing: - from epc_data.attributes.WindowAttributes import WindowAttributes - descriptions = {x["windows-description"] for x in data} + from epc_data.attributes.MainheatControlAttributes import MainheatControlAttributes + descriptions = {x["mainheatcont-description"] for x in data} out = [] for description in descriptions: - res = WindowAttributes(description).process() + res = MainheatControlAttributes(description).process() out.append( { "original_description": description, diff --git a/epc_data/attributes/MainheatControlAttributes.py b/epc_data/attributes/MainheatControlAttributes.py new file mode 100644 index 00000000..1d251713 --- /dev/null +++ b/epc_data/attributes/MainheatControlAttributes.py @@ -0,0 +1,53 @@ +from typing import Dict, Union +from epc_data.attributes.attribute_utils import clean_description + + +class MainheatControlAttributes: + CONTROL_SYSTEM_KEYWORDS = [ + "charging system", "flat rate charging", "no thermostatic control", + "programmer", "room thermostats", "trvs", "bypass", "flow switch", + "automatic charge control", "manual charge control", + "temperature zone control", "time and temperature zone control", + "high heat retention storage heaters", "appliance thermostats", "dhw only", + "no time or thermostatic control", "room thermostat" + ] + + # These systems allow for the automatic regulation of temperature + THERMOSTATIC_CONTROL_KEYWORDS = [] + + # These systems provide a way to store and manage energy usage + CHARGING_SYSTEM_KEYWORDS = [] + + # These systems are mainly focused on on/off operations + SWITCH_SYSTEM_KEYWORDS = [] + + # hese keywords indicate a lack of control system + NO_CONTROL_SYSTEM_KEYWORDS = ["none"] + + # These systems provide control specifically for Domestic Hot Water + DHW_CONTROL_KEYWORDS = [] + + def __init__(self, description: str): + self.description: str = clean_description(description.lower()) + + # In the case of an empty description, we want to return a dictionary with all values set to False + # and indicate there was no data + self.nodata = not description or self.description in self.NO_CONTROL_SYSTEM_KEYWORDS + + if not self.nodata: + if not any(keyword in self.description for keyword in self.CONTROL_SYSTEM_KEYWORDS): + raise ValueError('Invalid description') + + def process(self) -> Dict[str, Union[str, bool]]: + result: Dict[str, Union[str, bool]] = { + "no_data": self.nodata + } + + if self.nodata: + return result + + # We consolidate CONTROL_SYSTEM_KEYWORDS into separate attributes + for keyword in self.CONTROL_SYSTEM_KEYWORDS: + result[f'has_{keyword.replace(" ", "_")}'] = keyword in self.description + + return result diff --git a/epc_data/attributes/RoofAttributes.py b/epc_data/attributes/RoofAttributes.py index 22b4aaec..84afdc16 100644 --- a/epc_data/attributes/RoofAttributes.py +++ b/epc_data/attributes/RoofAttributes.py @@ -1,6 +1,6 @@ import re from typing import Dict, Union -from epc_data.attributes.attribute_utils import extract_component_types, extract_thermal_transmittance, process_part +from epc_data.attributes.attribute_utils import extract_component_types, extract_thermal_transmittance class RoofAttributes: