Model/epc_data/attributes/MainFuelAttributes.py
2023-06-14 17:20:49 +01:00

74 lines
2.5 KiB
Python

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