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

Fix User Matching Interaction #138

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions metrontagger/talker.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def _extract_id_str(notes: str, keyword: str) -> str:

return source, id_

def _process_file(self: Talker, fn: Path, interactive: bool) -> tuple[int | None, bool]: # noqa: PLR0912 PLR0915
def _process_file(self: Talker, fn: Path, interactive: bool) -> tuple[int | None, bool]: # noqa: PLR0912 PLR0911
"""Process a comic file for metadata.

This method processes a comic file to extract metadata, including checking for existing metadata, extracting
Expand Down Expand Up @@ -317,38 +317,43 @@ def _print_metadata_message(src: InfoSource, comic: Comic) -> None:
i_list = self.api.issues_list(params=params)
result_count = len(i_list)

issue_id = None
multiple_match = False
# No matches
if result_count <= 0:
issue_id = None
self.match_results.add_no_match(fn)
multiple_match = False
elif result_count > 1:
# Let's use the cover hash to try to narrow down the results
return None, False

# Multiple matches
if result_count > 1:
LOGGER.debug("Check Hamming for '%s'", ca)
if hamming_lst := self._get_hamming_results(ca, i_list):
hamming_lst = self._get_hamming_results(ca, i_list)
if hamming_lst:
if len(hamming_lst) == 1:
issue_id = hamming_lst[0].id
self.match_results.add_good_match(fn)
# TODO: Need to handle situation where *None* of the choices match.
elif issue_id := self._select_choice_from_matches(fn, hamming_lst):
self.match_results.add_good_match(fn)
else:
issue_id = None
self.match_results.add_multiple_match(MultipleMatch(fn, i_list))
multiple_match = True
elif result_count == 1:
# Let's see if the cover is correct otherwise ask for user to select issue.
if not interactive and self._within_hamming_distance(ca, i_list[0].cover_hash):
issue_id = i_list[0].id
self.match_results.add_good_match(fn)
else:
issue_id = self._select_choice_from_matches(fn, i_list)
return hamming_lst[0].id, False
issue_id = self._select_choice_from_matches(fn, hamming_lst)
if issue_id:
self.match_results.add_good_match(fn)
multiple_match = False
return issue_id, False
self.match_results.add_multiple_match(MultipleMatch(fn, i_list))
return None, True

return issue_id, multiple_match
# Ask for user interaction for each comic.
if interactive:
issue_id = self._select_choice_from_matches(fn, i_list)
if issue_id:
self.match_results.add_good_match(fn)
return issue_id, False
self.match_results.add_multiple_match(MultipleMatch(fn, i_list))
return None, True

# Single match within the hamming distance
if self._within_hamming_distance(ca, i_list[0].cover_hash):
self.match_results.add_good_match(fn)
return i_list[0].id, False

# Single match not withing the hamming distance. We'll ask if the single choice is correct.
self.match_results.add_multiple_match(MultipleMatch(fn, i_list))
return None, True

def _post_process_matches(self: Talker) -> None:
"""Post-process the match results.
Expand Down
Loading