def get_cur_artist(items): """Given a sequence of items, returns the current artist and artist ID that is most popular among the fingerprinted metadata for the tracks. """ # Get "fingerprinted" artists for each track. artists = [] artist_ids = [] for item in items: last_data = match(item.path) if last_data: artists.append(last_data['artist']) if last_data['artist_mbid']: artist_ids.append(last_data['artist_mbid']) # Vote on the most popular artist. artist, _ = autotag._plurality(artists) artist_id, _ = autotag._plurality(artist_ids) return artist, artist_id
def test_plurality_conflict(self): objs = [1, 1, 2, 2, 3] obj = autotag._plurality(objs) self.assert_(obj in (1, 2))
def test_plurality_near_consensus(self): objs = [1, 1, 2, 1] obj = autotag._plurality(objs) self.assertEqual(obj, 1)
def test_plurality_conflict(self): objs = [1, 1, 2, 2, 3] obj, consensus = autotag._plurality(objs) self.assert_(obj in (1, 2)) self.assertFalse(consensus)
def test_plurality_consensus(self): objs = [1, 1, 1, 1] obj, consensus = autotag._plurality(objs) self.assertEqual(obj, 1) self.assertTrue(consensus)
def test_plurality_near_consensus(self): objs = [1, 1, 2, 1] obj, consensus = autotag._plurality(objs) self.assertEqual(obj, 1) self.assertFalse(consensus)