moth/ctf/scoreboard.py

77 lines
2.2 KiB
Python
Raw Normal View History

2009-09-29 15:36:25 -06:00
#!/usr/bin/env python3
import cgitb; cgitb.enable()
2009-10-01 12:17:03 -06:00
import os
2009-10-02 16:38:25 -06:00
import sys
2010-01-19 15:31:15 -07:00
from cgi import escape as quote
2009-10-05 13:33:20 -06:00
from . import config
from . import teams
from . import points
2009-09-29 15:36:25 -06:00
2009-10-01 12:17:03 -06:00
flags_dir = config.get('global', 'flags_dir')
house_team = config.get('global', 'house_team')
2009-09-29 15:36:25 -06:00
def main():
s = points.Storage()
categories = [(cat, s.cat_points(cat)) for cat in s.categories()]
2010-01-19 15:31:15 -07:00
categories = [(c, p) for (c, p) in categories if p > 0]
2009-09-29 15:36:25 -06:00
print('Refresh: 10')
2009-10-08 16:42:26 -06:00
print(config.start_html('Scoreboard', cls='wide'))
2009-10-01 12:17:03 -06:00
print('<table class="scoreboard">')
2009-09-29 15:36:25 -06:00
print('<tr>')
2009-10-01 12:17:03 -06:00
print('<th>Overall</th>')
2009-09-29 15:36:25 -06:00
for cat, score in categories:
2009-10-01 12:17:03 -06:00
print('<th>')
print(' %s (%d)' % (cat, score))
try:
fn = os.path.join(flags_dir, cat)
team = open(fn).read() or house_team
print(' <br/>')
2009-10-02 16:38:25 -06:00
print(' <!-- flag: %s --> <span style="color: #%s" title="flag holder">%s</span>'
2010-01-19 15:31:15 -07:00
% (cat, teams.color(team), quote(team[:15])))
2009-10-01 12:17:03 -06:00
except IOError:
pass
print('</th>')
2009-09-29 15:36:25 -06:00
print('</tr>')
print('<tr>')
2009-10-01 12:17:03 -06:00
print('<td><ol>')
totals = []
for team in s.teams:
total = s.team_points(team)
totals.append((total, team))
for total, team in sorted(totals, reverse=True):
2010-01-19 15:31:15 -07:00
if total < 0.1:
break
2009-10-01 12:17:03 -06:00
print('<li><span style="color: #%s;">%s (%0.3f)</span></li>'
2010-01-19 15:31:15 -07:00
% (teams.color(team), quote(team[:15]), total))
2009-10-01 12:17:03 -06:00
print('</ol></td>')
2009-09-29 15:36:25 -06:00
for cat, total in categories:
2009-10-01 12:17:03 -06:00
print('<td>')
scores = sorted([(s.team_points_in_cat(cat, team), team) for team in s.teams])
2009-09-29 15:36:25 -06:00
for score, team in scores:
2010-01-19 15:31:15 -07:00
if not score:
continue
2009-10-01 12:17:03 -06:00
color = teams.color(team)
2009-09-29 15:36:25 -06:00
print('<div style="height: %f%%; overflow: hidden; background: #%s; color: black;">' % (float(score * 100)/total, color))
2010-01-19 15:31:15 -07:00
print('<!-- category: %s --> %s: %d' % (cat, quote(team[:15]), score))
2009-09-29 15:36:25 -06:00
print('</div>')
print('</td>')
print('</tr>')
print('''</table>
2009-10-02 16:38:25 -06:00
<p class="histogram">
<img src="histogram.png" alt="scores over time" />
</p>
2009-10-08 16:42:26 -06:00
''')
print(config.end_html())
2009-09-29 15:36:25 -06:00
if __name__ == '__main__':
main()
# Local Variables:
# mode: python
# End: