From 8b436e01dc53274e681f3e138bd9c129a19e6663 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 25 Aug 2009 17:53:55 -0600 Subject: [PATCH] Add scoreboard page and histogram-generation script --- histogram.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ scoreboard.cgi | 49 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100755 histogram.py create mode 100755 scoreboard.cgi diff --git a/histogram.py b/histogram.py new file mode 100755 index 0000000..48d4b12 --- /dev/null +++ b/histogram.py @@ -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() diff --git a/scoreboard.cgi b/scoreboard.cgi new file mode 100755 index 0000000..cbc22dc --- /dev/null +++ b/scoreboard.cgi @@ -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(''' + + + + yo mom + + +

Scoreboard

+''') +print('') +print('') +for cat, points in categories: + print('' % (cat, points)) +print('') + +print('') +for cat, total in categories: + print('') +print('') +print('''
%s (%d)
') + scores = sorted([(s.team_points_in_cat(cat, team), team) for team in teams]) + for points, team in scores: + color = teamcolors[team] + print('
' % (float(points * 100)/total, color)) + print(' %s: %d' % (cat, team, points)) + print('
') + print('
+ + + +''')