name:
src/python/fingerprinter/fingerprint_record.py
-rw-r--r--
938
1class FingerprintRecord(object):
2 """
3 Represents a single hash of a fingerprint record from the database
4 """
5
6 def __init__(self, hash_id, episode, play_head):
7 self.hash_id = hash_id
8 self.episode = episode
9 self.play_head = play_head
10
11 def __str__(self):
12 return "hash:{} episode:{} playhead:{}".format(self.hash_id, self.episode, self.play_head)
13
14MATCH_RATIO_THRESHOLD = 0.1
15
16def determine_match(records):
17 """
18 Determines a match based on frequency of episode in records.
19 :param records: FingerprintRecords
20 :return: episode match string, or None, if no match found.
21 """
22 histogram = {}
23 for record in records:
24 if record.episode in histogram:
25 histogram[record.episode] += 1
26 else:
27 histogram[record.episode] = 1
28 s = sorted(histogram.iteritems(), key=lambda (k, v): v)
29 match = s[-1]
30 if match[1] > int(MATCH_RATIO_THRESHOLD * len(records)):
31 return match[0]
32 else:
33 return None