From 23269bd03e7f948ac6cafb6df1b1f4362e11536d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 15 Jun 2023 12:59:53 +0100 Subject: [PATCH] initial implementation of HotWaterAttributes --- epc_data/app.py | 2 +- epc_data/attributes/HotWaterAttributes.py | 60 +++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 epc_data/attributes/HotWaterAttributes.py diff --git a/epc_data/app.py b/epc_data/app.py index e6c79fb9..b879ef96 100644 --- a/epc_data/app.py +++ b/epc_data/app.py @@ -43,7 +43,7 @@ def handler(): from epc_data.attributes.MainFuelAttributes import MainFuelAttributes from collections import Counter count = Counter([x["main-fuel"] for x in data]) - descriptions = {x["main-fuel"] for x in data} + descriptions = {x["hotwater-description"] for x in data} out = [] for description in descriptions: res = MainFuelAttributes(description).process() diff --git a/epc_data/attributes/HotWaterAttributes.py b/epc_data/attributes/HotWaterAttributes.py new file mode 100644 index 00000000..4e5e111e --- /dev/null +++ b/epc_data/attributes/HotWaterAttributes.py @@ -0,0 +1,60 @@ +from typing import Dict, Union +from epc_data.attributes.attribute_utils import clean_description, remove_punctuation, find_keyword + + +class HotWaterAttributes: + HEATER_TYPES = [ + 'gas instantaneous', + 'electric heat pump', + 'electric immersion', + 'gas boiler', + 'electric instantaneous', + 'gas multipoint', + ] + + SYSTEM_TYPES = [ + 'from main system', + 'from secondary system', + 'community scheme', + ] + + OTHER_CHARACTERISTICS = [ + 'waste water heat recovery', + 'plus solar', + 'off-peak', + 'no cylinder thermostat', + 'flue gas heat recovery', + 'standard tariff', + 'chp', + ] + + NO_SYSTEM_PRESENT_KEYWORDS = [ + 'no system present', + ] + + def __init__(self, description: str): + self.description: str = clean_description(description.lower()) + + if not any( + self._keyword_in_description(keywords) + for keywords in [ + self.HEATER_TYPES, + self.SYSTEM_TYPES, + self.OTHER_CHARACTERISTICS, + self.NO_SYSTEM_PRESENT_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]] = { + "heater_type": find_keyword(self.description, self.HEATER_TYPES), + "system_type": find_keyword(self.description, self.SYSTEM_TYPES), + "characteristics": find_keyword(self.description, self.OTHER_CHARACTERISTICS), + "no_system_present": find_keyword(self.description, self.NO_SYSTEM_PRESENT_KEYWORDS), + } + + return result