2014-01-02 13:09:48 -05:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
2012-07-25 21:59:42 -07:00
|
|
|
import math
|
|
|
|
|
import psycopg2
|
2014-01-02 13:09:48 -05:00
|
|
|
import rlgall
|
2012-07-25 21:59:42 -07:00
|
|
|
|
|
|
|
|
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)
|
2014-01-02 13:09:48 -05:00
|
|
|
print("{0}: {1} games, average {2}".format(game.name, count, int(1/lbd)))
|
2012-07-25 21:59:42 -07:00
|
|
|
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
|
2014-01-02 13:09:48 -05:00
|
|
|
print("{0:5}: {1:4} {2}".format(i, actual, predicted))
|
2012-07-25 21:59:42 -07:00
|
|
|
high = max(scores)
|
2014-01-02 13:09:48 -05:00
|
|
|
print("Max: {0} {1}\n".format(high, 1 - cdf(high)))
|
2012-07-25 21:59:42 -07:00
|
|
|
|
|
|
|
|
cur.close()
|
|
|
|
|
conn.close()
|
|
|
|
|
exit()
|