Skip to content

Commit

Permalink
PICARD-2584: Exclude AcoustID results without metadata and less then …
Browse files Browse the repository at this point in the history
…25% submission count
  • Loading branch information
phw committed Dec 27, 2023
1 parent e793e90 commit f1aa249
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions picard/acoustid/recordings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
from picard.webservice.api_helpers import MBAPIHelper


# Only do extra lookup for recordings without metadata, if they have at least
# this percentage of sources compared to the recording with most sources.
SOURCE_THRESHOLD_NO_METADATA = 0.25


class Recording:
recording: dict
result_score: float
Expand Down Expand Up @@ -74,6 +79,7 @@ def resolve(self) -> None:
recordings = result.get('recordings') or []
result_score = get_score(result)
acoustid = result.get('id')
max_sources = max_source_count_raw_recording(recordings)
for recording in recordings:
mbid = recording.get('id')
sources = recording.get('sources', 1)
Expand All @@ -86,12 +92,13 @@ def resolve(self) -> None:
sources=sources,
)
else:
self._missing_metadata.append(IncompleteRecording(
mbid=mbid,
acoustid=acoustid,
result_score=result_score,
sources=sources,
))
if sources / max_sources > SOURCE_THRESHOLD_NO_METADATA:
self._missing_metadata.append(IncompleteRecording(
mbid=mbid,
acoustid=acoustid,
result_score=result_score,
sources=sources,
))

if self._missing_metadata:
self._load_recordings()
Expand Down Expand Up @@ -172,3 +179,12 @@ def max_source_count(recordings: List[Recording]):
sources = {r.sources for r in recordings}
sources.add(1)
return max(sources)


def max_source_count_raw_recording(recordings: List[dict]):
"""Given a list of recordings return the highest number of sources.
This ignores recordings without metadata.
"""
sources = {r.get('sources', 1) for r in recordings}
sources.add(1)
return max(sources)

0 comments on commit f1aa249

Please sign in to comment.