#!/usr/bin/python3
import psycopg2
import rlgall
from datetime import datetime
sitename = "rlgallery.org"
svgpath = rlgall.webdir
timestr = datetime.utcnow().strftime("%Y-%m-%d %H:%M")
dochead = """
\n')
self.of.close()
def ylimits(x):
ll = [2, 3, 4, 5, 6, 8, 10, 15]
m = 1
size = 0
while True:
for i in ll:
if i * m > x * 1.1:
size = i
lim = i * m
break
if size:
break
else:
m *= 10
if size in [3, 6]:
if lim == 3:
divs = 3
else:
divs = 6
elif size in [4, 8]:
divs = 4
else:
if lim == 2:
divs = 2
else:
divs = 5
return divs, lim
def titles(l, c, r):
return ltitle.format(l) + ctitle.format(c) + rtitle.format(r)
def mkxlgraph(game, xldata):
xlgraph = SVGChart("{0}/xl-{1}.svg".format(svgpath, game.uname))
xlgraph.style("0000ff")
xlgraph.write(framerect)
xlgraph.write('\n')
xlgraph.write(framerect)
xlgraph.write('\n')
xldivs, xlmax = ylimits(max([ pt[1] for pt in xldata ]))
scale = 500 / xlmax
for xl, count in xldata:
barx = xl * 50 + 60
barh = scale * count
bary = 550 - barh
if count > 0:
xlgraph.write(bar3d(barx, 30, barh))
xlgraph.write(xllabel.format(barx + 15, xl))
for yl in range(xldivs + 1):
labeln = int(xlmax * yl / xldivs)
labelh = 550 + 8 - 500 * yl / xldivs
xlgraph.write(ylabel.format(labelh, labeln))
xlgraph.write(xlabelf.format("Experience level"))
xlgraph.write(ylabelf.format("# of games"))
xlgraph.write(titles(sitename, game.name, timestr))
xlgraph.close()
return
def mkscoregraph(game, scoredata):
if isinstance(game, rlgall.ARogueGame):
scorewidth = 1000
else:
scorewidth = 500
scoregraph = SVGChart("{0}/score-{1}.svg".format(svgpath, game.uname))
scoregraph.style("ffff00")
scoregraph.write(framerect)
scoregraph.write('\n')
scoregraph.write(framerect)
scoregraph.write('\n')
scoredivs, scoremax = ylimits(max([ pt[1] for pt in scoredata ]))
scale = 500 / scoremax
for block, count in scoredata:
n = block // scorewidth
barx = n * 50 + 100
barh = scale * count
bary = 550 - barh
if count > 0:
scoregraph.write(bar3d(barx, 50, barh))
if n % 2 == 0:
scoregraph.write(xllabel.format(barx, block))
for yl in range(scoredivs + 1):
labeln = int(scoremax * yl / scoredivs)
labelh = 550 + 8 - 500 * yl / scoredivs
scoregraph.write(ylabel.format(labelh, labeln))
scoregraph.write(xlabelf.format("Score"))
scoregraph.write(ylabelf.format("# of games"))
scoregraph.write(titles(sitename, game.name, timestr))
scoregraph.close()
return
def mkdeepgraph(game, deepdata):
deepgraph = SVGChart("{0}/deep-{1}.svg".format(svgpath, game.uname))
deepgraph.style("808000")
deepgraph.write(framerect)
deepgraph.write('\n')
deepgraph.write(framerect)
deepgraph.write('\n')
deepdivs, deepmax = ylimits(max([ pt[1] for pt in deepdata ]))
scale = 500 / deepmax
for lev, count in deepdata:
barx = lev * 25 + 75
barh = scale * count
bary = 550 - barh
if count > 0:
deepgraph.write(bar3d(barx, 25, barh))
if lev % 3 == 0:
deepgraph.write(xllabel.format(barx + 12.5, lev))
for yl in range(deepdivs + 1):
labeln = int(deepmax * yl / deepdivs)
labelh = 550 + 8 - 500 * yl / deepdivs
deepgraph.write(ylabel.format(labelh, labeln))
deepgraph.write(xlabelf.format("Deepest dungeon level"))
deepgraph.write(ylabelf.format("# of games"))
deepgraph.write(titles(sitename, game.name, timestr))
deepgraph.close()
return
for game in rlgall.gamelist:
xldata = game.getXLCounts(15)
deepdata = game.getDepthCounts(30)
if isinstance(game, rlgall.ARogueGame):
scorewidth = 1000
else:
scorewidth = 500
scoredata = game.getScoreCounts(15, scorewidth)
mkxlgraph(game, xldata)
mkscoregraph(game, scoredata)
mkdeepgraph(game, deepdata)
exit()