From 8d6cc5a3e1229467c0d358ebbacadd13b8a185ae Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 14 Jun 2023 15:10:40 +0100 Subject: [PATCH] working on MainheatControlAttributes --- epc_data/app.py | 18 ++-- .../attributes/MainheatControlAttributes.py | 90 +++++++++++++------ 2 files changed, 69 insertions(+), 39 deletions(-) diff --git a/epc_data/app.py b/epc_data/app.py index b2d9be49..eff07b74 100644 --- a/epc_data/app.py +++ b/epc_data/app.py @@ -56,20 +56,18 @@ def handler(): df = df.reset_index(drop=True) import numpy as np - idx = 88 + idx = 5 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]} from pprint import pprint pprint(record) - # This has has_electric as true and not sure if we want that - description = 'Boiler and radiators, mains gas, Electric storage heaters' - # This has has_electric as true and has has_underfloor_heating as true and has_electric_underfloor_heating as true - # and not sure if we want that but might be fine - description = 'Boiler and radiators, mains gas, Electric underfloor heating' - - z = df[df["original_description"] == 'Air source heat pump, radiators and underfloor, electric'] - - # LPG boiler + # Issues: + # 1) '2207 Time and temperature zone control' - we don't pick up any reference to the fact this is a time and + # temperature zone control + # and we only pick up temperature zone control at the moment. Can we capture this too + # 2) 'Charging system linked to use of community heating, programmer and at least two room stats' - what are room + # stats and how should + # we capture this? df.to_dict("records") diff --git a/epc_data/attributes/MainheatControlAttributes.py b/epc_data/attributes/MainheatControlAttributes.py index 1d251713..77db712a 100644 --- a/epc_data/attributes/MainheatControlAttributes.py +++ b/epc_data/attributes/MainheatControlAttributes.py @@ -3,51 +3,83 @@ 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 = [ + 'room thermostats', + 'appliance thermostats', + 'trvs', + 'room thermostat', + 'temperature zone control', + 'time and temperature zone control', + 'no thermostatic control' ] - # 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 = [] + CHARGING_SYSTEM_KEYWORDS = [ + 'charging system', + 'automatic charge control', + 'manual charge control', + 'flat rate charging', + 'high heat retention storage heaters' + ] # These systems are mainly focused on on/off operations - SWITCH_SYSTEM_KEYWORDS = [] + SWITCH_SYSTEM_KEYWORDS = [ + 'programmer', + 'flow switch', + 'bypass' + ] - # hese keywords indicate a lack of control system - NO_CONTROL_SYSTEM_KEYWORDS = ["none"] + # These keywords indicate a lack of control system + NO_CONTROL_SYSTEM_KEYWORDS = [ + 'no time or thermostatic control', + 'none' + ] # These systems provide control specifically for Domestic Hot Water - DHW_CONTROL_KEYWORDS = [] + DHW_CONTROL_KEYWORDS = [ + 'dhw only' + ] + + # This system indicates the use of community heating + COMMUNITY_HEATING_KEYWORDS = [ + 'use of community heating' + ] 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 + self.nodata = not description or any(keyword in self.description for keyword 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') + if not self.nodata and not any( + self._keyword_in_description(keywords) + for keywords in [ + self.THERMOSTATIC_CONTROL_KEYWORDS, + self.CHARGING_SYSTEM_KEYWORDS, + self.SWITCH_SYSTEM_KEYWORDS, + self.DHW_CONTROL_KEYWORDS + ] + ): + raise ValueError('Invalid description') + + def _keyword_in_description(self, keywords): + return any(keyword in self.description for keyword in keywords) def process(self) -> Dict[str, Union[str, bool]]: result: Dict[str, Union[str, bool]] = { - "no_data": self.nodata + "thermostatic_control": self._find_keyword(self.THERMOSTATIC_CONTROL_KEYWORDS), + "charging_system": self._find_keyword(self.CHARGING_SYSTEM_KEYWORDS), + "switch_system": self._find_keyword(self.SWITCH_SYSTEM_KEYWORDS), + "no_control": self._find_keyword(self.NO_CONTROL_SYSTEM_KEYWORDS), + "dhw_control": self._find_keyword(self.DHW_CONTROL_KEYWORDS), + "community_heating": self._find_keyword(self.COMMUNITY_HEATING_KEYWORDS), } - 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 + + def _find_keyword(self, keywords): + for keyword in keywords: + if keyword in self.description: + return keyword + + return None