# HG changeset patch # User John "Elwin" Edwards # Date 1389895669 28800 # Node ID 3ecbd4fa2a084b88ad87c3476a41235d04db1a68 # Parent e1de8aeb5ed46a3adbc1c1ad2d635d77f728a0e1 stats2.py: make graphs of maxdepth. diff -r e1de8aeb5ed4 -r 3ecbd4fa2a08 py/stats2.py --- a/py/stats2.py Sat Jan 11 10:45:33 2014 -0500 +++ b/py/stats2.py Thu Jan 16 10:07:49 2014 -0800 @@ -71,16 +71,102 @@ divs = 5 return divs, lim +def mkxlgraph(game, xls, xlcounts): + xlgraph = open("{0}/xl-{1}.svg".format(svgpath, game.uname), "w") + xlgraph.write(dochead) + xlgraph.write(stylesheet.format("0000ff")) + xlgraph.write(framerect) + xldivs, xlmax = ylimits(max(xlcounts)) + scale = 500 / xlmax + for xl, count in zip(xls, xlcounts): + barx = xl * 50 + 60 + barh = round(scale * count) + bary = 550 - barh + xlgraph.write(barstr.format(30, barh, barx, bary)) + 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(ltitle.format(sitename)) + xlgraph.write(ctitle.format(game.name)) + xlgraph.write(rtitle.format(timestr)) + xlgraph.write('\n') + xlgraph.close() + return + +def mkscoregraph(game, scoreblocks, scorecounts): + if isinstance(game, rlgall.ARogueGame): + scorewidth = 1500 + else: + scorewidth = 1000 + scoregraph = open("{0}/score-{1}.svg".format(svgpath, game.uname), "w") + scoregraph.write(dochead) + scoregraph.write(stylesheet.format("ffff00")) + scoregraph.write(framerect) + scoredivs, scoremax = ylimits(max(scorecounts)) + scale = 500 / scoremax + for block, count in zip(scoreblocks, scorecounts): + barx = block * 75 + 100 + barh = round(scale * count) + bary = 550 - barh + scoregraph.write(barstr.format(75, barh, barx, bary)) + scoregraph.write(xllabel.format(barx, block * scorewidth)) + 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(ltitle.format(sitename)) + scoregraph.write(ctitle.format(game.name)) + scoregraph.write(rtitle.format(timestr)) + scoregraph.write('\n') + scoregraph.close() + return + +def mkdeepgraph(game, deeps, deepcounts): + deepgraph = open("{0}/deep-{1}.svg".format(svgpath, game.uname), "w") + deepgraph.write(dochead) + deepgraph.write(stylesheet.format("808000")) + deepgraph.write(framerect) + deepdivs, deepmax = ylimits(max(deepcounts)) + scale = 500 / deepmax + for lev, count in zip(deeps, deepcounts): + barx = lev * 25 + 75 + barh = round(scale * count) + bary = 550 - barh + deepgraph.write(barstr.format(25, barh, barx, bary)) + 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(ltitle.format(sitename)) + deepgraph.write(ctitle.format(game.name)) + deepgraph.write(rtitle.format(timestr)) + deepgraph.write('\n') + deepgraph.close() + return + con = psycopg2.connect("dbname=rlg") cur = con.cursor() for game in rlgall.gamelist: xlq = "SELECT count(*) FROM {0} WHERE xl = %s;".format(game.uname) scrq = "SELECT count(*) FROM {0} WHERE score >= %s AND score < %s;".format(game.uname) + deepq = "SELECT count(*) FROM {0} WHERE maxdepth = %s;".format(game.uname) xls = range(1, 16) scoreblocks = range(10) + deeps = range(1, 31) xlcounts = [] scorecounts = [] + deepcounts = [] if isinstance(game, rlgall.ARogueGame): scorewidth = 1500 else: @@ -96,55 +182,12 @@ hscore = (sn + 1) * scorewidth cur.execute(scrq, (lscore, hscore)) scorecounts.append(cur.fetchone()[0]) - xlgraph = open("{0}/xl-{1}.svg".format(svgpath, game.uname), "w") - scoregraph = open("{0}/score-{1}.svg".format(svgpath, game.uname), "w") - xlgraph.write(dochead) - scoregraph.write(dochead) - xlgraph.write(stylesheet.format("0000ff")) - scoregraph.write(stylesheet.format("ffff00")) - xlgraph.write(framerect) - scoregraph.write(framerect) - - xldivs, xlmax = ylimits(max(xlcounts)) - scale = 500 / xlmax - for xl, count in zip(xls, xlcounts): - barx = xl * 50 + 60 - barh = round(scale * count) - bary = 550 - barh - xlgraph.write(barstr.format(30, barh, barx, bary)) - 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)) - - scoredivs, scoremax = ylimits(max(scorecounts)) - scale = 500 / scoremax - for block, count in zip(scoreblocks, scorecounts): - barx = block * 75 + 100 - barh = round(scale * count) - bary = 550 - barh - scoregraph.write(barstr.format(75, barh, barx, bary)) - scoregraph.write(xllabel.format(barx, block * scorewidth)) - for yl in range(scoredivs + 1): - labeln = int(scoremax * yl / scoredivs) - labelh = 550 + 8 - 500 * yl / scoredivs - scoregraph.write(ylabel.format(labelh, labeln)) - - xlgraph.write(xlabelf.format("Experience level")) - xlgraph.write(ylabelf.format("# of games")) - scoregraph.write(xlabelf.format("Score")) - scoregraph.write(ylabelf.format("# of games")) - xlgraph.write(ltitle.format(sitename)) - xlgraph.write(ctitle.format(game.name)) - xlgraph.write(rtitle.format(timestr)) - scoregraph.write(ltitle.format(sitename)) - scoregraph.write(ctitle.format(game.name)) - scoregraph.write(rtitle.format(timestr)) - xlgraph.write('\n') - xlgraph.close() - scoregraph.write('\n') - scoregraph.close() + for lev in deeps: + cur.execute(deepq, [lev]) + deepcounts.append(cur.fetchone()[0]) + mkxlgraph(game, xls, xlcounts) + mkscoregraph(game, scoreblocks, scorecounts) + mkdeepgraph(game, deeps, deepcounts) cur.close() con.close()