mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Debugging roof and lighting welsh translations
This commit is contained in:
parent
1a1cf80d7e
commit
4edf4ceedb
3 changed files with 25 additions and 5 deletions
|
|
@ -5,7 +5,8 @@ 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"
|
||||
"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):
|
||||
|
|
|
|||
|
|
@ -22,16 +22,34 @@ class RoofAttributes(Definitions):
|
|||
self.description: str = description.lower()
|
||||
self.nodata = not description or description in self.DATA_ANOMALY_MATCHES
|
||||
|
||||
translation = self.WELSH_TEXT.get(self.description)
|
||||
if translation:
|
||||
self.nodata = False
|
||||
self.description = translation
|
||||
self.welsh_translation_search()
|
||||
|
||||
if not self.nodata and not any(
|
||||
rt in self.description for rt in self.ROOF_TYPES + self.DWELLING_ABOVE + ["average thermal transmittance"]
|
||||
):
|
||||
raise ValueError('Invalid description')
|
||||
|
||||
def welsh_translation_search(self):
|
||||
"""
|
||||
For some descriptions,
|
||||
we want to translate, however they have a consistent structure, where the only change
|
||||
is the thickness of insulation. Instead of manually adding a record for each translation, we
|
||||
search for regular expressions and translate
|
||||
"""
|
||||
|
||||
insulation_thickness_match = re.search(r"(\d+ mm) o inswleiddio yn y llofft", self.description)
|
||||
|
||||
# Step 2: Generalized translation with placeholder
|
||||
if insulation_thickness_match:
|
||||
insulation_thickness = insulation_thickness_match.group(1)
|
||||
self.description = self.description.replace(insulation_thickness_match.group(0), "")
|
||||
self.description = f"pitched, {insulation_thickness} loft insulation"
|
||||
else:
|
||||
translation = self.WELSH_TEXT.get(self.description)
|
||||
if translation:
|
||||
self.nodata = False
|
||||
self.description = translation
|
||||
|
||||
def process(self) -> Dict[str, Union[float, str, bool, None]]:
|
||||
|
||||
result: Dict[str, Union[float, str, bool, None]] = {}
|
||||
|
|
|
|||
|
|
@ -32,4 +32,5 @@ test_cases = [
|
|||
{'original_description': 'No Low energy lighting', 'low_energy_proportion': 0},
|
||||
{'original_description': 'Goleuadau ynni-isel mewn 60% oGÇÖr mannau gosod', 'low_energy_proportion': 0.6},
|
||||
{'original_description': 'Goleuadau ynni-isel ym mhob un oGÇÖr mannau gosod', 'low_energy_proportion': 1},
|
||||
{'original_description': 'Dim goleuadau ynni-isel', 'low_energy_proportion': 0},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue