Mercurial > hg > rlgallery-misc
view py/stats.py @ 21:453278a81371
Add tablerecent() so recent.cgi will work as before.
Port the tablerecent() function, which reads the most recent games
directly from the logfile instead of the database. This allows
recent.cgi to show games immediately without waiting for the recorder
to put them in the database.
author | John "Elwin" Edwards <elwin@sdf.org> |
---|---|
date | Mon, 17 Sep 2012 13:41:10 -0700 |
parents | 5ba2123d2c20 |
children | 25843238434a |
line wrap: on
line source
import math import psycopg2 import rlgalldb as rlgall def makeExpPDF(lbd): def lpdf(x): return lbd * math.exp(-lbd * x) return lpdf def makeExpCDF(lbd): def lcdf(x): return 1 - math.exp(-lbd * x) return lcdf conn = psycopg2.connect("dbname=rlg") cur = conn.cursor() for game in rlgall.gamelist: query = "SELECT score FROM {0};".format(game.uname) cur.execute(query) scores = [ r[0] for r in cur.fetchall() ] count = len(scores) total = sum(scores) lbd = float(count) / total cdf = makeExpCDF(lbd) print "{0}: {1} games, average {2}".format(game.name, count, int(1/lbd)) for i in range(0, 10000, 1000): actual = len([ s for s in scores if i <= s < i + 1000 ]) predicted = (cdf(i + 1000) - cdf(i)) * count print "{0:5}: {1:4} {2}".format(i, actual, predicted) high = max(scores) print "Max: {0} {1}\n".format(high, 1 - cdf(high)) cur.close() conn.close() exit()