annotate py/stats2.py @ 72:1d8dc3ed22cf

Restore the default size of the high score list. In an era of megabyte JavaScript libraries, ten lines of text is not too much.
author John "Elwin" Edwards
date Sun, 20 Mar 2016 07:59:22 -0400
parents 876786c55450
children
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 }}
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
29 g.bar3d polygon {{
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
30 fill:#{0};
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
31 fill-opacity:1;
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
32 stroke:#000000;
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
33 stroke-width:1;
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
34 stroke-opacity:1;
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
35 }}
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
36 </style>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
37 """
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
38 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
39 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
40 xllabel = '<text x="{0}" y="570" font-size="15" text-anchor="middle">{1}</text>\n'
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
41 ylabel = '<text x="90" y="{0:.2f}" font-size="16" text-anchor="end">{1}</text>\n'
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
42 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
43 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
44 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
45 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
46 ylabelf = """<g transform="translate(100, 300)">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
47 <g transform="rotate(-90)">
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
48 <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
49 </g>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
50 </g>
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
51 """
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
52
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
53 def makepolygon(coords):
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
54 points = [ "{0:.2f},{1:.2f}".format(pt[0], pt[1]) for pt in coords ]
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
55 pointstr = " ".join(points)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
56 return '<polygon points="{}"/>\n'.format(pointstr)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
57
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
58 def bar3d(x, w, h):
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
59 ydelta = w / 2
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
60 xdelta = ydelta / 3
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
61 flowerleft = (x, 550)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
62 flowerright = (x + w, 550)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
63 fupperleft = (x, 550 - h)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
64 fupperright = (x + w, 550 - h)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
65 blowerright = (x + w + xdelta, 550 - ydelta)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
66 bupperleft = (x + xdelta, 550 - h - ydelta)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
67 bupperright = (x + w + xdelta, 550 - h - ydelta)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
68 frontface = makepolygon([flowerleft, flowerright, fupperright, fupperleft])
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
69 rightface = makepolygon([blowerright, flowerright, fupperright, bupperright])
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
70 topface = makepolygon([bupperleft, bupperright, fupperright, fupperleft])
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
71 gopen = '<g class="bar3d" clip-path="url(#framer)">\n'
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
72 gclose = '</g>\n'
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
73 return gopen + "".join([frontface, rightface, topface]) + gclose
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
74
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
75 class SVGChart():
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
76 def __init__(self, filename):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
77 self.of = open(filename, "w", encoding="utf-8")
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
78 self.of.write(dochead)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
79 def style(self, barcolor):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
80 self.of.write(stylesheet.format(barcolor))
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
81 def write(self, obj):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
82 self.of.write(obj)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
83 def close(self):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
84 self.of.write('</svg>\n')
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
85 self.of.close()
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
86
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
87 def ylimits(x):
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
88 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
89 m = 1
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
90 size = 0
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
91 while True:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
92 for i in ll:
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
93 if i * m > x * 1.1:
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
94 size = i
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
95 lim = i * m
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
96 break
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
97 if size:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
98 break
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
99 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
100 m *= 10
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
101 if size in [3, 6]:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
102 if lim == 3:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
103 divs = 3
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
104 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
105 divs = 6
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
106 elif size in [4, 8]:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
107 divs = 4
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
108 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
109 if lim == 2:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
110 divs = 2
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
111 else:
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
112 divs = 5
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
113 return divs, lim
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
114
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
115 def titles(l, c, r):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
116 return ltitle.format(l) + ctitle.format(c) + rtitle.format(r)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
117
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
118 def mkxlgraph(game, xldata):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
119 xlgraph = SVGChart("{0}/xl-{1}.svg".format(svgpath, game.uname))
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
120 xlgraph.style("0000ff")
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
121 xlgraph.write(framerect)
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
122 xlgraph.write('<clipPath id="framer">\n')
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
123 xlgraph.write(framerect)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
124 xlgraph.write('</clipPath>\n')
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
125 xldivs, xlmax = ylimits(max([ pt[1] for pt in xldata ]))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
126 scale = 500 / xlmax
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
127 for xl, count in xldata:
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
128 barx = xl * 50 + 60
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
129 barh = scale * count
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
130 bary = 550 - barh
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
131 if count > 0:
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
132 xlgraph.write(bar3d(barx, 30, barh))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
133 xlgraph.write(xllabel.format(barx + 15, xl))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
134 for yl in range(xldivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
135 labeln = int(xlmax * yl / xldivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
136 labelh = 550 + 8 - 500 * yl / xldivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
137 xlgraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
138 xlgraph.write(xlabelf.format("Experience level"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
139 xlgraph.write(ylabelf.format("# of games"))
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
140 xlgraph.write(titles(sitename, game.name, timestr))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
141 xlgraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
142 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
143
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
144 def mkscoregraph(game, scoredata):
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
145 if isinstance(game, rlgall.ARogueGame):
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
146 scorewidth = 1000
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
147 else:
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
148 scorewidth = 500
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
149 scoregraph = SVGChart("{0}/score-{1}.svg".format(svgpath, game.uname))
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
150 scoregraph.style("ffff00")
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
151 scoregraph.write(framerect)
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
152 scoregraph.write('<clipPath id="framer">\n')
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
153 scoregraph.write(framerect)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
154 scoregraph.write('</clipPath>\n')
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
155 scoredivs, scoremax = ylimits(max([ pt[1] for pt in scoredata ]))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
156 scale = 500 / scoremax
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
157 for block, count in scoredata:
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
158 n = block // scorewidth
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
159 barx = n * 50 + 100
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
160 barh = scale * count
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
161 bary = 550 - barh
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
162 if count > 0:
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
163 scoregraph.write(bar3d(barx, 50, barh))
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
164 if n % 2 == 0:
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
165 scoregraph.write(xllabel.format(barx, block))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
166 for yl in range(scoredivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
167 labeln = int(scoremax * yl / scoredivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
168 labelh = 550 + 8 - 500 * yl / scoredivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
169 scoregraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
170 scoregraph.write(xlabelf.format("Score"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
171 scoregraph.write(ylabelf.format("# of games"))
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
172 scoregraph.write(titles(sitename, game.name, timestr))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
173 scoregraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
174 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
175
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
176 def mkdeepgraph(game, deepdata):
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
177 deepgraph = SVGChart("{0}/deep-{1}.svg".format(svgpath, game.uname))
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
178 deepgraph.style("808000")
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
179 deepgraph.write(framerect)
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
180 deepgraph.write('<clipPath id="framer">\n')
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
181 deepgraph.write(framerect)
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
182 deepgraph.write('</clipPath>\n')
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
183 deepdivs, deepmax = ylimits(max([ pt[1] for pt in deepdata ]))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
184 scale = 500 / deepmax
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
185 for lev, count in deepdata:
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
186 barx = lev * 25 + 75
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
187 barh = scale * count
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
188 bary = 550 - barh
56
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
189 if count > 0:
5cf88bd4e556 stats2.py: add some 3D perspective to the graphs.
John "Elwin" Edwards
parents: 45
diff changeset
190 deepgraph.write(bar3d(barx, 25, barh))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
191 if lev % 3 == 0:
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
192 deepgraph.write(xllabel.format(barx + 12.5, lev))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
193 for yl in range(deepdivs + 1):
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
194 labeln = int(deepmax * yl / deepdivs)
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
195 labelh = 550 + 8 - 500 * yl / deepdivs
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
196 deepgraph.write(ylabel.format(labelh, labeln))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
197 deepgraph.write(xlabelf.format("Deepest dungeon level"))
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
198 deepgraph.write(ylabelf.format("# of games"))
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
199 deepgraph.write(titles(sitename, game.name, timestr))
43
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
200 deepgraph.close()
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
201 return
3ecbd4fa2a08 stats2.py: make graphs of maxdepth.
John "Elwin" Edwards
parents: 40
diff changeset
202
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
203 for game in rlgall.gamelist:
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
204 xldata = game.getXLCounts(15)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
205 deepdata = game.getDepthCounts(30)
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
206 if isinstance(game, rlgall.ARogueGame):
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
207 scorewidth = 1000
39
a97a20571526 stats2.py: adjust x-axis scale for arogue5 score chart.
John "Elwin" Edwards
parents: 38
diff changeset
208 else:
60
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
209 scorewidth = 500
876786c55450 Reduce the score graphs' column widths.
John "Elwin" Edwards
parents: 56
diff changeset
210 scoredata = game.getScoreCounts(15, scorewidth)
45
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
211 mkxlgraph(game, xldata)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
212 mkscoregraph(game, scoredata)
0f4163dbbafc SVG charts: separate database-querying and chart-printing code.
John "Elwin" Edwards
parents: 43
diff changeset
213 mkdeepgraph(game, deepdata)
38
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
214
d2c3c29ca4f9 Add a new statistics script that creates SVG plots.
John "Elwin" Edwards
parents:
diff changeset
215 exit()