]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Replace the game_index view w/ game_finder.
authorAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 23:34:12 +0000 (19:34 -0400)
committerAnt Zucaro <azucaro@gmail.com>
Fri, 19 Apr 2013 23:34:12 +0000 (19:34 -0400)
The game_index view was cluttered, ugly, slow, and not used much.
This changeset makes the page similar to the "recent games" lists
throughout the app, but with a game type filter on it. This should
be a more useable alternative than showing a bunch of scoreboards.

xonstat/__init__.py
xonstat/templates/game_finder.mako
xonstat/templates/main_index.mako
xonstat/views/game.py
xonstat/views/helpers.py
xonstat/views/player.py

index 08946adb2431b7f7221216ed89dbaeb0f2fc2daf..bbd08bf7485559650228867bb59fd67d0ede5262 100644 (file)
@@ -74,10 +74,10 @@ def main(global_config, **settings):
     config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
 
     # GAME ROUTES
-    config.add_route("game_index",      "/games")
-    config.add_route("game_index_json", "/games.json")
-    config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
-    config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
+    config.add_route("game_index",      "/games")
+    config.add_route("game_index_json", "/games.json")
+    config.add_view(game_index,      route_name="game_index",      renderer="game_index.mako")
+    config.add_view(game_index_json, route_name="game_index_json", renderer="jsonp")
 
     config.add_route("game_info",      "/game/{id:\d+}")
     config.add_route("game_info_json", "/game/{id:\d+}.json")
@@ -89,8 +89,8 @@ def main(global_config, **settings):
     config.add_view(rank_index,      route_name="rank_index",      renderer="rank_index.mako")
     config.add_view(rank_index_json, route_name="rank_index_json", renderer="jsonp")
 
-    config.add_route("game_finder", "/gamefinder")
-    config.add_view(game_finder, route_name="game_finder", renderer="game_finder.mako")
+    config.add_route("game_index", "/games")
+    config.add_view(game_finder, route_name="game_index", renderer="game_finder.mako")
 
     # SERVER ROUTES
     config.add_route("server_index",      "/servers")
index cff48762af2548b38cf3f11200d5dd2bccdb21d4..fc96277480a0ec6557607e015ba05d1015e8b729 100644 (file)
@@ -11,10 +11,41 @@ ${nav.nav('games')}
     <link href="/static/css/sprites.css" rel="stylesheet">
 </%block>
 
+<%block name="title">
+Game Index
+</%block>
+
 % if len(recent_games) > 0:
+
+##### ROW OF GAME TYPE ICONS #####
+<div class="row">
+  <div class="span12 tabbable">
+    <ul class="nav nav-tabs">
+      % for gt in ('overall','duel','ctf','dm','tdm','ca','kh','ft','lms','as','dom','nb','cts','rc'):
+      <li 
+      % if game_type_cd == gt or (game_type_cd is None and gt == 'overall'):
+      class="active"
+      % endif
+      >
+
+      % if gt == 'overall':
+      <a href="${request.route_url("game_index")}" alt="${gt}" title="" data-toggle="none">
+      % else:
+      <a href="${request.route_url("game_index", _query={'type':gt})}" alt="${gt}" title="" data-toggle="none">
+      % endif
+        <span class="sprite sprite-${gt}"> </span><br />
+        ${gt} <br />
+      </a>
+      </li>
+      % endfor
+    </ul>
+    <br />
+  </div>
+</div>
+
+##### RECENT GAMES TABLE #####
 <div class="row">
   <div class="span12">
-    <h3>Recent Games</h3>
     <table class="table table-hover table-condensed">
       <thead>
         <tr>
@@ -48,5 +79,5 @@ ${nav.nav('games')}
 </div> <!-- /row -->
 
 <!-- navigation links -->
-${navlinks("game_finder", recent_games.page, recent_games.last_page, search_query=query)}
+${navlinks("game_index", recent_games.page, recent_games.last_page, search_query=query)}
 % endif
index b27efe412bdd94e285cc204ba1aee154b1762566..1814b2f1c06fba94b605de51dfc9f8a1bbb128a1 100644 (file)
@@ -199,7 +199,7 @@ Leaderboard
         % endfor
         </tbody>
     </table>
-    <p><a href="${request.route_url('game_finder')}">More...</a></p>
+    <p><a href="${request.route_url('game_index')}">More...</a></p>
   </div> <!-- /span12 -->
 </div> <!-- /row -->
 % endif
