summaryrefslogtreecommitdiff
path: root/imdb-lookup/imdbinfo.py
diff options
context:
space:
mode:
Diffstat (limited to 'imdb-lookup/imdbinfo.py')
-rwxr-xr-ximdb-lookup/imdbinfo.py9
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__":