MainFuelAttributes outline

This commit is contained in:
Khalim Conn-Kowlessar 2023-06-14 17:20:49 +01:00
parent 6b2adcb58e
commit 6e26b941b7
2 changed files with 77 additions and 1 deletions

View file

@ -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()

View file

@ -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