2009-08-25 17:53:55 -06:00
|
|
|
#! /usr/bin/env python3
|
|
|
|
|
|
|
|
import time
|
|
|
|
import os
|
2009-09-01 09:34:15 -06:00
|
|
|
import tempfile
|
2009-10-05 13:33:20 -06:00
|
|
|
from . import points
|
|
|
|
from . import teams
|
|
|
|
from . import config
|
2009-09-29 15:36:25 -06:00
|
|
|
|
|
|
|
pngout = config.datafile('histogram.png')
|
2009-08-25 17:53:55 -06:00
|
|
|
|
2009-09-01 09:34:15 -06:00
|
|
|
def main(s=None):
|
|
|
|
scores = {}
|
|
|
|
now = 0
|
2009-08-25 17:53:55 -06:00
|
|
|
|
2009-09-01 09:34:15 -06:00
|
|
|
if not s:
|
2009-09-29 15:36:25 -06:00
|
|
|
s = points.Storage()
|
2009-08-25 17:53:55 -06:00
|
|
|
|
2009-09-01 09:34:15 -06:00
|
|
|
plotparts = []
|
2009-08-25 17:53:55 -06:00
|
|
|
|
2009-09-01 09:34:15 -06:00
|
|
|
catscores = {}
|
|
|
|
for cat in s.categories():
|
|
|
|
catscores[cat] = s.cat_points(cat)
|
2009-08-25 17:53:55 -06:00
|
|
|
|
2009-09-01 09:34:15 -06:00
|
|
|
scoresfile = tempfile.NamedTemporaryFile('w')
|
|
|
|
fn = scoresfile.name
|
|
|
|
i = 2
|
2009-10-01 18:33:21 -06:00
|
|
|
for team in s.teams:
|
2009-10-01 12:17:03 -06:00
|
|
|
plotparts.append('"%s" using 1:%d with lines linewidth 2 linetype rgb "#%s"' % (fn, i, teams.color(team)))
|
2009-09-01 09:34:15 -06:00
|
|
|
scores[team] = 0
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
def write_scores(t):
|
|
|
|
scoresfile.write('%d' % t)
|
2009-10-01 18:33:21 -06:00
|
|
|
for team in s.teams:
|
2009-09-01 09:34:15 -06:00
|
|
|
scoresfile.write('\t%f' % (scores[team]))
|
|
|
|
scoresfile.write('\n')
|
|
|
|
|
|
|
|
for when, cat, team, score in s.log:
|
|
|
|
if when > now:
|
|
|
|
if now:
|
|
|
|
write_scores(now)
|
|
|
|
now = when
|
|
|
|
pct = score / catscores[cat]
|
|
|
|
scores[team] += pct
|
|
|
|
#print('%d [%s] [%s] %d' % (when, cat, team, points))
|
|
|
|
|
|
|
|
write_scores(when)
|
|
|
|
scoresfile.flush()
|
|
|
|
|
2009-09-01 11:23:40 -06:00
|
|
|
instructions = tempfile.NamedTemporaryFile('w')
|
|
|
|
instructions.write('''
|
|
|
|
set style data lines
|
|
|
|
set xdata time
|
|
|
|
set timefmt "%%s"
|
|
|
|
set format ""
|
|
|
|
set border 3
|
|
|
|
set xtics nomirror
|
|
|
|
set ytics nomirror
|
|
|
|
set nokey
|
|
|
|
set terminal png transparent size 640,200 x000000 xffffff
|
2009-09-29 15:36:25 -06:00
|
|
|
set output "%(pngout)s"
|
|
|
|
plot %(plot)s\n''' % {'plot': ','.join(plotparts),
|
|
|
|
'pngout': pngout})
|
2009-09-01 11:23:40 -06:00
|
|
|
instructions.flush()
|
|
|
|
|
2009-10-01 18:33:21 -06:00
|
|
|
gp = os.system('gnuplot %s 2>/dev/null </dev/null' % instructions.name)
|
2009-09-01 09:34:15 -06:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|