Fix bad rating calculation

This commit is contained in:
2017-04-19 22:40:59 +02:00
parent b4f37029a3
commit 447ade9a86

View File

@@ -219,6 +219,7 @@ class ITunesParser:
file_artist = io.open('es-artist-data.json', 'wb') file_artist = io.open('es-artist-data.json', 'wb')
for artist in self._artists: for artist in self._artists:
persistent_id = self._artists[artist]['Persistent ID'] persistent_id = self._artists[artist]['Persistent ID']
self._artists[artist]['Rating'] = round(self._artists[artist]['Rating'])
json_track_index = { json_track_index = {
"index": {"_index": "itunessongs", "_type": "artist", "_id": persistent_id} "index": {"_index": "itunessongs", "_type": "artist", "_id": persistent_id}
} }
@@ -236,6 +237,7 @@ class ITunesParser:
file_albums = io.open('es-albums-data.json', 'wb') file_albums = io.open('es-albums-data.json', 'wb')
for album in self._albums: for album in self._albums:
persistent_id = self._albums[album]['Persistent ID'] persistent_id = self._albums[album]['Persistent ID']
self._albums[album]['Rating'] = round(self._albums[album]['Rating'])
json_track_index = { json_track_index = {
"index": {"_index": "itunessongs", "_type": "album", "_id": persistent_id} "index": {"_index": "itunessongs", "_type": "album", "_id": persistent_id}
} }
@@ -250,7 +252,7 @@ class ITunesParser:
""" """
Calculate average rating from a current rating, a rating value to add and the number of elements Calculate average rating from a current rating, a rating value to add and the number of elements
""" """
return (current_rating * count + added_value) // (count + 1) return (current_rating * count + added_value) / (count + 1)
@classmethod @classmethod
def calc_id(cls, key): def calc_id(cls, key):