From: Ant Zucaro Date: Thu, 5 Oct 2017 01:00:04 +0000 (-0400) Subject: Initial display of the frag matrix. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=eedc246f8d3fc836c3f939cf7505a3f497bb3241;p=xonotic%2Fxonstat.git Initial display of the frag matrix. --- diff --git a/xonstat/templates/frag_matrix.mako b/xonstat/templates/frag_matrix.mako new file mode 100644 index 0000000..ee321b6 --- /dev/null +++ b/xonstat/templates/frag_matrix.mako @@ -0,0 +1,32 @@ +<%def name="frag_matrix(pgstats, matrix_by_pgstat_id)"> + +## Displays a frag matrix table, in scoreboardpos order from top to bottom and left to right + + + + + % for pgstat in pgstats: + + % endfor + + + % for fragger in pgstats: + + + % for victim in pgstats: + <% + pgfm = matrix_by_pgstat_id.get(fragger.player_game_stat_id) + + victim_pgfm = matrix_by_pgstat_id.get(victim.player_game_stat_id) + if victim_pgfm: + victim_index = str(victim_pgfm.player_index) + else: + victim_index = "-1" + %> + + % endfor + + % endfor +
${pgstat.nick_html_colors()|n}
${fragger.nick_html_colors()|n}${pgfm.matrix.get(victim_index, 0)}
+ + diff --git a/xonstat/templates/game_info.mako b/xonstat/templates/game_info.mako index 2b7cd70..fd46f8c 100644 --- a/xonstat/templates/game_info.mako +++ b/xonstat/templates/game_info.mako @@ -2,6 +2,7 @@ <%namespace name="nav" file="nav.mako" /> <%namespace file="scoreboard.mako" import="scoreboard" /> <%namespace file="accuracy.mako" import="accuracy" /> +<%namespace file="frag_matrix.mako" import="frag_matrix" /> <%block name="navigation"> ${nav.nav('games')} @@ -149,4 +150,14 @@ % endif + + % if show_frag_matrix: +
+
+

Frag Matrix

+ ${frag_matrix(pgstats, matrix_by_pgstat_id)} +
+
+ % endif + % endif diff --git a/xonstat/views/game.py b/xonstat/views/game.py index 3df051f..479b645 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -5,7 +5,7 @@ from pyramid import httpexceptions from sqlalchemy.orm.exc import * from webhelpers.paginate import Page from xonstat.models import DBSession, Server, Map, Game, PlayerGameStat, PlayerWeaponStat -from xonstat.models import TeamGameStat, PlayerRank, GameType, Weapon +from xonstat.models import PlayerGameFragMatrix, TeamGameStat, PlayerRank, GameType, Weapon from xonstat.util import page_url from xonstat.views.helpers import RecentGame, recent_games_q @@ -19,17 +19,18 @@ def _game_info_data(request): show_elo = bool(request.params.get("show_elo", False)) try: - (game, server, map, gametype) = DBSession.query(Game, Server, Map, GameType).\ - filter(Game.game_id == game_id).\ - filter(Game.server_id == Server.server_id).\ - filter(Game.map_id == Map.map_id).\ - filter(Game.game_type_cd == GameType.game_type_cd).one() - - pgstats = DBSession.query(PlayerGameStat).\ - filter(PlayerGameStat.game_id == game_id).\ - order_by(PlayerGameStat.scoreboardpos).\ - order_by(PlayerGameStat.score).\ - all() + (game, server, map, gametype) = DBSession.query(Game, Server, Map, GameType)\ + .filter(Game.game_id == game_id)\ + .filter(Game.server_id == Server.server_id)\ + .filter(Game.map_id == Map.map_id)\ + .filter(Game.game_type_cd == GameType.game_type_cd)\ + .one() + + pgstats = DBSession.query(PlayerGameStat)\ + .filter(PlayerGameStat.game_id == game_id)\ + .order_by(PlayerGameStat.scoreboardpos)\ + .order_by(PlayerGameStat.score)\ + .all() # Really old games don't have latency sent, so we have to check. If at # least one player has a latency value, we'll show the ping column. @@ -39,13 +40,12 @@ def _game_info_data(request): show_latency = True break - q = DBSession.query(TeamGameStat).\ - filter(TeamGameStat.game_id == game_id) + q = DBSession.query(TeamGameStat).filter(TeamGameStat.game_id == game_id) + if game.game_type_cd == 'ctf': q = q.order_by(TeamGameStat.caps.desc()) elif game.game_type_cd == 'ca': q = q.order_by(TeamGameStat.rounds.desc()) - # dom -> ticks, rc -> laps, nb -> goals, as -> objectives q = q.order_by(TeamGameStat.score.desc()) @@ -65,11 +65,11 @@ def _game_info_data(request): captimes = sorted(captimes, key=lambda x:x.fastest) pwstats = {} - for (pwstat, weapon) in DBSession.query(PlayerWeaponStat, Weapon).\ - filter(PlayerWeaponStat.game_id == game_id).\ - filter(PlayerWeaponStat.weapon_cd == Weapon.weapon_cd).\ - order_by(PlayerWeaponStat.actual.desc()).\ - all(): + for (pwstat, weapon) in DBSession.query(PlayerWeaponStat, Weapon)\ + .filter(PlayerWeaponStat.game_id == game_id)\ + .filter(PlayerWeaponStat.weapon_cd == Weapon.weapon_cd)\ + .order_by(PlayerWeaponStat.actual.desc())\ + .all(): if pwstat.player_game_stat_id not in pwstats: pwstats[pwstat.player_game_stat_id] = [] @@ -77,24 +77,37 @@ def _game_info_data(request): weapon.weapon_cd, pwstat.actual, pwstat.max, pwstat.hit, pwstat.fired, pwstat.frags)) + frag_matrix = DBSession.query(PlayerGameFragMatrix)\ + .filter(PlayerGameFragMatrix.game_id == game_id)\ + .all() + + matrix_by_pgstat_id = {e.player_game_stat_id: e for e in frag_matrix} + if len(matrix_by_pgstat_id): + show_frag_matrix = True + else: + show_frag_matrix = False + except NoResultFound as e: raise httpexceptions.HTTPNotFound("Could not find that game!") except Exception as e: raise e - return {'game':game, - 'server':server, - 'map':map, - 'gametype':gametype, - 'pgstats':pgstats, - 'tgstats':tgstats, - 'pwstats':pwstats, - 'captimes':captimes, - 'show_elo':show_elo, - 'show_latency':show_latency, - 'stats_by_team':stats_by_team, - } + return { + 'game': game, + 'server': server, + 'map': map, + 'gametype': gametype, + 'pgstats': pgstats, + 'tgstats': tgstats, + 'pwstats': pwstats, + 'captimes': captimes, + 'show_elo': show_elo, + 'show_latency': show_latency, + 'stats_by_team': stats_by_team, + 'show_frag_matrix': show_frag_matrix, + 'matrix_by_pgstat_id': matrix_by_pgstat_id, + } def game_info(request):