]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Add views for player captimes (all the fastest caps per player) and map captimes...
authorJan Behrens <zykure@web.de>
Wed, 16 Jan 2013 17:40:09 +0000 (18:40 +0100)
committerJan Behrens <zykure@web.de>
Wed, 16 Jan 2013 18:01:12 +0000 (19:01 +0100)
xonstat/__init__.py
xonstat/templates/map_captimes.mako [new file with mode: 0644]
xonstat/templates/player_captimes.mako [new file with mode: 0644]
xonstat/views/__init__.py
xonstat/views/map.py
xonstat/views/player.py

index d4ccfde2e5590fa158414ff2d3e721e279daafb8..93a43d5d386d1285b93880024ae168a6fabfed50 100644 (file)
@@ -54,9 +54,9 @@ def main(global_config, **settings):
     config.add_view(player_elo_info_json, route_name="player_elo_info_json", renderer="jsonp")
 
     config.add_route("player_accuracy",      "/player/{id:\d+}/accuracy")
-    config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
+    #config.add_route("player_accuracy_json", "/player/{id:\d+}/accuracy.json")
     config.add_view(player_accuracy_json, route_name="player_accuracy",      renderer="jsonp")
-    config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="jsonp")
+    #config.add_view(player_accuracy_json, route_name="player_accuracy_json", renderer="jsonp")
 
     config.add_route("player_index",      "/players")
     config.add_route("player_index_json", "/players.json")
@@ -64,8 +64,12 @@ def main(global_config, **settings):
     config.add_view(player_index_json, route_name="player_index_json", renderer="jsonp")
 
     config.add_route("player_damage", "/player/{id:\d+}/damage")
-    config.add_view(player_damage_json, route_name="player_damage",
-        renderer="json")
+    config.add_view(player_damage_json, route_name="player_damage", renderer="jsonp")
+
+    config.add_route("player_captimes",      "/player/{id:\d+}/captimes")
+    config.add_route("player_captimes_json", "/player/{id:\d+}/captimes.json")
+    config.add_view(player_captimes,      route_name="player_captimes",      renderer="player_captimes.mako")
+    config.add_view(player_captimes_json, route_name="player_captimes_json", renderer="jsonp")
 
     # GAME ROUTES
     config.add_route("game_index",      "/games")
@@ -113,6 +117,11 @@ def main(global_config, **settings):
     config.add_view(map_info,      route_name="map_info",      renderer="map_info.mako")
     config.add_view(map_info_json, route_name="map_info_json", renderer="jsonp")
 
+    config.add_route("map_captimes",      "/map/{id:\d+}/captimes")
+    config.add_route("map_captimes_json", "/map/{id:\d+}/captimes.json")
+    config.add_view(map_captimes,      route_name="map_captimes",      renderer="map_captimes.mako")
+    config.add_view(map_captimes_json, route_name="map_captimes_json", renderer="jsonp")
+
     # SEARCH ROUTES
     config.add_route("search",      "search")
     config.add_route("search_json", "search.json")
