mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-30 13:10:47 +00:00
updated class definition
This commit is contained in:
parent
6e26b941b7
commit
d6b4403cfe
2 changed files with 23 additions and 36 deletions
|
|
@ -40,13 +40,13 @@ def handler():
|
||||||
cleaner.clean()
|
cleaner.clean()
|
||||||
|
|
||||||
# For testing:
|
# For testing:
|
||||||
from epc_data.attributes.MainheatControlAttributes import MainheatControlAttributes
|
from epc_data.attributes.MainFuelAttributes import MainFuelAttributes
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
count = Counter([x["main-fuel"] for x in data])
|
count = Counter([x["main-fuel"] for x in data])
|
||||||
descriptions = {x["main-fuel"] for x in data}
|
descriptions = {x["main-fuel"] for x in data}
|
||||||
out = []
|
out = []
|
||||||
for description in descriptions:
|
for description in descriptions:
|
||||||
res = MainheatControlAttributes(description).process()
|
res = MainFuelAttributes(description).process()
|
||||||
out.append(
|
out.append(
|
||||||
{
|
{
|
||||||
"original_description": description,
|
"original_description": description,
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,25 @@
|
||||||
from typing import Dict, Union
|
from typing import Dict, Union
|
||||||
from epc_data.attributes.attribute_utils import clean_description
|
from epc_data.attributes.attribute_utils import clean_description, remove_punctuation
|
||||||
|
|
||||||
|
|
||||||
class MainFuelAttributes:
|
class MainFuelAttributes:
|
||||||
COMMUNITY_FUEL_KEYWORDS = [
|
FUEL_KEYWORDS = [
|
||||||
'from heat network data (community)',
|
'heat network',
|
||||||
'mains gas (community)',
|
'mains gas',
|
||||||
'electricity (community)',
|
'electricity',
|
||||||
'oil (community)',
|
'oil',
|
||||||
'biomass (community)',
|
'biomass',
|
||||||
'heat from boilers using biodiesel from any biomass source (community)',
|
'biodiesel',
|
||||||
'LPG (community)',
|
# Note: there is als a category called 'bottled LPG', but only 2/50k entries had this
|
||||||
'waste combustion (community)'
|
'LPG',
|
||||||
]
|
'waste combustion',
|
||||||
|
'biogas',
|
||||||
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',
|
'wood logs',
|
||||||
'dual fuel - mineral + wood',
|
'dual fuel - mineral + wood',
|
||||||
'Gas: mains gas',
|
'gas',
|
||||||
'Electricity: electricity, unspecified tariff',
|
|
||||||
'anthracite',
|
'anthracite',
|
||||||
'smokeless coal'
|
'smokeless coal',
|
||||||
|
'house coal'
|
||||||
]
|
]
|
||||||
|
|
||||||
NO_FUEL_KEYWORDS = [
|
NO_FUEL_KEYWORDS = [
|
||||||
|
|
@ -39,16 +27,16 @@ class MainFuelAttributes:
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, description: str):
|
def __init__(self, description: str):
|
||||||
self.description: str = clean_description(description.lower())
|
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.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(
|
if not self.nodata and not any(
|
||||||
self._keyword_in_description(keywords)
|
self._keyword_in_description(keywords)
|
||||||
for keywords in [
|
for keywords in [
|
||||||
self.COMMUNITY_FUEL_KEYWORDS,
|
self.FUEL_KEYWORDS
|
||||||
self.NOT_COMMUNITY_FUEL_KEYWORDS,
|
|
||||||
self.SPECIFIC_FUEL_KEYWORDS
|
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
raise ValueError('Invalid description')
|
raise ValueError('Invalid description')
|
||||||
|
|
@ -58,10 +46,9 @@ class MainFuelAttributes:
|
||||||
|
|
||||||
def process(self) -> Dict[str, Union[str, bool]]:
|
def process(self) -> Dict[str, Union[str, bool]]:
|
||||||
result: Dict[str, Union[str, bool]] = {
|
result: Dict[str, Union[str, bool]] = {
|
||||||
"community_fuel": self._find_keyword(self.COMMUNITY_FUEL_KEYWORDS),
|
"fuel_type": self._find_keyword(self.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),
|
"no_fuel": self._find_keyword(self.NO_FUEL_KEYWORDS),
|
||||||
|
"is_community": self.is_community
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue