Commit b0e86516 authored by Lukáš Lalinský's avatar Lukáš Lalinský

Fix track merging test

parent 19595769
# Copyright (C) 2011 Lukas Lalinsky
# Distributed under the MIT license, see the LICENSE file for details.
# minimum similarity with the best matching fingerprint
TRACK_MERGE_THRESHOLD = 0.7
# minimum similarity with the worst matching fingerprint
TRACK_GROUP_MERGE_THRESHOLD = 0.3
# minimum similarity for two fingerprints to be considered the same
FINGERPRINT_MERGE_THRESHOLD = 0.95
# how many items must a fingerprint have to be indexed
FINGERPRINT_MIN_UNIQUE_ITEMS = 30
......@@ -3,16 +3,12 @@
import logging
from sqlalchemy import sql
from acoustid import tables as schema
from acoustid import tables as schema, const
from acoustid.data.fingerprint import lookup_fingerprint, insert_fingerprint, inc_fingerprint_submission_count
from acoustid.data.musicbrainz import find_puid_mbids, resolve_mbid_redirect
from acoustid.data.track import insert_track, insert_mbid, insert_puid, merge_tracks, insert_track_meta, can_add_fp_to_track, can_merge_tracks
logger = logging.getLogger(__name__)
TRACK_MERGE_TRESHOLD = 0.7
FINGERPRINT_MERGE_TRESHOLD = 0.95
FINGERPRINT_MIN_UNIQUE_ITEMS = 30
def insert_submission(conn, data):
"""
......@@ -49,7 +45,7 @@ def import_submission(conn, submission):
logger.info("Importing submission %d with MBIDs %s",
submission['id'], ', '.join(mbids))
num_unique_items = len(set(submission['fingerprint']))
if num_unique_items < FINGERPRINT_MIN_UNIQUE_ITEMS:
if num_unique_items < const.FINGERPRINT_MIN_UNIQUE_ITEMS:
logger.info("Skipping, has only %d unique items", num_unique_items)
return
num_query_items = conn.execute("SELECT icount(acoustid_extract_query(%(fp)s))", dict(fp=submission['fingerprint']))
......@@ -58,7 +54,8 @@ def import_submission(conn, submission):
return
matches = lookup_fingerprint(conn,
submission['fingerprint'], submission['length'],
FINGERPRINT_MERGE_TRESHOLD, TRACK_MERGE_TRESHOLD, fast=True)
const.FINGERPRINT_MERGE_THRESHOLD,
const.TRACK_MERGE_THRESHOLD, fast=True)
fingerprint = {
'id': None,
'track_id': None,
......@@ -71,7 +68,7 @@ def import_submission(conn, submission):
match = matches[0]
logger.debug("Matches %d results, the top result %s with track %d is %d%% similar",
len(matches), match['id'], match['track_id'], match['score'] * 100)
if match['score'] > FINGERPRINT_MERGE_TRESHOLD:
if match['score'] > const.FINGERPRINT_MERGE_THRESHOLD:
fingerprint['id'] = match['id']
if can_add_fp_to_track(conn, match['track_id'], submission['fingerprint']):
fingerprint['track_id'] = match['track_id']
......
......@@ -3,7 +3,7 @@
import logging
from sqlalchemy import sql
from acoustid import tables as schema
from acoustid import tables as schema, const
logger = logging.getLogger(__name__)
......@@ -215,7 +215,7 @@ def can_merge_tracks(conn, track_ids):
rows = conn.execute(query)
merges = {}
for fp1_id, fp2_id, score in rows:
if score < 0.3:
if score < const.TRACK_GROUP_MERGE_THRESHOLD:
continue
group = fp1_id
if group in merges:
......@@ -233,7 +233,7 @@ def can_add_fp_to_track(conn, track_id, fingerprint):
sql.func.min(sql.func.acoustid_compare2(schema.fingerprint.c.fingerprint, fingerprint)),
], cond, from_obj=schema.fingerprint)
score = conn.execute(query).scalar()
if score < 0.3:
if score < const.TRACK_GROUP_MERGE_THRESHOLD:
return False
return True
......@@ -17,7 +17,7 @@ from tests import (
TEST_2_FP_RAW,
TEST_2_LENGTH,
)
from acoustid import tables
from acoustid import tables, const
from acoustid.data.meta import insert_meta
from acoustid.data.submission import insert_submission, import_submission, import_queued_submissions
......@@ -183,7 +183,7 @@ def test_import_submission_reuse_track_93(conn):
@with_database
def test_import_submission_new_track_55(conn):
def test_import_submission_new_track(conn):
prepare_database(conn, """
INSERT INTO fingerprint (fingerprint, length, track_id)
VALUES (%(fp)s, %(len)s, 1);
......@@ -198,7 +198,12 @@ def test_import_submission_new_track_55(conn):
query = tables.submission.select(tables.submission.c.id == id)
submission = conn.execute(query).fetchone()
assert_false(submission['handled'])
fingerprint = import_submission(conn, submission)
try:
old_threshold = const.TRACK_MERGE_THRESHOLD
const.TRACK_MERGE_THRESHOLD = 0.9
fingerprint = import_submission(conn, submission)
finally:
const.TRACK_MERGE_THRESHOLD = old_threshold
assert_equals(2, fingerprint['id'])
assert_equals(5, fingerprint['track_id'])
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment