From b4f8f4fde17afe14ce1de92a77d3204d33baab25 Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Wed, 20 Mar 2024 20:28:10 +0100 Subject: [PATCH 1/9] 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. --- tdm_loader/tdm_loader.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index 707f554..755bef6 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -185,22 +185,27 @@ def channel_group_search(self, search_term): if not isinstance(search_term, str): raise TypeError("I can search for str terms only.") - chg_names = [ - x.text - for x in self._root.findall(".//tdm_channelgroup/name") - if x.text is not None - ] + group_names = {} + chg_names = [] + for x in self._root.findall(".//tdm_channelgroup/name"): + if x.text is not None: + if x.text not in group_names: + group_names[x.text] = 0 + else: + group_names[x.text] += 1 + chg_names.append((f"{x.text}", group_names[x.text])) + search_term = search_term.upper().replace(" ", "") found_terms = [ name for name in chg_names - if name.upper().replace(" ", "").find(search_term) >= 0 + if name[0].upper().replace(" ", "").find(search_term) >= 0 ] ind = [] for name in found_terms: - i = chg_names.index(name) - ind.append((name, i)) + i = self.channel_group_index(name[0], name[1]) + ind.append((name[0], i)) return ind From ecf15ee3df6d10647dd81b62bcb2d0f168bfbadf Mon Sep 17 00:00:00 2001 From: EspenEnes Date: Thu, 21 Mar 2024 06:07:16 +0100 Subject: [PATCH 2/9] Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener --- tdm_loader/tdm_loader.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index 755bef6..e122a1a 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -204,8 +204,9 @@ def channel_group_search(self, search_term): ind = [] for name in found_terms: - i = self.channel_group_index(name[0], name[1]) - ind.append((name[0], i)) + for occurence in range(found_terms.count(name)): + i = self.channel_group_index(name, occurence) + ind.append((name, i)) return ind From bbfb1c294e5d26fbc58d6b386976f01eecee2d46 Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Thu, 21 Mar 2024 06:15:58 +0100 Subject: [PATCH 3/9] 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. --- tdm_loader/tdm_loader.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index e122a1a..015206d 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -189,17 +189,13 @@ def channel_group_search(self, search_term): chg_names = [] for x in self._root.findall(".//tdm_channelgroup/name"): if x.text is not None: - if x.text not in group_names: - group_names[x.text] = 0 - else: - group_names[x.text] += 1 - chg_names.append((f"{x.text}", group_names[x.text])) + chg_names.append(x.text) search_term = search_term.upper().replace(" ", "") found_terms = [ name for name in chg_names - if name[0].upper().replace(" ", "").find(search_term) >= 0 + if name.upper().replace(" ", "").find(search_term) >= 0 ] ind = [] From 11d2861161894c40591bd5426eb74b35bfa480ef Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Thu, 21 Mar 2024 06:19:14 +0100 Subject: [PATCH 4/9] 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. --- tdm_loader/tdm_loader.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index 015206d..bafb4e0 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -185,11 +185,11 @@ def channel_group_search(self, search_term): if not isinstance(search_term, str): raise TypeError("I can search for str terms only.") - group_names = {} - chg_names = [] - for x in self._root.findall(".//tdm_channelgroup/name"): - if x.text is not None: - chg_names.append(x.text) + chg_names = [ + x.text + for x in self._root.findall(".//tdm_channelgroup/name") + if x.text is not None + ] search_term = search_term.upper().replace(" ", "") found_terms = [ From 96a49fc66e64879dbdc6384e95af348ce8605386 Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Thu, 21 Mar 2024 08:35:27 +0100 Subject: [PATCH 5/9] 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. --- tdm_loader/tdm_loader.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index bafb4e0..df878cc 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -204,7 +204,7 @@ def channel_group_search(self, search_term): i = self.channel_group_index(name, occurence) ind.append((name, i)) - return ind + return set(ind) def channel_search(self, search_term): """Returns a list of channel names that contain ``search term``. From 1837a926352c8d33c0fa9b1f5ba49c83edb75a40 Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Thu, 21 Mar 2024 14:23:17 +0100 Subject: [PATCH 6/9] Removed the use of set when returning search results from channel_group_search --- tdm_loader/tdm_loader.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index df878cc..8c8642a 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -199,12 +199,15 @@ def channel_group_search(self, search_term): ] ind = [] + occurences = {} for name in found_terms: - for occurence in range(found_terms.count(name)): - i = self.channel_group_index(name, occurence) - ind.append((name, i)) + if name not in occurences: + occurences[name] = True + for occurence in range(found_terms.count(name)): + i = self.channel_group_index(name, occurence) + ind.append((name, i)) - return set(ind) + return ind def channel_search(self, search_term): """Returns a list of channel names that contain ``search term``. From 811a68c2ea68154cf697f778e4e86e4379d5ab71 Mon Sep 17 00:00:00 2001 From: EspenEnes Date: Thu, 21 Mar 2024 18:11:55 +0100 Subject: [PATCH 7/9] Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener --- tdm_loader/tdm_loader.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index 8c8642a..e5c9b26 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -201,11 +201,10 @@ def channel_group_search(self, search_term): ind = [] occurences = {} for name in found_terms: - if name not in occurences: - occurences[name] = True - for occurence in range(found_terms.count(name)): - i = self.channel_group_index(name, occurence) - 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 From 546c23eb82581fd74d8a14deb17acd56bd4024c2 Mon Sep 17 00:00:00 2001 From: EspenEnes Date: Thu, 21 Mar 2024 18:12:17 +0100 Subject: [PATCH 8/9] Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener --- tdm_loader/tdm_loader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index e5c9b26..ad03daa 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -199,7 +199,6 @@ def channel_group_search(self, search_term): ] ind = [] - occurences = {} for name in found_terms: for occurence in range(found_terms.count(name)): i = self.channel_group_index(name, occurence) From ec7689f38517b3e95f19aeb0998355fa0e689a5f Mon Sep 17 00:00:00 2001 From: EspenEnes Date: Thu, 21 Mar 2024 18:12:25 +0100 Subject: [PATCH 9/9] Update tdm_loader/tdm_loader.py Co-authored-by: Florian Dobener --- tdm_loader/tdm_loader.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tdm_loader/tdm_loader.py b/tdm_loader/tdm_loader.py index ad03daa..4c39e19 100644 --- a/tdm_loader/tdm_loader.py +++ b/tdm_loader/tdm_loader.py @@ -190,7 +190,6 @@ def channel_group_search(self, search_term): for x in self._root.findall(".//tdm_channelgroup/name") if x.text is not None ] - search_term = search_term.upper().replace(" ", "") found_terms = [ name