From b4f8f4fde17afe14ce1de92a77d3204d33baab25 Mon Sep 17 00:00:00 2001 From: Espen Enes Date: Wed, 20 Mar 2024 20:28:10 +0100 Subject: [PATCH] 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