mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
69 lines
2.6 KiB
Python
69 lines
2.6 KiB
Python
import re
|
|
from model_data.epc_attributes.attribute_utils import clean_description
|
|
from model_data.utils import correct_spelling
|
|
|
|
|
|
class LightingAttributes:
|
|
WELSH_TEXT = {
|
|
"goleuadau ynni-isel ym mhob un ogçör mannau gosod": "low energy lighting in all fixed outlets",
|
|
"dim goleuadau ynni-isel": "no low energy lighting",
|
|
"goleuadau ynni-isel ym mhob un o'r mannau gosod": 'Low energy lighting in all fixed outlets'
|
|
}
|
|
|
|
def __init__(self, description, averages):
|
|
self.description: str = clean_description(description.lower())
|
|
|
|
self.welsh_translation_search()
|
|
|
|
self.description = correct_spelling(self.description)
|
|
self.averages = averages
|
|
|
|
def welsh_translation_search(self):
|
|
"""
|
|
For welsh text describing the percentage of low energy lighting, we match the regular
|
|
expression and perform the translation
|
|
"""
|
|
lel_match = re.search(r"goleuadau ynni-isel mewn (\d+)%? ogçör mannau gosod", self.description)
|
|
lel_match2 = re.search(r"goleuadau ynni-isel mewn (\d+)%? o'r mannau gosod", self.description)
|
|
|
|
if lel_match is not None or lel_match2 is not None:
|
|
|
|
# Perform the actual translation
|
|
percentage = lel_match.group(1) if lel_match is not None else lel_match2.group(1)
|
|
self.description = f"low energy lighting in {percentage}% of fixed outlets"
|
|
else:
|
|
translation = self.WELSH_TEXT.get(self.description)
|
|
if translation:
|
|
self.description = translation
|
|
|
|
def process(self):
|
|
|
|
description = self.description
|
|
|
|
if 'no low energy lighting' in description:
|
|
return {"low_energy_proportion": 0}
|
|
|
|
if "all fixed outlets" in description:
|
|
return {"low_energy_proportion": 1}
|
|
|
|
if "excellent lighting efficiency" in description:
|
|
return {"low_energy_proportion": 1}
|
|
|
|
if ('good lighting efficiency' in description) or ('excellent lighting efficiency' in description) or \
|
|
('below average lighting efficiency' in description):
|
|
average = [
|
|
x for x in self.averages if x["lighting-description"] == description
|
|
][0]["low-energy-lighting"]
|
|
|
|
return {
|
|
"low_energy_proportion": average
|
|
}
|
|
|
|
match = re.search(r'\d+', description)
|
|
if match:
|
|
proportion = int(match.group()) / 100.0
|
|
return {
|
|
"low_energy_proportion": proportion
|
|
}
|
|
|
|
raise NotImplementedError("Not handled this case - investigate me")
|