mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
53 lines
1.7 KiB
Python
53 lines
1.7 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"
|
|
}
|
|
|
|
def __init__(self, description, averages):
|
|
self.description: str = clean_description(description.lower())
|
|
|
|
translation = self.WELSH_TEXT.get(self.description)
|
|
if translation:
|
|
self.nodata = False
|
|
self.description = translation
|
|
|
|
self.description = correct_spelling(self.description)
|
|
self.averages = averages
|
|
|
|
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")
|