Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor channel_group_search implementation in tdm_loader #27

Merged
merged 9 commits into from
Mar 22, 2024
Next Next commit
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.
espenenesNOV committed Mar 20, 2024
commit b4f8f4fde17afe14ce1de92a77d3204d33baab25
21 changes: 13 additions & 8 deletions tdm_loader/tdm_loader.py
Original file line number Diff line number Diff line change
@@ -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]))
domna marked this conversation as resolved.
Show resolved Hide resolved

EspenEnes marked this conversation as resolved.
Show resolved Hide resolved
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))
EspenEnes marked this conversation as resolved.
Show resolved Hide resolved

return ind