comparison 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
comparison
equal deleted inserted replaced
42:e1de8aeb5ed4 43:3ecbd4fa2a08
69 divs = 2 69 divs = 2
70 else: 70 else:
71 divs = 5 71 divs = 5
72 return divs, lim 72 return divs, lim
73 73
74 def mkxlgraph(game, xls, xlcounts):
75 xlgraph = open("{0}/xl-{1}.svg".format(svgpath, game.uname), "w")
76 xlgraph.write(dochead)
77 xlgraph.write(stylesheet.format("0000ff"))
78 xlgraph.write(framerect)
79 xldivs, xlmax = ylimits(max(xlcounts))
80 scale = 500 / xlmax
81 for xl, count in zip(xls, xlcounts):
82 barx = xl * 50 + 60
83 barh = round(scale * count)
84 bary = 550 - barh
85 xlgraph.write(barstr.format(30, barh, barx, bary))
86 xlgraph.write(xllabel.format(barx + 15, xl))
87 for yl in range(xldivs + 1):
88 labeln = int(xlmax * yl / xldivs)
89 labelh = 550 + 8 - 500 * yl / xldivs
90 xlgraph.write(ylabel.format(labelh, labeln))
91 xlgraph.write(xlabelf.format("Experience level"))
92 xlgraph.write(ylabelf.format("# of games"))
93 xlgraph.write(ltitle.format(sitename))
94 xlgraph.write(ctitle.format(game.name))
95 xlgraph.write(rtitle.format(timestr))
96 xlgraph.write('</svg>\n')
97 xlgraph.close()
98 return
99
100 def mkscoregraph(game, scoreblocks, scorecounts):
101 if isinstance(game, rlgall.ARogueGame):
102 scorewidth = 1500
103 else:
104 scorewidth = 1000
105 scoregraph = open("{0}/score-{1}.svg".format(svgpath, game.uname), "w")
106 scoregraph.write(dochead)
107 scoregraph.write(stylesheet.format("ffff00"))
108 scoregraph.write(framerect)
109 scoredivs, scoremax = ylimits(max(scorecounts))
110 scale = 500 / scoremax
111 for block, count in zip(scoreblocks, scorecounts):
112 barx = block * 75 + 100
113 barh = round(scale * count)
114 bary = 550 - barh
115 scoregraph.write(barstr.format(75, barh, barx, bary))
116 scoregraph.write(xllabel.format(barx, block * scorewidth))
117 for yl in range(scoredivs + 1):
118 labeln = int(scoremax * yl / scoredivs)
119 labelh = 550 + 8 - 500 * yl / scoredivs
120 scoregraph.write(ylabel.format(labelh, labeln))
121 scoregraph.write(xlabelf.format("Score"))
122 scoregraph.write(ylabelf.format("# of games"))
123 scoregraph.write(ltitle.format(sitename))
124 scoregraph.write(ctitle.format(game.name))
125 scoregraph.write(rtitle.format(timestr))
126 scoregraph.write('</svg>\n')
127 scoregraph.close()
128 return
129
130 def mkdeepgraph(game, deeps, deepcounts):
131 deepgraph = open("{0}/deep-{1}.svg".format(svgpath, game.uname), "w")
132 deepgraph.write(dochead)
133 deepgraph.write(stylesheet.format("808000"))
134 deepgraph.write(framerect)
135 deepdivs, deepmax = ylimits(max(deepcounts))
136 scale = 500 / deepmax
137 for lev, count in zip(deeps, deepcounts):
138 barx = lev * 25 + 75
139 barh = round(scale * count)
140 bary = 550 - barh
141 deepgraph.write(barstr.format(25, barh, barx, bary))
142 if lev % 3 == 0:
143 deepgraph.write(xllabel.format(barx + 12.5, lev))
144 for yl in range(deepdivs + 1):
145 labeln = int(deepmax * yl / deepdivs)
146 labelh = 550 + 8 - 500 * yl / deepdivs
147 deepgraph.write(ylabel.format(labelh, labeln))
148 deepgraph.write(xlabelf.format("Deepest dungeon level"))
149 deepgraph.write(ylabelf.format("# of games"))
150 deepgraph.write(ltitle.format(sitename))
151 deepgraph.write(ctitle.format(game.name))
152 deepgraph.write(rtitle.format(timestr))
153 deepgraph.write('</svg>\n')
154 deepgraph.close()
155 return
156
74 con = psycopg2.connect("dbname=rlg") 157 con = psycopg2.connect("dbname=rlg")
75 cur = con.cursor() 158 cur = con.cursor()
76 159
77 for game in rlgall.gamelist: 160 for game in rlgall.gamelist:
78 xlq = "SELECT count(*) FROM {0} WHERE xl = %s;".format(game.uname) 161 xlq = "SELECT count(*) FROM {0} WHERE xl = %s;".format(game.uname)
79 scrq = "SELECT count(*) FROM {0} WHERE score >= %s AND score < %s;".format(game.uname) 162 scrq = "SELECT count(*) FROM {0} WHERE score >= %s AND score < %s;".format(game.uname)
163 deepq = "SELECT count(*) FROM {0} WHERE maxdepth = %s;".format(game.uname)
80 xls = range(1, 16) 164 xls = range(1, 16)
81 scoreblocks = range(10) 165 scoreblocks = range(10)
166 deeps = range(1, 31)
82 xlcounts = [] 167 xlcounts = []
83 scorecounts = [] 168 scorecounts = []
169 deepcounts = []
84 if isinstance(game, rlgall.ARogueGame): 170 if isinstance(game, rlgall.ARogueGame):
85 scorewidth = 1500 171 scorewidth = 1500
86 else: 172 else:
87 scorewidth = 1000 173 scorewidth = 1000
88 for xl in xls: 174 for xl in xls:
94 hscore = scorewidth * 32 180 hscore = scorewidth * 32
95 else: 181 else:
96 hscore = (sn + 1) * scorewidth 182 hscore = (sn + 1) * scorewidth
97 cur.execute(scrq, (lscore, hscore)) 183 cur.execute(scrq, (lscore, hscore))
98 scorecounts.append(cur.fetchone()[0]) 184 scorecounts.append(cur.fetchone()[0])
99 xlgraph = open("{0}/xl-{1}.svg".format(svgpath, game.uname), "w") 185 for lev in deeps:
100 scoregraph = open("{0}/score-{1}.svg".format(svgpath, game.uname), "w") 186 cur.execute(deepq, [lev])
101 xlgraph.write(dochead) 187 deepcounts.append(cur.fetchone()[0])
102 scoregraph.write(dochead) 188 mkxlgraph(game, xls, xlcounts)
103 xlgraph.write(stylesheet.format("0000ff")) 189 mkscoregraph(game, scoreblocks, scorecounts)
104 scoregraph.write(stylesheet.format("ffff00")) 190 mkdeepgraph(game, deeps, deepcounts)
105 xlgraph.write(framerect)
106 scoregraph.write(framerect)
107
108 xldivs, xlmax = ylimits(max(xlcounts))
109 scale = 500 / xlmax
110 for xl, count in zip(xls, xlcounts):
111 barx = xl * 50 + 60
112 barh = round(scale * count)
113 bary = 550 - barh
114 xlgraph.write(barstr.format(30, barh, barx, bary))
115 xlgraph.write(xllabel.format(barx + 15, xl))
116 for yl in range(xldivs + 1):
117 labeln = int(xlmax * yl / xldivs)
118 labelh = 550 + 8 - 500 * yl / xldivs
119 xlgraph.write(ylabel.format(labelh, labeln))
120
121 scoredivs, scoremax = ylimits(max(scorecounts))
122 scale = 500 / scoremax
123 for block, count in zip(scoreblocks, scorecounts):
124 barx = block * 75 + 100
125 barh = round(scale * count)
126 bary = 550 - barh
127 scoregraph.write(barstr.format(75, barh, barx, bary))
128 scoregraph.write(xllabel.format(barx, block * scorewidth))
129 for yl in range(scoredivs + 1):
130 labeln = int(scoremax * yl / scoredivs)
131 labelh = 550 + 8 - 500 * yl / scoredivs
132 scoregraph.write(ylabel.format(labelh, labeln))
133
134 xlgraph.write(xlabelf.format("Experience level"))
135 xlgraph.write(ylabelf.format("# of games"))
136 scoregraph.write(xlabelf.format("Score"))
137 scoregraph.write(ylabelf.format("# of games"))
138 xlgraph.write(ltitle.format(sitename))
139 xlgraph.write(ctitle.format(game.name))
140 xlgraph.write(rtitle.format(timestr))
141 scoregraph.write(ltitle.format(sitename))
142 scoregraph.write(ctitle.format(game.name))
143 scoregraph.write(rtitle.format(timestr))
144 xlgraph.write('</svg>\n')
145 xlgraph.close()
146 scoregraph.write('</svg>\n')
147 scoregraph.close()
148 191
149 cur.close() 192 cur.close()
150 con.close() 193 con.close()
151 exit() 194 exit()