From 7a57208767dcdebdc908885be23942e515a34a6b Mon Sep 17 00:00:00 2001 From: AlexisTres <81624964+AlexisTres@users.noreply.github.com> Date: Thu, 2 Jun 2022 15:13:51 +0200 Subject: [PATCH 1/3] Fix get_data slow when label_type == "name" (#55) * change get_data with "name" label_type --- braincube_connector/memory_base/memory_base.py | 5 ++++- tests/test_memory_base/test_memory_base.py | 9 +++++---- tests_integration/mocks.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/braincube_connector/memory_base/memory_base.py b/braincube_connector/memory_base/memory_base.py index e57f3a8..14ad72a 100644 --- a/braincube_connector/memory_base/memory_base.py +++ b/braincube_connector/memory_base/memory_base.py @@ -150,7 +150,10 @@ def get_data( datasource = data.collect_data(int_var_ids, self, filters) if label_type == "name": - mapping = {var_id: self.get_variable(var_id).get_name() for var_id in int_var_ids} + mapping = { + int(collected_variable.get_bcid()): collected_variable.get_name() + for collected_variable in self.get_variable_list() + } datasource = { mapping[data_key]: data_value for data_key, data_value in datasource.items() } diff --git a/tests/test_memory_base/test_memory_base.py b/tests/test_memory_base/test_memory_base.py index 3abdaab..a2b337e 100644 --- a/tests/test_memory_base/test_memory_base.py +++ b/tests/test_memory_base/test_memory_base.py @@ -157,10 +157,11 @@ def test_get_rule_list(mocker, monkeypatch, mb_obj, mock_request_entity): ) def test_get_data(mocker, mb_obj, create_mock_var, label_type, dataframe, expected_data): mocker.patch( - "braincube_connector.memory_base.memory_base.MemoryBase.get_variable", - lambda memory_base_object, bcid: create_mock_var( - bcid=bcid, metadata={"standard": "name_standard_{0}".format(bcid)} - ), + "braincube_connector.memory_base.memory_base.MemoryBase.get_variable_list", + return_value=[ + create_mock_var(bcid=1, metadata={"standard": "name_standard_1"}), + create_mock_var(bcid=2, metadata={"standard": "name_standard_2"}), + ], ) mocker.patch( diff --git a/tests_integration/mocks.py b/tests_integration/mocks.py index d588d50..16a7cdf 100644 --- a/tests_integration/mocks.py +++ b/tests_integration/mocks.py @@ -49,6 +49,24 @@ "status": 200, "json": {"name": "mb1", "order": "mb1/d101",}, }, + { + "method": "GET", + "url": "https://api.test.com/braincube/demo/braincube/mb/1/variables/summary?offset=0&size=150", + "status": 200, + "json": { + "items": [ + {"bcId": 101, "tag": "tag_101", "local": "local_101", "standard": "standard_101",}, + {"bcId": 102, "tag": "tag_102", "local": "local_102", "standard": "standard_102",}, + {"bcId": 103, "tag": "tag_103", "local": "local_103", "standard": "standard_103",}, + ] + }, + }, + { + "method": "GET", + "url": "https://api.test.com/braincube/demo/braincube/mb/1/variables/summary?offset=150&size=150", + "status": 200, + "json": {"items": []}, + }, { "method": "POST", "url": "https://api.test.com/braincube/demo/braindata/mb1/LF", From 745dc77101fd5bb99f2e1b53a00f3d50f820f50a Mon Sep 17 00:00:00 2001 From: Alexis TRESCARTE Date: Thu, 2 Jun 2022 15:28:31 +0200 Subject: [PATCH 2/3] Update ChangeLog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3126931..cf44c98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### FIXED + +- #[29](https://github.com/braincube-io/python-connector/issues/29): Fix `{get_data}` very slow when using `{label_type="name"}` + ## [2.5.1 - 2021-10-25](https://github.com/braincube-io/python-connector/compare/2.5.0...2.5.1) ### FIXED From a1d956defbb91d16633c1b3b97f140e5dbe214d2 Mon Sep 17 00:00:00 2001 From: AlexisTres <81624964+AlexisTres@users.noreply.github.com> Date: Fri, 3 Jun 2022 09:18:28 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Maxime Morille --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf44c98..8390d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.5.2 - 2022-06-02](https://github.com/braincube-io/python-connector/compare/2.5.1...2.5.2) + ### FIXED - #[29](https://github.com/braincube-io/python-connector/issues/29): Fix `{get_data}` very slow when using `{label_type="name"}`