diff --git a/xonstat/templates/map_captimes.mako b/xonstat/templates/map_captimes.mako
new file mode 100644 (file)
index 0000000..1591cc4
--- /dev/null
@@ -0,0 +1,40 @@
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="title">
+Map captimes
+</%block>
+
+
+<div class="row">
+  <div class="span12">
+
+    <h2>${map.name}</h2>
+    <p><a href="${map_url}">Back to map info page</a></p>
+
+    <h3>Fastest flag capture times:</h3>
+
+    <table class="table table-bordered table-condensed">
+      <thead>
+        <tr>
+           <th>Game</th>
+           <th>Captime</th>
+           <th>Nick</th>
+           <th>Server</th>
+           <th>Date</th>
+        </tr>
+      </thead>
+      <tbody>
+      % for ct in captimes:
+        <tr>
+          <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
+          <td>${ct.fastest_cap.total_seconds()} seconds</td>
+          <td><span class="nick">${ct.player_nick_html|n}</span></td>
+          <td><a href="${request.route_url('server_info', id=ct.server_id)}" title="Go to the detail page for this server">${ct.server_name}</a></td>
+          <td><span class="abstime" data-epoch="${ct.create_dt_epoch}" title="${ct.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${ct.create_dt_fuzzy}</span></td>
+      % endfor
+      </tbody>
+    </table>
+
+  </div>
+</div>
diff --git a/xonstat/templates/player_captimes.mako b/xonstat/templates/player_captimes.mako
new file mode 100644 (file)
index 0000000..96d8ff7
--- /dev/null
@@ -0,0 +1,41 @@
+<%inherit file="base.mako"/>
+<%namespace name="nav" file="nav.mako" />
+
+<%block name="title">
+Player captimes
+</%block>
+
+<div class="row">
+  <div class="span12">
+
+    <h2><span class="nick">${player.nick_html_colors()|n}</span></h2>
+    <p><a href="${player_url}">Back to player info page</a></p>
+
+    <h3>Fastest flag capture times:</h3>
+
+    <table class="table table-bordered table-condensed">
+      <thead>
+        <tr>
+           <th>Game</th>
+           <th>Captime</th>
+           ##<th>Nick</th>
+           <th>Map</th>
+           <th>Server</th>
+           <th>Date</th>
+        </tr>
+      </thead>
+      <tbody>
+      % for ct in captimes:
+        <tr>
+          <td class="tdcenter"><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=ct.game_id)}" title="View detailed information about this game">view</a></td>
+          <td>${ct.fastest_cap.total_seconds()} seconds</td>
+          ##<td><span class="nick">${ct.html_nick|n}</span></td>
+          <td><a href="${request.route_url('map_info', id=ct.map_id)}" title="Go to the detail page for this map">${ct.map_name}</a></td>
+          <td><a href="${request.route_url('server_info', id=ct.server_id)}" title="Go to the detail page for this server">${ct.server_name}</a></td>
+          <td><span class="abstime" data-epoch="${ct.create_dt_epoch}" title="${ct.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${ct.create_dt_fuzzy}</span></td>
+      % endfor
+      </tbody>
+    </table>
+
+  </div>
+</div>
index 0d9fd13bf8075a88b794a778c6aa76d7c796faee..d3097dd0f164514746b51d6e635fa2b01a2a4378 100644 (file)
@@ -5,6 +5,7 @@ from xonstat.views.player import player_index_json, player_info_json
 from xonstat.views.player import player_game_index_json, player_accuracy_json
 from xonstat.views.player import player_damage_json, player_hashkey_info_json
 from xonstat.views.player import player_hashkey_info_text, player_elo_info_json
+from xonstat.views.player import player_captimes, player_captimes_json
 
 from xonstat.views.game   import game_index, game_info, rank_index
 from xonstat.views.game   import game_index_json, game_info_json, rank_index_json
@@ -12,6 +13,7 @@ from xonstat.views.game   import game_finder
 
 from xonstat.views.map    import map_info, map_index
 from xonstat.views.map    import map_info_json, map_index_json
+from xonstat.views.map    import map_captimes, map_captimes_json
 
 from xonstat.views.server import server_info, server_game_index, server_index
 from xonstat.views.server import server_info_json, server_game_index_json
index 6ecbf371760dfa6c1adce920a5468b0cab46835f..4c65a2d45a44ecfe29be115c85d7aa1607c3f9a3 100644 (file)
@@ -38,7 +38,7 @@ def map_index(request):
 
 def map_index_json(request):
     """
-    Provides a JSON-serialized list of all the current maps. 
+    Provides a JSON-serialized list of all the current maps.
     """
     view_data = _map_index_data(request)
 
@@ -50,7 +50,7 @@ def map_index_json(request):
 def _map_info_data(request):
     map_id = request.matchdict['id']
 
-    try: 
+    try:
         leaderboard_lifetime = int(
                 request.registry.settings['xonstat.leaderboard_lifetime'])
     except:
@@ -77,7 +77,7 @@ def _map_info_data(request):
                 filter(Game.game_id == PlayerGameStat.game_id).\
                 filter(Game.map_id == map_id).\
                 filter(Player.player_id > 2).\
