Revision: ${server.revision} <br />
Created: ${server.create_dt.strftime('%m/%d/%Y at %I:%M %p')} <br />
-% if recent_games:
+
+##### RECENT GAMES #####
<h2>Recent Games</h2>
-% for (game, theserver, map) in recent_games:
- <a href="${request.route_url("game_info", id=game.game_id)}" name="Game info page for game #${game.game_id}">#${game.game_id}</a>: <a href="${request.route_url("map_info", id=map.map_id)}" name="Map info page for ${map.name}">${map.name}</a>
-<br />
-% endfor
-<a href="${request.route_url("server_game_index", server_id=server.server_id, page=1)}" name="Game index page for server #${server.name}">More games played on ${server.name}...</a>
-% endif
+<table id="recent-games">
+ <thead>
+ <tr>
+ <th>Game #</th>
+ <th>Type</th>
+ <th>Map</th>
+ <th>Time</th>
+ <th>Winner</th>
+ </tr>
+ </thead>
+ <tbody>
+ % for (game, srv, map, pgstat) in recent_games:
+ % if game != '-':
+ <tr>
+ <td><a href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">${game.game_id}</a></td>
+ <td class="gt_icon"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
+ <td><a href="${request.route_url('map_info', id=map.map_id)}" title="Go to the map detail page for this map">${map.name}</a></td>
+ <td>${game.start_dt.strftime('%m/%d/%Y %H:%M')}</td>
+ <td class=
+ % if pgstat.team == 5:
+ "blue"
+ % elif pgstat.team == 14:
+ "red"
+ % elif pgstat.team == 13:
+ "yellow"
+ % endif
+ >
+ % if pgstat.player_id > 2:
+ <a href="${request.route_url('player_info', id=pgstat.player_id)}" title="Go to the player info page for this player">${pgstat.nick_html_colors()}</a></td>
+ % else:
+ ${pgstat.nick_html_colors()}</td>
+ % endif
+ </tr>
+ % else:
+ <tr>
+ <td>-</td>
+ <td>-</td>
+ <td>-</td>
+ <td>-</td>
+ <td>-</td>
+ </tr>
+ % endif
+ % endfor
+ </tbody>
+</table>
+
+
+##### TOP PLAYERS #####
+<div class="table_block">
+<h2>Most Active Players</h2>
+<table id="top-players">
+ <thead>
+ <tr>
+ <th>#</th>
+ <th>Nick</th>
+ <th>Playing Time</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% i = 1 %>
+ % for (player_id, nick, alivetime) in top_players:
+ <tr>
+ <td>${i}</td>
+ % if player_id != '-':
+ <td><a href="${request.route_url('player_info', id=player_id)}" title="Go to the player info page for this player">${nick|n}</a></td>
+ % else:
+ <td>${nick}</td>
+ % endif
+ <td>${alivetime}</td>
+ </tr>
+ <% i = i+1 %>
+ % endfor
+ </tbody>
+</table>
+</div>
+
+
+##### TOP MAPS #####
+<div class="table_block">
+<h2>Most Active Maps</h2>
+<table id="top-maps">
+ <thead>
+ <tr>
+ <th>#</th>
+ <th>Map</th>
+ <th># Games</th>
+ </tr>
+ </thead>
+ <tbody>
+ <% i = 1 %>
+ % for (map_id, name, count) in top_maps:
+ <tr>
+ <td>${i}</td>
+ % if map_id != '-':
+ <td><a href="${request.route_url('map_info', id=map_id)}" title="Go to the map info page for ${name}">${name}</a></td>
+ % else:
+ <td>${name}</td>
+ % endif
+ <td>${count}</td>
+ </tr>
+ <% i = i+1 %>
+ % endfor
+ </tbody>
+</table>
+</div>
+
% endif
-import datetime\r
import logging\r
+import sqlalchemy.sql.functions as func\r
+import sqlalchemy.sql.expression as expr\r
import time\r
+from datetime import datetime, timedelta\r
+from pyramid.config import get_current_registry\r
from pyramid.response import Response\r
from sqlalchemy import desc\r
from webhelpers.paginate import Page, PageURL\r
from xonstat.models import *\r
-from xonstat.util import page_url\r
+from xonstat.util import page_url, html_colors\r
\r
log = logging.getLogger(__name__)\r
\r
List the stored information about a given server.\r
"""\r
server_id = request.matchdict['id']\r
+\r
+ # get settings specific to this view\r
+ settings = get_current_registry().settings\r
+ try: \r
+ leaderboard_lifetime = int(\r
+ settings['xonstat.leaderboard_lifetime'])\r
+ except:\r
+ leaderboard_lifetime = 30\r
+\r
+ leaderboard_count = 10\r
+ recent_games_count = 20\r
+\r
try:\r
server = DBSession.query(Server).filter_by(server_id=server_id).one()\r
- recent_games = DBSession.query(Game, Server, Map).\\r
- filter(Game.server_id == server_id).\\r
- filter(Game.server_id == Server.server_id).\\r
- filter(Game.map_id == Map.map_id).\\r
- order_by(Game.game_id.desc())[0:10]\r
+\r
+ # top maps by total times played\r
+ top_maps = DBSession.query(Game.map_id, Map.name, \r
+ func.count()).\\r
+ filter(Map.map_id==Game.map_id).\\r
+ filter(Game.server_id==server.server_id).\\r
+ filter(Game.create_dt > \r
+ (datetime.now() - timedelta(days=leaderboard_lifetime))).\\r
+ order_by(expr.desc(func.count())).\\r
+ group_by(Game.map_id).\\r
+ group_by(Map.name).all()[0:10]\r
+\r
+ for i in range(leaderboard_count-len(top_maps)):\r
+ top_maps.append(('-', '-', '-'))\r
+\r
+ # top players by playing time\r
+ top_players = DBSession.query(Player.player_id, Player.nick, \r
+ func.sum(PlayerGameStat.alivetime)).\\r
+ filter(Player.player_id == PlayerGameStat.player_id).\\r
+ filter(Game.game_id == PlayerGameStat.game_id).\\r
+ filter(Game.server_id == server.server_id).\\r
+ filter(Player.player_id > 2).\\r
+ filter(PlayerGameStat.create_dt > \r
+ (datetime.now() - timedelta(days=leaderboard_lifetime))).\\r
+ order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\\r
+ group_by(Player.nick).\\r
+ group_by(Player.player_id).all()[0:10]\r
+\r
+ top_players = [(player_id, html_colors(nick), score) \\r
+ for (player_id, nick, score) in top_players]\r
+\r
+ for i in range(leaderboard_count-len(top_players)):\r
+ top_players.append(('-', '-', '-'))\r
+\r
+ # recent games played in descending order\r
+ recent_games = DBSession.query(Game, Server, Map, PlayerGameStat).\\r
+ filter(Game.server_id==Server.server_id).\\r
+ filter(Game.map_id==Map.map_id).\\r
+ filter(PlayerGameStat.game_id==Game.game_id).\\r
+ filter(PlayerGameStat.rank==1).\\r
+ filter(Server.server_id==server.server_id).\\r
+ order_by(expr.desc(Game.start_dt)).all()[0:recent_games_count]\r
+\r
+ for i in range(recent_games_count-len(recent_games)):\r
+ recent_games.append(('-', '-', '-', '-'))\r
\r
except Exception as e:\r
server = None\r
recent_games = None\r
+ top_players = None\r
+ raise e\r
return {'server':server,\r
- 'recent_games':recent_games}\r
+ 'recent_games':recent_games,\r
+ 'top_players': top_players,\r
+ 'top_maps': top_maps,\r
+ }\r
\r
\r
def server_game_index(request):\r