Change rating calculation system to have good avg

This commit is contained in:
2017-04-18 01:49:32 +02:00
parent bf3682bd00
commit 9429aca981

View File

@@ -136,19 +136,22 @@ class ITunesParser:
# Add artist
if akey not in self._artists:
self._artists[akey] = {
'id': len(self._artists),
'id': len(self._artists), # TODO Calc an uniq ID (permit to replace data)
'name': akey,
'count': 0, 'plays': 0, 'rating': 0,
# TODO Use Rating with R upper case to be coherent with iTunes data
'genres': set()
}
# Compute information
rating = (track['Rating'] // 20) if 'Rating' in track else 0
# TODO Improve rating that currently can go ahead to 100
rating = track['Rating'] if 'Rating' in track else 0
# TODO If no Rating, don't take 0
plays = track['Play Count'] if 'Play Count' in track else 0
rating = self._calc_rating(rating, self._artists[akey]['rating'], self._artists[akey]['count'])
self._artists[akey]['count'] += 1
self._artists[akey]['rating'] += rating
self._artists[akey]['rating'] = rating
self._artists[akey]['plays'] += plays
if 'Genre' not in track:
@@ -172,18 +175,22 @@ class ITunesParser:
self._albums[akey] = {
'id': len(self._albums),
'name': akey,
'count': 0, 'plays': 0, 'rating': 0,
'count': 0, 'plays': 0, 'rating': 0,
# TODO Use Rating with R upper case to be coherent with iTunes data
'genres': set(),
'artist': set()
}
# Compute information
rating = (track['Rating'] // 20) if 'Rating' in track else 0
rating = track['Rating'] if 'Rating' in track else 0
# TODO Use Album Rating
# TODO If no Rating, don't take 0
plays = track['Play Count'] if 'Play Count' in track else 0
rating = self._calc_rating(rating, self._albums[akey]['rating'], self._albums[akey]['count'])
self._albums[akey]['count'] += 1
self._albums[akey]['rating'] += rating
# TODO Improve rating that currently can go ahead to 100
self._albums[akey]['rating'] = rating
self._albums[akey]['plays'] += plays
if 'Genre' not in track:
@@ -231,6 +238,9 @@ class ITunesParser:
file_albums.write(bytes("\n", 'UTF-8'))
file_albums.close()
def _calc_rating(self, added_value, current_rating, count):
return (current_rating * count + added_value) // (count + 1)
#### main block ####
# Default input & output files