From: Ant Zucaro Date: Thu, 26 May 2011 16:36:43 +0000 (-0400) Subject: Move the accuracy table rendering into a callable template, modify views and other... X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=d30fa6dc7566c5bd5e7167742f59e287347cbce9;p=xonotic%2Fxonstat.git Move the accuracy table rendering into a callable template, modify views and other templates to suit. --- diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index 70c0197..2c2b7db 100755 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -1,4 +1,5 @@ <%inherit file="base.mako"/> +<%namespace file="accuracy.mako" import="accuracy" /> <%block name="title"> % if player: @@ -24,45 +25,10 @@ ${parent.title()} ##### ACCURACY ##### % if weapon_stats:

Accuracy

- - - - - - - - - - - -% for weapon_stat in weapon_stats: -<% -if weapon_stat[2] > 0: - damage_pct = round(float(weapon_stat[2])/weapon_stat[3]*100, 2) -else: - damage_pct = 0 -if weapon_stat[4] > 0: - hit_pct = round(float(weapon_stat[4])/weapon_stat[5]*100, 2) -else: - hit_pct = 0 -%> - - ## Note: the name of the image must match up with the weapon_cd - ## entry of that weapon, else this won't work - - - - - - - - - -% endfor -
WeaponHitFiredHit %Actual DamagePotential DamageDamage %
${weapon_stat[0]}${weapon_stat[4]}${weapon_stat[5]}${hit_pct}%${weapon_stat[2]}${weapon_stat[3]}${damage_pct}%
- +${accuracy(weapon_stats)} % endif + ##### RECENT GAMES ##### % if recent_games:

Recent Games

diff --git a/xonstat/templates/player_weapon_stats.mako b/xonstat/templates/player_weapon_stats.mako old mode 100644 new mode 100755 index 84c115d..34a5e41 --- a/xonstat/templates/player_weapon_stats.mako +++ b/xonstat/templates/player_weapon_stats.mako @@ -1,39 +1,21 @@ <%inherit file="base.mako"/> +<%namespace file="accuracy.mako" import="accuracy" /> <%block name="title"> Accuracy Information - ${parent.title()} -% if pwstats is None or pgstat is None or game is None: +% if weapon_stats is None or pgstat is None or game is None:

Sorry, I can't find those weapon stats!

Assume the best, though. Really.

% else:

Player Accuracy for ${pgstat.nick_html_colors()} in Game ${game.game_id}:

- - - - - - - - - - - -% for (pwstat, weapon) in pwstats: - - - - - - - - - - -% endfor -
WeaponFiredHitHit %Potential DamageActual DamageDamage %Frags
${weapon.descr}${pwstat.fired}${pwstat.hit}${round(float(pwstat.hit)/pwstat.fired*100, 2)}%${pwstat.max}${pwstat.actual}${round(float(pwstat.actual)/pwstat.max*100, 2)}%${pwstat.frags}
+## ACCURACY TABLE +% if weapon_stats: +${accuracy(weapon_stats)} +% endif + % endif diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 8db3c55..36e8b29 100755 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -17,7 +17,6 @@ def player_index(request): """ players = DBSession.query(Player) - log.debug("testing logging; entered PlayerHandler.index()") return {'players':players} def player_info(request): @@ -41,8 +40,6 @@ def player_info(request): "order by descr" ).params(player_id=player_id).all() - log.debug(weapon_stats) - recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\ filter(PlayerGameStat.player_id == player_id).\ filter(PlayerGameStat.game_id == Game.game_id).\ @@ -88,7 +85,6 @@ def player_game_index(request): except Exception as e: player = None games = None - raise e return {'player':player, 'games':games} @@ -109,18 +105,19 @@ def player_weapon_stats(request): order_by(Weapon.descr).\ all() + # turn this into something the accuracy template can use + weapon_stats = [] + for (pwstat, weapon) in pwstats: + weapon_stats.append((weapon.descr, pwstat.weapon_cd, pwstat.fired, + pwstat.hit, pwstat.max, pwstat.actual)) + pgstat = DBSession.query(PlayerGameStat).\ filter_by(player_game_stat_id=pgstat_id).one() game = DBSession.query(Game).filter_by(game_id=game_id).one() - log.debug(pwstats) - log.debug(pgstat) - log.debug(game) - except Exception as e: - pwstats = None + weapon_stats = None pgstat = None game = None - raise e - return {'pwstats':pwstats, 'pgstat':pgstat, 'game':game} + return {'weapon_stats':weapon_stats, 'pgstat':pgstat, 'game':game}