From 9dd1bd8f512f200091f3929b1eb846d601aa17ed Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 17 Nov 2014 23:36:40 +0100 Subject: Changed rating calculation --- imdb-lookup/imdbinfo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/imdb-lookup/imdbinfo.py b/imdb-lookup/imdbinfo.py index 63daa21..748e872 100755 --- a/imdb-lookup/imdbinfo.py +++ b/imdb-lookup/imdbinfo.py @@ -7,6 +7,7 @@ import re import dbm import json import argparse +import math try: import tmdbsimple as tmdb @@ -99,13 +100,17 @@ def do_prune(args, imdb_ids): tmdbcache.prune(imdb_id) def do_rating(args, imdb_ids): + """Calculates a rating based on vote_average and vote_count. + See http://blog.moertel.com/posts/2006-01-17-mining-gold-from-the-internet-movie-database-part-1.html + for details""" with TMDBCache() as tmdbcache: infos = map(lambda imdb_id: tmdbcache.infos(imdb_id), imdb_ids) infos = filter(lambda i: "vote_average" in i and "vote_count" in i, infos) maxvotes = max(map(lambda i: i["vote_count"], infos)) - minvotes = min(map(lambda i: i["vote_count"], infos)) for info in infos: - info['rating'] = info["vote_average"] + 2*((float(info["vote_count"])/maxvotes) - 0.5) + f = math.sin(math.pi * ( info["vote_average"]/10.0 ) ) + d = (float(info["vote_count"]) / maxvotes) - 0.5 + info['rating'] = info["vote_average"] + 2 * d * f print "{rating:.02f} {imdb_id} {title:30s} avg={vote_average:.1f} count={vote_count:.0f}".format(**info) if __name__ == u"__main__": -- cgit v1.2.1