From f86a466f3d26e75f26b9e20f5df5b29c6801f3f6 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 19 Sep 2023 17:31:55 +0100 Subject: [PATCH] Added extra translation for lighting --- model_data/cleaner_app.py | 8 -------- model_data/epc_attributes/LightingAttributes.py | 7 ++++--- .../test_data/test_lighting_attributes_cases.py | 1 + model_data/tests/test_lighting_attributes.py | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/model_data/cleaner_app.py b/model_data/cleaner_app.py index cf56675d..1ccb6238 100644 --- a/model_data/cleaner_app.py +++ b/model_data/cleaner_app.py @@ -34,14 +34,6 @@ def app(): Currently, this application is just run on a local machine """ - # mainheat control todos: - # [x]'System dalu wediGÇÖi chysylltu +ó defnyddio gwres cymunedol, rhaglennydd a TRVs' - # [x]'System dalu wediGÇÖi chysylltu +ó defnyddio gwres cymunedol, TRVs' - # [x] 'T+-ól un gyfradd, TRVs' - # [x]'T+ól un gyfradd, rhaglennydd a TRVs' - # [x]'T+ól un gyfradd, TRVs' - # 'TRVs a falf osgoi' - cleaned_data = {} epc_directories = [entry for entry in EPC_DIRECTORY.iterdir() if entry.is_dir()] for directory in tqdm(epc_directories): diff --git a/model_data/epc_attributes/LightingAttributes.py b/model_data/epc_attributes/LightingAttributes.py index 94285170..83e9ef5f 100644 --- a/model_data/epc_attributes/LightingAttributes.py +++ b/model_data/epc_attributes/LightingAttributes.py @@ -24,15 +24,16 @@ class LightingAttributes: 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: + if lel_match is not None or lel_match2 is not None: + # Perform the actual translation - percentage = lel_match.group(1) + 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.nodata = False self.description = translation def process(self): diff --git a/model_data/tests/test_data/test_lighting_attributes_cases.py b/model_data/tests/test_data/test_lighting_attributes_cases.py index 0a8fa6cf..f76b2d80 100644 --- a/model_data/tests/test_data/test_lighting_attributes_cases.py +++ b/model_data/tests/test_data/test_lighting_attributes_cases.py @@ -35,4 +35,5 @@ test_cases = [ {'original_description': 'Dim goleuadau ynni-isel', 'low_energy_proportion': 0}, {'original_description': 'Excellent lighting efficiency', 'low_energy_proportion': 1}, {'original_description': "Goleuadau ynni-isel ym mhob un o'r mannau gosod", 'low_energy_proportion': 1}, + {'original_description': "Goleuadau ynni-isel mewn 17% o'r mannau gosod", 'low_energy_proportion': 0.17}, ] diff --git a/model_data/tests/test_lighting_attributes.py b/model_data/tests/test_lighting_attributes.py index 392e10d7..38219e86 100644 --- a/model_data/tests/test_lighting_attributes.py +++ b/model_data/tests/test_lighting_attributes.py @@ -56,3 +56,17 @@ class TestLightingAttributes: del expected_result["original_description"] result = LightingAttributes(test_case['original_description'], averages).process() assert sorted(result.items()) == sorted(expected_result.items()) + + def test_regex_translations(self): + """ + Some of the regex translations were falling through the net, though we were pulling out the percentages + so we just make sure we're translating correctly + """ + + init1 = LightingAttributes("Goleuadau ynni-isel mewn 17% o'r mannau gosod", []) + + assert init1.description == 'low energy lighting in 17% of fixed outlets' + + init2 = LightingAttributes("Goleuadau ynni-isel mewn 60% oGÇÖr mannau gosod", []) + + assert init2.description == 'low energy lighting in 60% of fixed outlets'