Model/epc_data/attributes/MainFuelAttributes.py
2023-06-14 18:30:00 +01:00

61 lines
1.9 KiB
Python

from typing import Dict, Union
from epc_data.attributes.attribute_utils import clean_description, remove_punctuation
class MainFuelAttributes:
FUEL_KEYWORDS = [
'heat network',
'mains gas',
'electricity',
'oil',
'biomass',
'biodiesel',
# Note: there is als a category called 'bottled LPG', but only 2/50k entries had this
'LPG',
'waste combustion',
'biogas',
'wood logs',
'dual fuel - mineral + wood',
'gas',
'anthracite',
'smokeless coal',
'house 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 = remove_punctuation(clean_description(description.lower()))
self.nodata = not description or any(keyword in self.description for keyword in self.NO_FUEL_KEYWORDS)
self.is_community = False if 'not community' in self.description else 'community' in self.description
if not self.nodata and not any(
self._keyword_in_description(keywords)
for keywords in [
self.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]] = {
"fuel_type": self._find_keyword(self.FUEL_KEYWORDS),
"no_fuel": self._find_keyword(self.NO_FUEL_KEYWORDS),
"is_community": self.is_community
}
return result
def _find_keyword(self, keywords):
for keyword in keywords:
if keyword in self.description:
return keyword
return None