mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
windows class working nicely
This commit is contained in:
parent
87a2edcdba
commit
450b81cb14
2 changed files with 73 additions and 13 deletions
|
|
@ -1,11 +1,20 @@
|
|||
from typing import Dict, Union
|
||||
from epc_data.attributes.attribute_utils import clean_description, process_part
|
||||
from epc_data.attributes.attribute_utils import clean_description
|
||||
|
||||
|
||||
class WindowAttributes:
|
||||
GLAZING_KEYWORDS = ["glazing", "glazed", "glaze"]
|
||||
GLAZING_COVERAGE = ["fully", "mostly", "partial", "some"]
|
||||
GLAZING_TYPES = ["double", "triple", "secondary", "multiple", "high performance"]
|
||||
GLAZING_COVERAGE = ["fully", "mostly", "partial", "some", "full", "thoughout"]
|
||||
GLAZING_TYPES = ["double", "triple", "secondary", "multiple", "high performance", "single"]
|
||||
|
||||
coverage_map = {
|
||||
"full": "full",
|
||||
"fully": "full",
|
||||
"mostly": "most",
|
||||
"partial": "partial",
|
||||
"some": "partial",
|
||||
"throughout": "full"
|
||||
}
|
||||
|
||||
def __init__(self, description: str):
|
||||
self.description: str = clean_description(description.lower())
|
||||
|
|
@ -23,22 +32,34 @@ class WindowAttributes:
|
|||
|
||||
def process(self) -> Dict[str, Union[str, bool]]:
|
||||
result: Dict[str, Union[str, bool]] = {
|
||||
f'has_{wt.replace(" ", "_")}': False for wt in self.GLAZING_KEYWORDS
|
||||
"has_glazing": False,
|
||||
"glazing_coverage": None,
|
||||
"glazing_type": None,
|
||||
"no_data": self.nodata
|
||||
}
|
||||
result.update({f'is_{gc.replace(" ", "_")}': False for gc in self.GLAZING_COVERAGE})
|
||||
result.update({f'is_{gt.replace(" ", "_")}': False for gt in self.GLAZING_TYPES})
|
||||
result["no_data"] = self.nodata
|
||||
|
||||
if self.nodata:
|
||||
return result
|
||||
|
||||
description = self.description.split(',')
|
||||
# We consolidate GLAZING_KEYWORDS into a single attribute
|
||||
result["has_glazing"] = any(keyword in self.description for keyword in self.GLAZING_KEYWORDS)
|
||||
|
||||
# Process each part separately
|
||||
for part in description:
|
||||
# For coverage and type, we will only store the first one we find
|
||||
for part in self.description.split(','):
|
||||
part = part.strip() # remove leading/trailing white spaces
|
||||
process_part(result, part, self.GLAZING_KEYWORDS, 'has_')
|
||||
process_part(result, part, self.GLAZING_COVERAGE, 'is_')
|
||||
process_part(result, part, self.GLAZING_TYPES, 'is_')
|
||||
if not result["glazing_coverage"]:
|
||||
for coverage in self.GLAZING_COVERAGE:
|
||||
if coverage in part:
|
||||
result["glazing_coverage"] = self.coverage_map[coverage]
|
||||
break
|
||||
if not result["glazing_type"]:
|
||||
for glazing_type in self.GLAZING_TYPES:
|
||||
if glazing_type in part:
|
||||
result["glazing_type"] = glazing_type
|
||||
break
|
||||
|
||||
# If we didn't find any coverage or type, we assume full coverage
|
||||
if not result["glazing_coverage"]:
|
||||
result["glazing_coverage"] = "full"
|
||||
|
||||
return result
|
||||
|
|
|
|||
39
epc_data/tests/test_data/test_window_attributes_cases.py
Normal file
39
epc_data/tests/test_data/test_window_attributes_cases.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
windows_cases = [
|
||||
{'original_description': '', 'has_glazing': False, 'glazing_coverage': None, 'glazing_type': None, 'no_data': True},
|
||||
{'original_description': 'Full secondary glazing', 'has_glazing': True, 'glazing_coverage': 'full',
|
||||
'glazing_type': 'secondary', 'no_data': False},
|
||||
{'original_description': 'Fully double glazed', 'has_glazing': True, 'glazing_coverage': 'full',
|
||||
'glazing_type': 'double', 'no_data': False},
|
||||
{'original_description': 'Fully triple glazed', 'has_glazing': True, 'glazing_coverage': 'full',
|
||||
'glazing_type': 'triple', 'no_data': False},
|
||||
{'original_description': 'High performance glazing', 'has_glazing': True, 'glazing_coverage': 'full',
|
||||
'glazing_type': 'high performance', 'no_data': False},
|
||||
{'original_description': 'Mostly double glazing', 'has_glazing': True, 'glazing_coverage': 'most',
|
||||
'glazing_type': 'double', 'no_data': False},
|
||||
{'original_description': 'Mostly multiple glazing', 'has_glazing': True, 'glazing_coverage': 'most',
|
||||
'glazing_type': 'multiple', 'no_data': False},
|
||||
{'original_description': 'Mostly secondary glazing', 'has_glazing': True, 'glazing_coverage': 'most',
|
||||
'glazing_type': 'secondary', 'no_data': False},
|
||||
{'original_description': 'Mostly triple glazing', 'has_glazing': True, 'glazing_coverage': 'most',
|
||||
'glazing_type': 'triple', 'no_data': False},
|
||||
{'original_description': 'Multiple glazing throughout', 'has_glazing': True, 'glazing_coverage': 'full',
|
||||
'glazing_type': 'multiple', 'no_data': False},
|
||||
{'original_description': 'Partial double glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'double', 'no_data': False},
|
||||
{'original_description': 'Partial multiple glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'multiple', 'no_data': False},
|
||||
{'original_description': 'Partial secondary glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'secondary', 'no_data': False},
|
||||
{'original_description': 'Partial triple glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'triple', 'no_data': False},
|
||||
{'original_description': 'Single glazed', 'has_glazing': True, 'glazing_coverage': 'full', 'glazing_type': 'single',
|
||||
'no_data': False},
|
||||
{'original_description': 'Some double glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'double', 'no_data': False},
|
||||
{'original_description': 'Some multiple glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'multiple', 'no_data': False},
|
||||
{'original_description': 'Some secondary glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'secondary', 'no_data': False},
|
||||
{'original_description': 'Some triple glazing', 'has_glazing': True, 'glazing_coverage': 'partial',
|
||||
'glazing_type': 'triple', 'no_data': False}
|
||||
]
|
||||
Loading…
Add table
Reference in a new issue