-                filter(PlayerGameStat.create_dt > 
+                filter(PlayerGameStat.create_dt >
                         (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
                 order_by(expr.desc(func.sum(PlayerGameStat.score))).\
                 group_by(Player.nick).\
@@ -87,13 +87,13 @@ def _map_info_data(request):
                 for (player_id, nick, score) in top_scorers]
 
         # top players by playing time
-        top_players = DBSession.query(Player.player_id, Player.nick, 
+        top_players = DBSession.query(Player.player_id, Player.nick,
                 func.sum(PlayerGameStat.alivetime)).\
                 filter(Player.player_id == PlayerGameStat.player_id).\
                 filter(Game.game_id == PlayerGameStat.game_id).\
                 filter(Game.map_id == map_id).\
                 filter(Player.player_id > 2).\
-                filter(PlayerGameStat.create_dt > 
+                filter(PlayerGameStat.create_dt >
                         (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
                 order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\
                 group_by(Player.nick).\
@@ -103,11 +103,11 @@ def _map_info_data(request):
                 for (player_id, nick, score) in top_players]
 
         # top servers using/playing this map
-        top_servers = DBSession.query(Server.server_id, Server.name, 
+        top_servers = DBSession.query(Server.server_id, Server.name,
                 func.count(Game.game_id)).\
                 filter(Game.server_id == Server.server_id).\
                 filter(Game.map_id == map_id).\
-                filter(Game.create_dt > 
+                filter(Game.create_dt >
                         (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\
                 order_by(expr.desc(func.count(Game.game_id))).\
                 group_by(Server.name).\
@@ -162,3 +162,66 @@ def map_info_json(request):
     List the information stored about a given map. JSON.
     """
     return [{'status':'not implemented'}]
+
+
+def map_captimes_data(request):
+    map_id = int(request.matchdict['id'])
+
+    MapCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+        'player_id', 'player_nick', 'player_nick_stripped', 'player_nick_html',
+        'game_id', 'server_id', 'server_name'])
+
+    dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id',
+                'server_id', 'server_name', 'player_nick').\
+            from_statement(
+                "SELECT ct.fastest_cap, "
+                       "ct.create_dt, "
+                       "ct.player_id, "
+                       "ct.game_id, "
+                       "g.server_id, "
+                       "s.name server_name, "
+                       "pgs.nick player_nick "
+                "FROM   player_map_captimes ct, "
+                       "games g, "
+                       "maps m, "
+                       "servers s, "
+                       "player_game_stats pgs "
+                "WHERE  ct.map_id = :map_id "
+                  "AND  g.game_id = ct.game_id "
+                  "AND  g.server_id = s.server_id "
+                  "AND  m.map_id = ct.map_id "
+                  "AND  pgs.player_id = ct.player_id "
+                  "AND  pgs.game_id = ct.game_id "
+                "ORDER  BY ct.fastest_cap "
+            ).params(map_id=map_id).all()
+
+    mmap = DBSession.query(Map).filter_by(map_id=map_id).one()
+
+    map_captimes = []
+    for row in dbquery:
+        map_captimes.append(MapCaptimes(
+                fastest_cap=row.fastest_cap,
+                create_dt=row.create_dt,
+                create_dt_epoch=timegm(row.create_dt.timetuple()),
+                create_dt_fuzzy=pretty_date(row.create_dt),
+                player_id=row.player_id,
+                player_nick=row.player_nick,
+                player_nick_stripped=strip_colors(row.player_nick),
+                player_nick_html=html_colors(row.player_nick),
+                game_id=row.game_id,
+                server_id=row.server_id,
+                server_name=row.server_name,
+            ))
+
+    return {
+            'captimes':map_captimes,
+            'map_id':map_id,
+            'map_url':request.route_url('map_info', id=map_id),
+            'map':mmap,
+        }
+
+def map_captimes(request):
+    return map_captimes_data(request)
+
+def map_captimes_json(request):
+    return map_captimes_data(request)
index 24a6f26122f439dfd537c6de2e9ebcd8082ceea0..33b4774c88e5472754c5402995ff1231ab709793 100644 (file)
@@ -12,7 +12,7 @@ from pyramid.url import current_route_url
 from sqlalchemy import desc, distinct
 from webhelpers.paginate import Page, PageURL
 from xonstat.models import *
-from xonstat.util import page_url, to_json, pretty_date, datetime_seconds
+from xonstat.util import page_url, to_json, pretty_date, datetime_seconds, html_colors
 from xonstat.views.helpers import RecentGame, recent_games_q
 
 log = logging.getLogger(__name__)
@@ -272,7 +272,7 @@ def get_fav_maps(player_id, game_type_cd=None):
             map_id=row.map_id,
             times_played=row.times_played,
             game_type_cd=row.game_type_cd)
-    
+
         # if we aren't given a favorite game_type_cd
         # then the overall favorite is the one we've
         # played the most
@@ -302,7 +302,7 @@ def get_ranks(player_id):
 
     The key to the dictionary is the game type code. There is also an
     "overall" game_type_cd which is the overall best rank.
-    """    
+    """
     Rank = namedtuple('Rank', ['rank', 'max_rank', 'percentile', 'game_type_cd'])
 
     raw_ranks = DBSession.query("game_type_cd", "rank", "max_rank").\
@@ -412,7 +412,7 @@ def get_accuracy_stats(player_id, weapon_cd, games):
 
         # Determine the raw accuracy (hit, fired) numbers for $games games
         # This is then enumerated to create parameters for a flot graph
-        raw_accs = DBSession.query(PlayerWeaponStat.game_id, 
+        raw_accs = DBSession.query(PlayerWeaponStat.game_id,
             PlayerWeaponStat.hit, PlayerWeaponStat.fired).\
                 filter(PlayerWeaponStat.player_id == player_id).\
                 filter(PlayerWeaponStat.weapon_cd == weapon_cd).\
@@ -448,7 +448,7 @@ def get_damage_stats(player_id, weapon_cd, games):
 
         # Determine the damage efficiency (hit, fired) numbers for $games games
         # This is then enumerated to create parameters for a flot graph
-        raw_dmgs = DBSession.query(PlayerWeaponStat.game_id, 
+        raw_dmgs = DBSession.query(PlayerWeaponStat.game_id,
             PlayerWeaponStat.actual, PlayerWeaponStat.hit).\
                 filter(PlayerWeaponStat.player_id == player_id).\
                 filter(PlayerWeaponStat.weapon_cd == weapon_cd).\
@@ -526,7 +526,7 @@ def player_info_json(request):
     """
 
     # All player_info fields are converted into JSON-formattable dictionaries
-    player_info = player_info_data(request)    
+    player_info = player_info_data(request)
 
     player = player_info['player'].to_dict()
 
@@ -646,11 +646,11 @@ def player_accuracy_data(request):
         games = len(accs)
 
     return {
-            'player_id':player_id, 
-            'player_url':request.route_url('player_info', id=player_id), 
-            'weapon':weapon_cd, 
-            'games':games, 
-            'avg':avg, 
+            'player_id':player_id,
+            'player_url':request.route_url('player_info', id=player_id),
+            'weapon':weapon_cd,
+            'games':games,
+            'avg':avg,
             'accs':accs
             }
 
@@ -703,11 +703,11 @@ def player_damage_data(request):
         games = len(dmgs)
 
     return {
-            'player_id':player_id, 
-            'player_url':request.route_url('player_info', id=player_id), 
-            'weapon':weapon_cd, 
-            'games':games, 
-            'avg':avg, 
+            'player_id':player_id,
+            'player_url':request.route_url('player_info', id=player_id),
+            'weapon':weapon_cd,
+            'games':games,
+            'avg':avg,
             'dmgs':dmgs
             }
 
@@ -868,3 +868,69 @@ def player_elo_info_json(request):
         'version':          1,
         'elos':             elos,
     }]
+
+def player_captimes_data(request):
+    player_id = int(request.matchdict['id'])
+    if player_id <= 2:
+        player_id = -1;
+
+    #player_captimes = DBSession.query(PlayerCaptime).\
+    #        filter(PlayerCaptime.player_id==player_id).\
+    #        order_by(PlayerCaptime.fastest_cap).\
+    #        all()
+
+    PlayerCaptimes = namedtuple('PlayerCaptimes', ['fastest_cap', 'create_dt', 'create_dt_epoch', 'create_dt_fuzzy',
+        'player_id', 'game_id', 'map_id', 'map_name', 'server_id', 'server_name'])
+
+    dbquery = DBSession.query('fastest_cap', 'create_dt', 'player_id', 'game_id', 'map_id',
+                'map_name', 'server_id', 'server_name').\
+            from_statement(
+                "SELECT ct.fastest_cap, "
+                       "ct.create_dt, "
+                       "ct.player_id, "
+                       "ct.game_id, "
+                       "ct.map_id, "
+                       "m.name map_name, "
+                       "g.server_id, "
+                       "s.name server_name "
+                "FROM   player_map_captimes ct, "
+                       "games g, "
+                       "maps m, "
+                       "servers s "
+                "WHERE  ct.player_id = :player_id "
+                  "AND  g.game_id = ct.game_id "
+                  "AND  g.server_id = s.server_id "
+                  "AND  m.map_id = ct.map_id "
+                #"ORDER  BY ct.fastest_cap "
+                "ORDER  BY ct.create_dt desc"
+            ).params(player_id=player_id).all()
+
+    player = DBSession.query(Player).filter_by(player_id=player_id).one()
+
+    player_captimes = []
+    for row in dbquery:
+        player_captimes.append(PlayerCaptimes(
+                fastest_cap=row.fastest_cap,
+                create_dt=row.create_dt,
+                create_dt_epoch=timegm(row.create_dt.timetuple()),
+                create_dt_fuzzy=pretty_date(row.create_dt),
+                player_id=row.player_id,
+                game_id=row.game_id,
+                map_id=row.map_id,
+                map_name=row.map_name,
+                server_id=row.server_id,
+                server_name=row.server_name,
+            ))
+
+    return {
+            'captimes':player_captimes,
+            'player_id':player_id,
+            'player_url':request.route_url('player_info', id=player_id),
+            'player':player,
+        }
+
+def player_captimes(request):
+    return player_captimes_data(request)
+
+def player_captimes_json(request):
+    return player_captimes_data(request)