fixes #1 and fixes #2. also identifies issue with DELETE_ORPHANS sql command

This commit is contained in:
worldveil 2013-11-29 22:08:25 -05:00
parent 90a93bc47b
commit 51680735db
3 changed files with 20 additions and 13 deletions

View file

@ -1,5 +1,5 @@
from dejavu.database import SQLDatabase
from dejavu.converter import Converter
from dejavu.convert import Converter
from dejavu.fingerprint import Fingerprinter
from scipy.io import wavfile
from multiprocessing import Process
@ -62,8 +62,9 @@ class Dejavu():
p.join()
# delete orphans
print "Done fingerprinting. Deleting orphaned fingerprints..."
self.fingerprinter.db.delete_orphans()
# print "Done fingerprinting. Deleting orphaned fingerprints..."
# TODO: need a more performant query in database.py for the
#self.fingerprinter.db.delete_orphans()
def fingerprint_worker(self, files, sql_connection, output):

View file

@ -102,7 +102,11 @@ class SQLDatabase():
# delete
DELETE_UNFINGERPRINTED = "DELETE FROM %s WHERE %s = 0;" % (SONGS_TABLENAME, FIELD_FINGERPRINTED)
DELETE_ORPHANS = ""
DELETE_ORPHANS = """
delete from fingerprints
where not exists (
select * from songs where fingerprints.song_id = songs.song_id
)"""
def __init__(self, hostname, username, password, database):
# connect
@ -154,13 +158,14 @@ class SQLDatabase():
def delete_orphans(self):
try:
self.cursor = self.connection.cursor()
self.cursor.execute(SQLDatabase.DELETE_ORPHANS)
self.connection.commit()
### TODO: SQLDatabase.DELETE_ORPHANS is not performant enough, need better query
### to delete fingerprints for which no song is tied to.
#self.cursor.execute(SQLDatabase.DELETE_ORPHANS)
#self.connection.commit()
except mysql.Error, e:
print "Error in delete_orphans(), %d: %s" % (e.args[0], e.args[1])
self.connection.rollback()
def delete_unfingerprinted_songs(self):
try:
self.cursor = self.connection.cursor()

View file

@ -197,13 +197,14 @@ class Fingerprinter():
largest_count = diff_counter[diff][sid]
song_id = sid
if verbose: print "Diff is %d with %d offset-aligned matches" % (largest, largest_count)
if verbose:
print "Diff is %d with %d offset-aligned matches" % (largest, largest_count)
#from collections import OrderedDict
#print OrderedDict(diff_counter)
# extract idenfication
songname = self.db.get_song_by_id(song_id)[SQLDatabase.FIELD_SONGNAME]
# extract idenfication
song = self.db.get_song_by_id(song_id)
songname = song.get(SQLDatabase.FIELD_SONGNAME, None)
if not songname:
return None
songname = songname.replace("_", " ")
elapsed = time.time() - starttime