diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2014-11-17 23:36:40 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2014-11-17 23:36:45 +0100 |
commit | 9dd1bd8f512f200091f3929b1eb846d601aa17ed (patch) | |
tree | 91080df40a5fdea5841e8640a0ae50311614ec4f | |
parent | 522517568d71d7ad0688422b64c48387aafee026 (diff) | |
download | scripts-9dd1bd8f512f200091f3929b1eb846d601aa17ed.tar.gz scripts-9dd1bd8f512f200091f3929b1eb846d601aa17ed.zip |
Changed rating calculation
-rwxr-xr-x | imdb-lookup/imdbinfo.py | 9 |
1 files 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__": |