annotate py/stats2.py @ 43:3ecbd4fa2a08

stats2.py: make graphs of maxdepth.
author John "Elwin" Edwards
date Thu, 16 Jan 2014 10:07:49 -0800
parents 1ddd2d950e31
children 0f4163dbbafc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
1 #!/usr/bin/python3
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
2
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
3 import psycopg2
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
4 import rlgall
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
5 from datetime import datetime
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
6
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
7 sitename = "rlgallery.org"
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
8 svgpath = rlgall.webdir
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
9 timestr = datetime.utcnow().strftime("%Y-%m-%d %H:%M")
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
10
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
11 dochead = """<?xml version="1.0" encoding="UTF-8"?>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
12 <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="900" height="600">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
13 """
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
14 stylesheet = """<style type="text/css">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
15 rect.frame {{
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
16 fill:#ffffff;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
17 fill-opacity:1;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
18 stroke:#000000;
40
1ddd2d950e31 SVG charts: reduce frame stroke width.
John "Elwin" Edwards
parents: 39
diff changeset
19 stroke-width:2;
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
20 stroke-opacity:1;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
21 }}
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
22 rect.bar {{
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
23 fill:#{0};
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
24 fill-opacity:1;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
25 stroke:#000000;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
26 stroke-width:2;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
27 stroke-opacity:1;
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
28 }}
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
29 </style>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
30 """
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
31 framerect = '<rect width="750" height="500" x="100" y="50" class="frame"/>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
32 barstr = '<rect width="{0}" height="{1}" x="{2}" y="{3}" class="bar"/>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
33 xllabel = '<text x="{0}" y="570" font-size="15" text-anchor="middle">{1}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
34 ylabel = '<text x="90" y="{0}" font-size="16" text-anchor="end">{1}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
35 xlabelf = '<text x="475" y="590" font-size="15" text-anchor="middle">{0}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
36 ltitle = '<text x="100" y="35" font-size="16" text-anchor="start">{0}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
37 ctitle = '<text x="475" y="34" font-size="18" text-anchor="middle">{0}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
38 rtitle = '<text x="850" y="35" font-size="16" text-anchor="end">{0}</text>\n'
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
39 ylabelf = """<g transform="translate(100, 300)">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
40 <g transform="rotate(-90)">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
41 <text x="0" y="-60" font-size="16" text-anchor="middle">{0}</text>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
42 </g>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
43 </g>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
44 """
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
45
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
46 def ylimits(x):
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
47 ll = [2, 3, 4, 5, 6, 8, 10, 15]
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
48 m = 1
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
49 size = 0
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
50 while True:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
51 for i in ll:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
52 if i * m > x:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
53 size = i
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
54 lim = i * m
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
55 break
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
56 if size:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
57 break
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
58 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
59 m *= 10
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
60 if size in [3, 6]:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
61 if lim == 3:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
62 divs = 3
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
63 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
64 divs = 6
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
65 elif size in [4, 8]:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
66 divs = 4
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
67 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
68 if lim == 2:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
69 divs = 2
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
70 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
71 divs = 5
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
72 return divs, lim
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
73
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
74 def mkxlgraph(game, xls, xlcounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
75 xlgraph = open("{0}/xl-{1}.svg".format(svgpath, game.uname), "w")
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
76 xlgraph.write(dochead)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
77 xlgraph.write(stylesheet.format("0000ff"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
78 xlgraph.write(framerect)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
79 xldivs, xlmax = ylimits(max(xlcounts))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
80 scale = 500 / xlmax
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
81 for xl, count in zip(xls, xlcounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
82 barx = xl * 50 + 60
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
83 barh = round(scale * count)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
84 bary = 550 - barh
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
85 xlgraph.write(barstr.format(30, barh, barx, bary))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
86 xlgraph.write(xllabel.format(barx + 15, xl))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
87 for yl in range(xldivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
88 labeln = int(xlmax * yl / xldivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
89 labelh = 550 + 8 - 500 * yl / xldivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
90 xlgraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
91 xlgraph.write(xlabelf.format("Experience level"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
92 xlgraph.write(ylabelf.format("# of games"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
93 xlgraph.write(ltitle.format(sitename))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
94 xlgraph.write(ctitle.format(game.name))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
95 xlgraph.write(rtitle.format(timestr))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
96 xlgraph.write('</svg>\n')
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
97 xlgraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
98 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
99
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
100 def mkscoregraph(game, scoreblocks, scorecounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
101 if isinstance(game, rlgall.ARogueGame):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
102 scorewidth = 1500
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
103 else:
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
104 scorewidth = 1000
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
105 scoregraph = open("{0}/score-{1}.svg".format(svgpath, game.uname), "w")
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
106 scoregraph.write(dochead)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
107 scoregraph.write(stylesheet.format("ffff00"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
108 scoregraph.write(framerect)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
109 scoredivs, scoremax = ylimits(max(scorecounts))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
110 scale = 500 / scoremax
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
111 for block, count in zip(scoreblocks, scorecounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
112 barx = block * 75 + 100
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
113 barh = round(scale * count)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
114 bary = 550 - barh
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
115 scoregraph.write(barstr.format(75, barh, barx, bary))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
116 scoregraph.write(xllabel.format(barx, block * scorewidth))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
117 for yl in range(scoredivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
118 labeln = int(scoremax * yl / scoredivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
119 labelh = 550 + 8 - 500 * yl / scoredivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
120 scoregraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
121 scoregraph.write(xlabelf.format("Score"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
122 scoregraph.write(ylabelf.format("# of games"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
123 scoregraph.write(ltitle.format(sitename))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
124 scoregraph.write(ctitle.format(game.name))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
125 scoregraph.write(rtitle.format(timestr))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
126 scoregraph.write('</svg>\n')
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
127 scoregraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
128 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
129
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
130 def mkdeepgraph(game, deeps, deepcounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
131 deepgraph = open("{0}/deep-{1}.svg".format(svgpath, game.uname), "w")
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
132 deepgraph.write(dochead)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
133 deepgraph.write(stylesheet.format("808000"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
134 deepgraph.write(framerect)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
135 deepdivs, deepmax = ylimits(max(deepcounts))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
136 scale = 500 / deepmax
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
137 for lev, count in zip(deeps, deepcounts):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
138 barx = lev * 25 + 75
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
139 barh = round(scale * count)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
140 bary = 550 - barh
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
141 deepgraph.write(barstr.format(25, barh, barx, bary))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
142 if lev % 3 == 0:
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
143 deepgraph.write(xllabel.format(barx + 12.5, lev))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
144 for yl in range(deepdivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
145 labeln = int(deepmax * yl / deepdivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
146 labelh = 550 + 8 - 500 * yl / deepdivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
147 deepgraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
148 deepgraph.write(xlabelf.format("Deepest dungeon level"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
149 deepgraph.write(ylabelf.format("# of games"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
150 deepgraph.write(ltitle.format(sitename))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
151 deepgraph.write(ctitle.format(game.name))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
152 deepgraph.write(rtitle.format(timestr))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
153 deepgraph.write('</svg>\n')
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
154 deepgraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
155 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
156
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
157 con = psycopg2.connect("dbname=rlg")
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
158 cur = con.cursor()
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
159
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
160 for game in rlgall.gamelist:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
161 xlq = "SELECT count(*) FROM {0} WHERE xl = %s;".format(game.uname)
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
162 scrq = "SELECT count(*) FROM {0} WHERE score >= %s AND score < %s;".format(game.uname)
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
163 deepq = "SELECT count(*) FROM {0} WHERE maxdepth = %s;".format(game.uname)
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
164 xls = range(1, 16)
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
165 scoreblocks = range(10)
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
166 deeps = range(1, 31)
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
167 xlcounts = []
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
168 scorecounts = []
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
169 deepcounts = []
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
170 if isinstance(game, rlgall.ARogueGame):
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
171 scorewidth = 1500
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
172 else:
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
173 scorewidth = 1000
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
174 for xl in xls:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
175 cur.execute(xlq, [xl])
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
176 xlcounts.append(cur.fetchone()[0])
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
177 for sn in scoreblocks:
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
178 lscore = sn * scorewidth
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
179 if sn == 9:
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
180 hscore = scorewidth * 32
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
181 else:
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
182 hscore = (sn + 1) * scorewidth
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
183 cur.execute(scrq, (lscore, hscore))
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
184 scorecounts.append(cur.fetchone()[0])
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
185 for lev in deeps:
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
186 cur.execute(deepq, [lev])
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
187 deepcounts.append(cur.fetchone()[0])
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
188 mkxlgraph(game, xls, xlcounts)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
189 mkscoregraph(game, scoreblocks, scorecounts)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
190 mkdeepgraph(game, deeps, deepcounts)
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
191
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
192 cur.close()
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
193 con.close()
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
194 exit()