mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
from typing import Dict, Union
|
|
from epc_data.attributes.attribute_utils import clean_description, process_part
|
|
|
|
|
|
class WindowAttributes:
|
|
GLAZING_KEYWORDS = ["glazing", "glazed", "glaze"]
|
|
GLAZING_COVERAGE = ["fully", "mostly", "partial", "some"]
|
|
GLAZING_TYPES = ["double", "triple", "secondary", "multiple", "high performance"]
|
|
|
|
def __init__(self, description: str):
|
|
self.description: str = clean_description(description.lower())
|
|
|
|
# In the case of an empty description, we want to return a dictionary with all values set to False
|
|
# and indicate there was no data
|
|
self.nodata = not description
|
|
|
|
if not self.nodata:
|
|
if not any(
|
|
rt in self.description for rt in
|
|
self.GLAZING_KEYWORDS + self.GLAZING_COVERAGE + self.GLAZING_TYPES
|
|
):
|
|
raise ValueError('Invalid description')
|
|
|
|
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
|
|
}
|
|
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(',')
|
|
|
|
# Process each part separately
|
|
for part in description:
|
|
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_')
|
|
|
|
return result
|