]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Initial display of the frag matrix.
authorAnt Zucaro <azucaro@gmail.com>
Thu, 5 Oct 2017 01:00:04 +0000 (21:00 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Thu, 5 Oct 2017 01:00:04 +0000 (21:00 -0400)
xonstat/templates/frag_matrix.mako [new file with mode: 0644]
xonstat/templates/game_info.mako
xonstat/views/game.py

diff --git a/xonstat/templates/frag_matrix.mako b/xonstat/templates/frag_matrix.mako
new file mode 100644 (file)
index 0000000..ee321b6
--- /dev/null
@@ -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
+
+<table class="table-hover table-condensed">
+  <thead>
+    <th></th>
+    % for pgstat in pgstats:
+    <th>${pgstat.nick_html_colors()|n}</th>
+    % endfor
+  </thead>
+
+  % for fragger in pgstats:
+  <tr>
+    <td>${fragger.nick_html_colors()|n}</td>
+    % 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"
+    %>
+    <td>${pgfm.matrix.get(victim_index, 0)}</td>
+    % endfor
+  </tr>
+  % endfor
+</table>
+
+</%def>
index 2b7cd70670330224e6d0011b6eaea834e9f69f7e..fd46f8c60cb970c8d1bb5cd81a1a8902e33528dd 100644 (file)
@@ -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')}
         </div>
       </div>
   % endif
+
+  % if show_frag_matrix:
+    <div class="row">
+      <div class="small-12 columns">
+        <h3>Frag Matrix</h3>
+        ${frag_matrix(pgstats, matrix_by_pgstat_id)}
+      </div>
+    </div>
+  % endif
+
 % endif
index 3df051f4e5e7b464673f149b483db8a5f9ab79e8..479b645d2c4142ac7d489d4d8892b6883cbfd00d 100644 (file)
@@ -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):