From: Ant Zucaro Date: Sat, 7 Jul 2012 01:45:23 +0000 (-0400) Subject: Basic support for batch processes. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9e0a93b6f5d9a4a5edbca58ae46c6a950e00bf1e;p=xonotic%2Fxonstat.git Basic support for batch processes. Badges is the first batch process supported. It basically sets up the pyramid environment, then iterates over the player base and generates static HTML files showing their high-level stats. That static HTML is then converted into a PNG for use in forum signatures. A bash wrapper is needed to drive the whole process via cron. --- diff --git a/xonstat/batch/badges/css/style.css b/xonstat/batch/badges/css/style.css new file mode 100644 index 0000000..1d7627e --- /dev/null +++ b/xonstat/batch/badges/css/style.css @@ -0,0 +1,39 @@ +body { + color: #ccc; + font-family: monospace; + font-size: 12px; +} +#badge { + background: url('../img/dark_wall.png'); + height: 60px; + padding: 5px; + position: fixed; + width: 550px; +} +#nick { + font-size: 22px; + font-weight: bold; + height: 28px; + left: 10px; + overflow: hidden; + position: absolute; + width: 285px; +} +#games_played { + left: 10px; + position: absolute; + top: 45px; +} +#win_percentage, #kill_ratio, #elo { + left: 300px; + position: absolute; +} +#win_percentage { + top: 5px; +} +#kill_ratio { + top: 25px; +} +#elo { + top: 45px; +} diff --git a/xonstat/batch/badges/gen_badges.py b/xonstat/batch/badges/gen_badges.py new file mode 100644 index 0000000..f6e02f4 --- /dev/null +++ b/xonstat/batch/badges/gen_badges.py @@ -0,0 +1,36 @@ +from mako.template import Template +from os import system +from pyramid.paster import bootstrap +from xonstat.models import * +from xonstat.views.player import player_info_data + +# converter params +CONVERTER = "/home/ant/xonotic/xonstat/xonstat/batch/badges/wkhtmltoimage-amd64 --crop-x 10 --crop-y 10 --width 560 --height 70 -f png" + +# environment setup +env = bootstrap('../../../development.ini.home') +req = env['request'] +req.matchdict = {'id':3} + +# template setup +t = Template(filename = 'templates/badge.mako') + +players = DBSession.query(Player).filter(Player.player_id < 50).\ + filter(Player.player_id == PlayerElo.player_id).\ + filter(Player.nick != None).\ + filter(Player.player_id > 2).\ + filter(Player.active_ind == True).all() + +for player in players: + req.matchdict['id'] = player.player_id + data = player_info_data(req) + rt = t.render(player=data['player'], elos_display=data['elos_display'], + total_stats=data['total_stats'], total_games=data['total_games'], + games_breakdown=data['games_breakdown']) + f = open("output/%s.html" % player.player_id, 'w') + f.write(rt) + f.close() + + cmd = "%s %s %s" % (CONVERTER, "output/%s.html" % player.player_id, + "output/%s.png" % player.player_id) + system(cmd) diff --git a/xonstat/batch/badges/img/dark_wall.png b/xonstat/batch/badges/img/dark_wall.png new file mode 100644 index 0000000..50a2f64 Binary files /dev/null and b/xonstat/batch/badges/img/dark_wall.png differ diff --git a/xonstat/batch/badges/templates/badge.html b/xonstat/batch/badges/templates/badge.html new file mode 100644 index 0000000..9c6e11f --- /dev/null +++ b/xonstat/batch/badges/templates/badge.html @@ -0,0 +1,31 @@ + + + + + +
+
+ + print('Antibody') + +
+ +
+ 218 games (144 duel, 41 ctf, 31 dm, 2 tdm) +
+ +
+ 111 wins, 107 losses (50.92%) +
+ +
+ 3084 kills, 2519 deaths (1.224) +
+ +
+ Elo: 375.091 (ctf), 358.604 (dm) +
+
+ + + diff --git a/xonstat/batch/badges/templates/badge.mako b/xonstat/batch/badges/templates/badge.mako new file mode 100644 index 0000000..e43089e --- /dev/null +++ b/xonstat/batch/badges/templates/badge.mako @@ -0,0 +1,39 @@ + + + + + +
+
+ + ${player.nick_html_colors()|n} + +
+ +
+ <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %> + ${total_games} (${games_breakdown_str}) +
+ +
+ % if total_games > 0 and total_stats['wins'] is not None: + ${total_stats['wins']} wins, ${total_games - total_stats['wins']} losses (${round(float(total_stats['wins'])/total_games * 100, 2)}%) + % endif +
+ +
+ % if total_stats['kills'] > 0 and total_stats['deaths'] > 0: + ${total_stats['kills']} kills, ${total_stats['deaths']} deaths (${round(float(total_stats['kills'])/total_stats['deaths'], 3)}) + % endif +
+ +
+ % if elos_display is not None and len(elos_display) > 0: + Elo: ${', '.join(elos_display[0:2])} + % endif +
+ +
+ + +