diff --git a/epc_data/app.py b/epc_data/app.py index 9bb3a722..cebd9ab8 100644 --- a/epc_data/app.py +++ b/epc_data/app.py @@ -41,7 +41,9 @@ def handler(): # For testing: from epc_data.attributes.MainheatControlAttributes import MainheatControlAttributes - descriptions = {x["mainheatcont-description"] for x in data} + from collections import Counter + count = Counter([x["main-fuel"] for x in data]) + descriptions = {x["main-fuel"] for x in data} out = [] for description in descriptions: res = MainheatControlAttributes(description).process() diff --git a/epc_data/attributes/MainFuelAttributes.py b/epc_data/attributes/MainFuelAttributes.py new file mode 100644 index 00000000..1be67f23 --- /dev/null +++ b/epc_data/attributes/MainFuelAttributes.py @@ -0,0 +1,74 @@ +from typing import Dict, Union +from epc_data.attributes.attribute_utils import clean_description + + +class MainFuelAttributes: + COMMUNITY_FUEL_KEYWORDS = [ + 'from heat network data (community)', + 'mains gas (community)', + 'electricity (community)', + 'oil (community)', + 'biomass (community)', + 'heat from boilers using biodiesel from any biomass source (community)', + 'LPG (community)', + 'waste combustion (community)' + ] + + NOT_COMMUNITY_FUEL_KEYWORDS = [ + 'mains gas (not community)', + 'electricity (not community)', + 'oil (not community)', + 'house coal (not community)', + 'LPG (not community)', + 'biogas (not community)' + ] + + SPECIFIC_FUEL_KEYWORDS = [ + 'waste combustion - this is for backwards compatibility only and should not be used', + 'bottled LPG', + 'wood logs', + 'dual fuel - mineral + wood', + 'Gas: mains gas', + 'Electricity: electricity, unspecified tariff', + 'anthracite', + 'smokeless coal' + ] + + NO_FUEL_KEYWORDS = [ + 'To be used only when there is no heating/hot-water system or data is from a community network' + ] + + def __init__(self, description: str): + self.description: str = clean_description(description.lower()) + + self.nodata = not description or any(keyword in self.description for keyword in self.NO_FUEL_KEYWORDS) + + if not self.nodata and not any( + self._keyword_in_description(keywords) + for keywords in [ + self.COMMUNITY_FUEL_KEYWORDS, + self.NOT_COMMUNITY_FUEL_KEYWORDS, + self.SPECIFIC_FUEL_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]] = { + "community_fuel": self._find_keyword(self.COMMUNITY_FUEL_KEYWORDS), + "not_community_fuel": self._find_keyword(self.NOT_COMMUNITY_FUEL_KEYWORDS), + "specific_fuel": self._find_keyword(self.SPECIFIC_FUEL_KEYWORDS), + "no_fuel": self._find_keyword(self.NO_FUEL_KEYWORDS), + } + + return result + + def _find_keyword(self, keywords): + for keyword in keywords: + if keyword in self.description: + return keyword + + return None