mirror of https://github.com/dirtbags/moth.git
Add scoreboard page and histogram-generation script
This commit is contained in:
parent
86493ff0c9
commit
8b436e01dc
|
@ -0,0 +1,57 @@
|
||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
import points
|
||||||
|
import time
|
||||||
|
import os
|
||||||
|
|
||||||
|
teamfiles = {}
|
||||||
|
scores = {}
|
||||||
|
now = 0
|
||||||
|
|
||||||
|
s = points.Storage('scores.dat')
|
||||||
|
|
||||||
|
plotparts = []
|
||||||
|
teams = s.teams()
|
||||||
|
teamcolors = points.colors(teams)
|
||||||
|
|
||||||
|
fn = 'scores.hist'
|
||||||
|
scoresfile = open(fn, 'w')
|
||||||
|
i = 2
|
||||||
|
for team in teams:
|
||||||
|
plotparts.append('"%s" using 1:%d with lines linetype rgb "#%s"' % (fn, i, teamcolors[team]))
|
||||||
|
scores[team] = 0
|
||||||
|
i += 1
|
||||||
|
print(plotparts)
|
||||||
|
|
||||||
|
def write_scores(t):
|
||||||
|
scoresfile.write('%d' % t)
|
||||||
|
for team in teams:
|
||||||
|
scoresfile.write('\t%d' % (scores[team]))
|
||||||
|
scoresfile.write('\n')
|
||||||
|
|
||||||
|
for when, cat, team, points in s.log:
|
||||||
|
if when > now:
|
||||||
|
if now:
|
||||||
|
write_scores(now)
|
||||||
|
now = when
|
||||||
|
scores[team] += points
|
||||||
|
#print('%d [%s] [%s] %d' % (when, cat, team, points))
|
||||||
|
|
||||||
|
write_scores(when)
|
||||||
|
|
||||||
|
for f in teamfiles.values():
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
gp = os.popen('gnuplot > /dev/null', 'w')
|
||||||
|
gp.write('set style data lines\n')
|
||||||
|
gp.write('set xdata time\n')
|
||||||
|
gp.write('set timefmt "%s"\n')
|
||||||
|
gp.write('set format ""\n')
|
||||||
|
gp.write('set border 3\n')
|
||||||
|
gp.write('set xtics nomirror\n')
|
||||||
|
gp.write('set ytics nomirror\n')
|
||||||
|
gp.write('set nokey\n')
|
||||||
|
gp.write('set terminal png transparent x000000 xffffff\n')
|
||||||
|
gp.write('set output "histogram.png"\n')
|
||||||
|
gp.write('plot %s\n' % ','.join(plotparts))
|
||||||
|
gp.flush()
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import cgitb; cgitb.enable()
|
||||||
|
import points
|
||||||
|
|
||||||
|
print('Content-type: text/html')
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
s = points.Storage('scores.dat')
|
||||||
|
|
||||||
|
rows = 20
|
||||||
|
|
||||||
|
teams = s.teams()
|
||||||
|
categories = [(cat, s.cat_points(cat)) for cat in s.categories()]
|
||||||
|
teamcolors = points.colors(teams)
|
||||||
|
|
||||||
|
print('''<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||||
|
<head>
|
||||||
|
<title>yo mom</title>
|
||||||
|
</head>
|
||||||
|
<body style="background: black; color: white;">
|
||||||
|
<h1>Scoreboard</h1>
|
||||||
|
''')
|
||||||
|
print('<table>')
|
||||||
|
print('<tr>')
|
||||||
|
for cat, points in categories:
|
||||||
|
print('<th>%s (%d)</th>' % (cat, points))
|
||||||
|
print('</tr>')
|
||||||
|
|
||||||
|
print('<tr>')
|
||||||
|
for cat, total in categories:
|
||||||
|
print('<td style="height: 400px;">')
|
||||||
|
scores = sorted([(s.team_points_in_cat(cat, team), team) for team in teams])
|
||||||
|
for points, team in scores:
|
||||||
|
color = teamcolors[team]
|
||||||
|
print('<div style="height: %f%%; overflow: hidden; background: #%s; color: black;">' % (float(points * 100)/total, color))
|
||||||
|
print('<!-- %s --> %s: %d' % (cat, team, points))
|
||||||
|
print('</div>')
|
||||||
|
print('</td>')
|
||||||
|
print('</tr>')
|
||||||
|
print('''</table>
|
||||||
|
|
||||||
|
<img src="histogram.png" />
|
||||||
|
</body>
|
||||||
|
</html>''')
|
Loading…
Reference in New Issue