renderer="player_info.mako")
config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
- config.add_view(player_accuracy, route_name="player_accuracy",
+ config.add_view(player_accuracy_json, route_name="player_accuracy",
renderer="json")
# GAME ROUTES
from xonstat.views.submission import stats_submit\r
from xonstat.views.player import player_index, player_info, player_game_index\r
-from xonstat.views.player import player_accuracy\r
+from xonstat.views.player import player_accuracy_json\r
from xonstat.views.game import game_index, game_info, rank_index\r
from xonstat.views.map import map_info, map_index, map_index_json\r
from xonstat.views.server import server_info, server_game_index, server_index\r
-from xonstat.views.search import *\r
+from xonstat.views.search import search_q, search\r
from xonstat.views.main import main_index\r
log = logging.getLogger(__name__)\r
\r
\r
-def game_index(request):\r
- """\r
- Provides a list of current games, with the associated game stats.\r
- These games are ordered by game_id, with the most current ones first.\r
- Paginated.\r
- """\r
+def _game_index_data(request):\r
if request.params.has_key('page'):\r
current_page = request.params['page']\r
else:\r
'pgstats':pgstats}\r
\r
\r
-def game_info(request):\r
+def game_index(request):\r
"""\r
- List the game stats (scoreboard) for a particular game. Paginated.\r
+ Provides a list of current games, with the associated game stats.\r
+ These games are ordered by game_id, with the most current ones first.\r
+ Paginated.\r
"""\r
+ return _game_index_data(request)\r
+\r
+\r
+def _game_info_data(request):\r
game_id = request.matchdict['id']\r
try:\r
notfound = False\r
}\r
\r
\r
-def rank_index(request):\r
+def game_info(request):\r
"""\r
- Provide a list of gametype ranks, paginated.\r
+ List the game stats (scoreboard) for a particular game. Paginated.\r
"""\r
+ return _game_info_data(request)\r
+\r
+\r
+def _rank_index_data(request):\r
if request.params.has_key('page'):\r
current_page = request.params['page']\r
else:\r
'ranks':ranks,\r
'game_type_cd':game_type_cd,\r
}\r
+\r
+\r
+def rank_index(request):\r
+ """\r
+ Provide a list of gametype ranks, paginated.\r
+ """\r
+ return _rank_index_data(request)\r
log = logging.getLogger(__name__)
-def main_index(request):
+def _main_index_data(request):
try:
leaderboard_lifetime = int(
request.registry.settings['xonstat.leaderboard_lifetime'])
PlayerRank.elo).\
filter(PlayerRank.game_type_cd=='duel').\
order_by(PlayerRank.rank).\
- limit(10).all()
+ limit(leaderboard_count).all()
duel_ranks = [(player_id, html_colors(nick), elo) \
for (player_id, nick, elo) in duel_ranks]
- for i in range(leaderboard_count-len(duel_ranks)):
- duel_ranks.append(('-', '-', '-'))
-
# top ranked CTF-ers
ctf_ranks = DBSession.query(PlayerRank.player_id, PlayerRank.nick,
PlayerRank.elo).\
filter(PlayerRank.game_type_cd=='ctf').\
order_by(PlayerRank.rank).\
- limit(10).all()
+ limit(leaderboard_count).all()
ctf_ranks = [(player_id, html_colors(nick), elo) \
for (player_id, nick, elo) in ctf_ranks]
- for i in range(leaderboard_count-len(ctf_ranks)):
- ctf_ranks.append(('-', '-', '-'))
-
# top ranked DM-ers
dm_ranks = DBSession.query(PlayerRank.player_id, PlayerRank.nick,
PlayerRank.elo).\
filter(PlayerRank.game_type_cd=='dm').\
order_by(PlayerRank.rank).\
- limit(10).all()
+ limit(leaderboard_count).all()
dm_ranks = [(player_id, html_colors(nick), elo) \
for (player_id, nick, elo) in dm_ranks]
- for i in range(leaderboard_count-len(dm_ranks)):
- dm_ranks.append(('-', '-', '-'))
-
right_now = datetime.utcnow()
back_then = datetime.utcnow() - timedelta(days=leaderboard_lifetime)
filter(expr.between(PlayerGameStat.create_dt, back_then, right_now)).\
order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\
group_by(Player.nick).\
- group_by(Player.player_id).limit(10).all()
+ group_by(Player.player_id).limit(leaderboard_count).all()
top_players = [(player_id, html_colors(nick), score) \
for (player_id, nick, score) in top_players]
- for i in range(leaderboard_count-len(top_players)):
- top_players.append(('-', '-', '-'))
-
# top servers by number of total players played
top_servers = DBSession.query(Server.server_id, Server.name,
func.count()).\
filter(expr.between(Game.create_dt, back_then, right_now)).\
order_by(expr.desc(func.count(Game.game_id))).\
group_by(Server.server_id).\
- group_by(Server.name).limit(10).all()
-
- for i in range(leaderboard_count-len(top_servers)):
- top_servers.append(('-', '-', '-'))
+ group_by(Server.name).limit(leaderboard_count).all()
# top maps by total times played
top_maps = DBSession.query(Game.map_id, Map.name,
filter(expr.between(Game.create_dt, back_then, right_now)).\
order_by(expr.desc(func.count())).\
group_by(Game.map_id).\
- group_by(Map.name).limit(10).all()
-
- for i in range(leaderboard_count-len(top_maps)):
- top_maps.append(('-', '-', '-'))
+ group_by(Map.name).limit(leaderboard_count).all()
# recent games played in descending order
recent_games = DBSession.query(Game, Server, Map, PlayerGameStat).\
filter(expr.between(Game.create_dt, back_then, right_now)).\
order_by(expr.desc(Game.start_dt)).limit(recent_games_count).all()
- for i in range(recent_games_count-len(recent_games)):
- recent_games.append(('-', '-', '-', '-'))
-
return {'top_players':top_players,
'top_servers':top_servers,
'top_maps':top_maps,
'ctf_ranks':ctf_ranks,
'dm_ranks':dm_ranks,
}
+
+
+def main_index(request):
+ """
+ Display the main page information.
+ """
+ mainindex_data = _main_index_data(request)
+
+ # FIXME: code clone, should get these from _main_index_data
+ leaderboard_count = 10
+ recent_games_count = 20
+
+ for i in range(leaderboard_count-len(mainindex_data['duel_ranks'])):
+ mainindex_data['duel_ranks'].append(('-', '-', '-'))
+
+ for i in range(leaderboard_count-len(mainindex_data['ctf_ranks'])):
+ mainindex_data['ctf_ranks'].append(('-', '-', '-'))
+
+ for i in range(leaderboard_count-len(mainindex_data['dm_ranks'])):
+ mainindex_data['dm_ranks'].append(('-', '-', '-'))
+
+ for i in range(leaderboard_count-len(mainindex_data['top_players'])):
+ mainindex_data['top_players'].append(('-', '-', '-'))
+
+ for i in range(leaderboard_count-len(mainindex_data['top_servers'])):
+ mainindex_data['top_servers'].append(('-', '-', '-'))
+
+ for i in range(leaderboard_count-len(mainindex_data['top_maps'])):
+ mainindex_data['top_maps'].append(('-', '-', '-'))
+
+ for i in range(recent_games_count-len(mainindex_data['recent_games'])):
+ mainindex_data['recent_games'].append(('-', '-', '-', '-'))
+
+ return mainindex_data
log = logging.getLogger(__name__)\r
\r
def _map_index_data(request):\r
- """\r
- Provides a list of all the current maps. \r
- """\r
if request.params.has_key('page'):\r
current_page = request.params['page']\r
else:\r
return maps\r
\r
\r
-def map_info(request):\r
- """\r
- List the information stored about a given map. \r
- """\r
+def _map_info_data(request):\r
map_id = request.matchdict['id']\r
\r
try: \r
filter(PlayerGameStat.rank==1).\\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
-\r
# top players by score\r
top_scorers = DBSession.query(Player.player_id, Player.nick,\r
func.sum(PlayerGameStat.score)).\\r
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\\r
order_by(expr.desc(func.sum(PlayerGameStat.score))).\\r
group_by(Player.nick).\\r
- group_by(Player.player_id).all()[0:10]\r
+ group_by(Player.player_id).all()[0:leaderboard_count]\r
\r
top_scorers = [(player_id, html_colors(nick), score) \\r
for (player_id, nick, score) in top_scorers]\r
\r
- for i in range(leaderboard_count-len(top_scorers)):\r
- top_scorers.append(('-', '-', '-'))\r
-\r
# top players by playing time\r
top_players = DBSession.query(Player.player_id, Player.nick, \r
func.sum(PlayerGameStat.alivetime)).\\r
(datetime.utcnow() - 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
+ group_by(Player.player_id).all()[0:leaderboard_count]\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
# top servers using/playing this map\r
top_servers = DBSession.query(Server.server_id, Server.name, \r
func.count(Game.game_id)).\\r
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\\r
order_by(expr.desc(func.count(Game.game_id))).\\r
group_by(Server.name).\\r
- group_by(Server.server_id).all()[0:10]\r
-\r
- for i in range(leaderboard_count-len(top_servers)):\r
- top_servers.append(('-', '-', '-'))\r
+ group_by(Server.server_id).all()[0:leaderboard_count]\r
\r
except Exception as e:\r
gmap = None\r
'top_players':top_players,\r
'top_servers':top_servers,\r
}\r
+\r
+\r
+def map_info(request):\r
+ """\r
+ List the information stored about a given map.\r
+ """\r
+ mapinfo_data = _map_info_data(request)\r
+\r
+ # FIXME: code clone, should get these from _map_info_data\r
+ leaderboard_count = 10\r
+ recent_games_count = 20\r
+\r
+ for i in range(recent_games_count-len(mapinfo_data['recent_games'])):\r
+ mapinfo_data['recent_games'].append(('-', '-', '-', '-'))\r
+\r
+ for i in range(leaderboard_count-len(mapinfo_data['top_scorers'])):\r
+ mapinfo_data['top_scorers'].append(('-', '-', '-'))\r
+\r
+ for i in range(leaderboard_count-len(mapinfo_data['top_players'])):\r
+ mapinfo_data['top_players'].append(('-', '-', '-'))\r
+\r
+ for i in range(leaderboard_count-len(mapinfo_data['top_servers'])):\r
+ mapinfo_data['top_servers'].append(('-', '-', '-'))\r
+\r
+ return mapinfo_data\r
log = logging.getLogger(__name__)\r
\r
\r
-def player_index(request):\r
- """\r
- Provides a list of all the current players. \r
- """\r
+def _player_index_data(request):\r
if request.params.has_key('page'):\r
current_page = request.params['page']\r
else:\r
}\r
\r
\r
-def get_games_played(player_id):\r
+def player_index(request):\r
+ """\r
+ Provides a list of all the current players.\r
+ """\r
+ return _player_index_data(request)\r
+\r
+\r
+def _get_games_played(player_id):\r
"""\r
Provides a breakdown by gametype of the games played by player_id.\r
\r
\r
# TODO: should probably factor the above function into this one such that\r
# total_stats['ctf_games'] is the count of CTF games and so on...\r
-def get_total_stats(player_id):\r
+def _get_total_stats(player_id):\r
"""\r
Provides aggregated stats by player_id.\r
\r
return (avg, accs)\r
\r
\r
-def player_info(request):\r
- """\r
- Provides detailed information on a specific player\r
- """\r
+def _player_info_data(request):\r
player_id = int(request.matchdict['id'])\r
if player_id <= 2:\r
player_id = -1;\r
filter(Player.active_ind == True).one()\r
\r
# games played, alivetime, wins, kills, deaths\r
- total_stats = get_total_stats(player.player_id)\r
+ total_stats = _get_total_stats(player.player_id)\r
\r
# games breakdown - N games played (X ctf, Y dm) etc\r
- (total_games, games_breakdown) = get_games_played(player.player_id)\r
+ (total_games, games_breakdown) = _get_games_played(player.player_id)\r
\r
\r
# friendly display of elo information and preliminary status\r
}\r
\r
\r
-def player_game_index(request):\r
+def player_info(request):\r
"""\r
- Provides an index of the games in which a particular\r
- player was involved. This is ordered by game_id, with\r
- the most recent game_ids first. Paginated.\r
+ Provides detailed information on a specific player\r
"""\r
+ return _player_info_data(request)\r
+\r
+\r
+def _player_game_index_data(request):\r
player_id = request.matchdict['player_id']\r
\r
if request.params.has_key('page'):\r
'games':games,\r
'pgstats':pgstats}\r
\r
-def player_accuracy(request):\r
- """\r
- Provides a JSON response representing the accuracy for the given weapon.\r
\r
- Parameters:\r
- weapon = which weapon to display accuracy for. Valid values are 'nex',\r
- 'shotgun', 'uzi', and 'minstanex'.\r
- games = over how many games to display accuracy. Can be up to 50.\r
+def player_game_index(request):\r
"""\r
+ Provides an index of the games in which a particular\r
+ player was involved. This is ordered by game_id, with\r
+ the most recent game_ids first. Paginated.\r
+ """\r
+ return _player_game_index_data(request)\r
+\r
+\r
+def _player_accuracy_data(request):\r
player_id = request.matchdict['id']\r
allowed_weapons = ['nex', 'rifle', 'shotgun', 'uzi', 'minstanex']\r
weapon_cd = 'nex'\r
'accs':accs\r
}\r
\r
+\r
+def player_accuracy_json(request):\r
+ """\r
+ Provides a JSON response representing the accuracy for the given weapon.\r
+\r
+ Parameters:\r
+ weapon = which weapon to display accuracy for. Valid values are 'nex',\r
+ 'shotgun', 'uzi', and 'minstanex'.\r
+ games = over how many games to display accuracy. Can be up to 50.\r
+ """\r
+ return _player_accuracy_data(request)\r
return (result_type, q)
-def search(request):
+def _search_data(request):
fs = None
nick = None
server_name = None
'results':results,
'query':query,
}
+
+
+def search(request):
+ return _search_data(request)
\r
log = logging.getLogger(__name__)\r
\r
-def server_index(request):\r
- """\r
- Provides a list of all the current servers. \r
- """\r
+def _server_index_data(request):\r
if request.params.has_key('page'):\r
current_page = request.params['page']\r
else:\r
return {'servers':servers, }\r
\r
\r
-def server_info(request):\r
+def server_index(request):\r
"""\r
- List the stored information about a given server.\r
+ Provides a list of all the current servers.\r
"""\r
+ return _server_index_data(request)\r
+\r
+\r
+def _server_info_data(request):\r
server_id = request.matchdict['id']\r
\r
try: \r
(datetime.utcnow() - 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
+ group_by(Map.name).all()[0:leaderboard_count]\r
\r
# top players by score\r
top_scorers = DBSession.query(Player.player_id, Player.nick, \r
(datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\\r
order_by(expr.desc(func.sum(PlayerGameStat.score))).\\r
group_by(Player.nick).\\r
- group_by(Player.player_id).all()[0:10]\r
+ group_by(Player.player_id).all()[0:leaderboard_count]\r
\r
top_scorers = [(player_id, html_colors(nick), score) \\r
for (player_id, nick, score) in top_scorers]\r
\r
- for i in range(leaderboard_count-len(top_scorers)):\r
- top_scorers.append(('-', '-', '-'))\r
-\r
# top players by playing time\r
top_players = DBSession.query(Player.player_id, Player.nick, \r
func.sum(PlayerGameStat.alivetime)).\\r
(datetime.utcnow() - 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
+ group_by(Player.player_id).all()[0:leaderboard_count]\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(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
}\r
\r
\r
-def server_game_index(request):\r
+def server_info(request):\r
"""\r
- List the games played on a given server. Paginated.\r
+ List the stored information about a given server.\r
"""\r
+ serverinfo_data = _server_info_data(request)\r
+\r
+ # FIXME: code clone, should get these from _server_info_data\r
+ leaderboard_count = 10\r
+ recent_games_count = 20\r
+\r
+ for i in range(leaderboard_count-len(serverinfo_data['top_maps'])):\r
+ serverinfo_data['top_maps'].append(('-', '-', '-'))\r
+\r
+ for i in range(leaderboard_count-len(serverinfo_data['top_scorers'])):\r
+ serverinfo_data['top_scorers'].append(('-', '-', '-'))\r
+\r
+ for i in range(leaderboard_count-len(serverinfo_data['top_players'])):\r
+ serverinfo_data['top_players'].append(('-', '-', '-'))\r
+\r
+ for i in range(recent_games_count-len(serverinfo_data['recent_games'])):\r
+ serverinfo_data['recent_games'].append(('-', '-', '-', '-'))\r
+\r
+ return serverinfo_data\r
+\r
+\r
+def _server_game_index_data(request):\r
server_id = request.matchdict['server_id']\r
current_page = request.matchdict['page']\r
\r
\r
return {'games':games,\r
'server':server}\r
+\r
+\r
+def server_game_index(request):\r
+ """\r
+ List the games played on a given server. Paginated.\r
+ """\r
+ return _server_game_index_data(request)\r