From 3cffb748ad86cf224aec52e8f4e726ea60839477 Mon Sep 17 00:00:00 2001 From: EspenEnes Date: Fri, 22 Mar 2024 10:16:34 +0100 Subject: [PATCH] Refactor channel_group_search implementation in tdm_loader (#27) * Refactor channel_group_search implementation in tdm_loader When searching and resulting groups has identical channel group names, only the first channel group index is returned New logic will look at channel group names together with occurrences to find the correct channel group index. * Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener * Simplify channel group search logic in tdm_loader The previous implementation counted and used the number of times a channel group name appeared, which added extra complexity to the search logic. The new logic simplifies this process by directly appending the names to the found_terms list and by making the search case- and space-insensitive. * Refactor search logic in tdm_loader for channel group names Switched from a for-loop and conditional check structure to an inline list comprehension to search for channel group names. The aim of this refactor is to simplify the code and improve readability, while maintaining the functionality of ignoring None values and retaining valid group names. * Update return type in tdm_loader Changed the return type of a function in tdm_loader from a list to a set. This modification ensures unique channel group names are returned from the function, thus improving the accuracy of the channel search process. * Removed the use of set when returning search results from channel_group_search * Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener * Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener * Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener --------- Co-authored-by: Espen Enes Co-authored-by: Florian Dobener --- tdm_loader/tdm_loader.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index 707f554..4c39e19 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -199,8 +199,10 @@ def channel_group_search(self, search_term): ind = [] for name in found_terms: - i = chg_names.index(name) - ind.append((name, i)) + for occurence in range(found_terms.count(name)): + i = self.channel_group_index(name, occurence) + if (name, i) not in ind: + ind.append((name, i)) return ind