index d18da8f7c3dcea28747ed1f194124b345eae753d..f1ba46132d09f330529edf9aafa8f3f994605c2e 100644 (file)
@@ -12,6 +12,7 @@ from xonstat.views.helpers import RecentGame, recent_games_q
 log = logging.getLogger(__name__)
 
 
+# DEPRECATED
 def _game_index_data(request):
     game_type_cd = None
     game_type_descr = None
@@ -216,7 +217,9 @@ def game_finder_data(request):
     query = {}
 
     server_id, map_id, player_id = None, None, None
-    range_start, range_end = None, None
+    range_start, range_end, game_type_cd = None, None, None
+    game_type_descr = None
+
     # these become WHERE clauses when present
     if request.params.has_key('server_id'):
         server_id = request.params['server_id']
@@ -238,8 +241,18 @@ def game_finder_data(request):
         range_end = request.params['range_end']
         query['range_end'] = range_end
 
+    if request.params.has_key('type'):
+        game_type_cd = request.params['type']
+        query['type'] = game_type_cd
+        try:
+            game_type_descr = DBSession.query(GameType.descr).\
+                filter(GameType.game_type_cd == game_type_cd).\
+                one()[0]
+        except Exception as e:
+            game_type_cd = None
+
     rgs_q = recent_games_q(server_id=server_id, map_id=map_id,
-            player_id=player_id)
+            player_id=player_id, game_type_cd=game_type_cd)
 
     recent_games = Page(rgs_q, current_page, url=page_url)
 
@@ -248,6 +261,7 @@ def game_finder_data(request):
     return {
             'recent_games':recent_games,
             'query':query,
+            'game_type_cd':game_type_cd,
            }
 
 def game_finder(request):
index 2f2db70ee3e451312d0616fca930365f6a9122d8..a3b3f535136fe4cfd3754314b5d9068b6ec3d98c 100644 (file)
@@ -1,6 +1,7 @@
 import logging
 import sqlalchemy.sql.expression as expr
 from datetime import datetime
+from sqlalchemy.orm import aliased
 from xonstat.models import *
 from xonstat.util import *
 
@@ -75,7 +76,8 @@ class RecentGame(object):
         return "<RecentGame(id=%s, gametype=%s, server=%s, map=%s)>" % (self.game_id, self.game_type_cd, self.server_name, self.map_name)
 
 
-def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=None, cutoff=None):
+def recent_games_q(server_id=None, map_id=None, player_id=None,
+        game_type_cd=None, cutoff=None, force_player_id=False):
     '''
     Returns a SQLA query of recent game data. Parameters filter
     the results returned if they are provided. If not, it is
@@ -85,6 +87,8 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non
     look when querying. Only games that happened on or after the
     cutoff (which is a datetime object) will be returned.
     '''
+    pgstat_alias = aliased(PlayerGameStat, name='pgstat_alias')
+
     recent_games_q = DBSession.query(Game.game_id, GameType.game_type_cd,
             Game.winner, Game.start_dt, GameType.descr.label('game_type_descr'),
             Server.server_id, Server.name.label('server_name'), Map.map_id,
@@ -106,9 +110,18 @@ def recent_games_q(server_id=None, map_id=None, player_id=None, game_type_cd=Non
         recent_games_q = recent_games_q.\
             filter(Map.map_id==map_id)
 
+    # Note: force_player_id makes the pgstat row returned be from the
+    # specified player_id. Otherwise it will just look for a game
+    # *having* that player_id, but returning the #1 player's pgstat row
     if player_id is not None:
-        recent_games_q = recent_games_q.\
-            filter(PlayerGameStat.player_id==player_id)
+        if force_player_id:
+            recent_games_q = recent_games_q.\
+                filter(PlayerGameStat.player_id==player_id)
+        else:
+            recent_games_q = recent_games_q.\
+                filter(PlayerGameStat.rank==1).\
+                filter(Game.game_id==pgstat_alias.game_id).\
+                filter(pgstat_alias.player_id==player_id)
     else:
         recent_games_q = recent_games_q.\
             filter(PlayerGameStat.rank==1)
index 94fe8cb613d0bec6bce2cc3069f80933fbab90e3..370bace94251cae19f8465041db3a436df61c02f 100644 (file)
@@ -624,7 +624,8 @@ def player_game_index_data(request):
                 filter(Player.active_ind == True).\
                 one()
 
-        rgs_q = recent_games_q(player_id=player.player_id, game_type_cd=game_type_cd)
+        rgs_q = recent_games_q(player_id=player.player_id,
+            force_player_id=True, game_type_cd=game_type_cd)
 
         games = Page(rgs_q, current_page, items_per_page=10, url=page_url)