Skip to content

Commit

Permalink
Refactor channel_group_search implementation in tdm_loader
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
espenenesNOV committed Mar 20, 2024
1 parent d390e77 commit b4f8f4f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions tdm_loader/tdm_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b4f8f4f

Please sign in to comment.