X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=xonstat%2Fviews%2Fmap.py;h=86e70ad3aff62bd68e060d7286649a78a4a212b8;hb=349dd5c4cdd51b406f58f817291e8f98e1da60a3;hp=fff321f9e3af10b6c25210822b58fa03e505ed40;hpb=ed2724e703b7b440bb87558df38043b1f6f9fe7e;p=xonotic%2Fxonstat.git diff --git a/xonstat/views/map.py b/xonstat/views/map.py index fff321f..86e70ad 100755 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -10,12 +10,9 @@ from xonstat.util import page_url log = logging.getLogger(__name__) -def map_index(request): - """ - Provides a list of all the current maps. - """ - if 'page' in request.matchdict: - current_page = request.matchdict['page'] +def _map_index_data(request): + if request.params.has_key('page'): + current_page = request.params['page'] else: current_page = 1 @@ -23,19 +20,33 @@ def map_index(request): map_q = DBSession.query(Map).\ order_by(Map.map_id.desc()) - maps = Page(map_q, current_page, url=page_url) + maps = Page(map_q, current_page, items_per_page=10, url=page_url) - except Exception as e: maps = None return {'maps':maps, } -def map_info(request): +def map_index(request): """ - List the information stored about a given map. + Provides a list of all the current maps. """ + return _map_index_data(request) + + +def map_index_json(request): + """ + Provides a JSON-serialized list of all the current maps. + """ + view_data = _map_index_data(request) + + maps = [m.to_dict() for m in view_data['maps']] + + return maps + + +def _map_info_data(request): map_id = request.matchdict['id'] try: @@ -59,10 +70,6 @@ def map_info(request): filter(PlayerGameStat.rank==1).\ order_by(expr.desc(Game.start_dt)).all()[0:recent_games_count] - for i in range(recent_games_count-len(recent_games)): - recent_games.append(('-', '-', '-', '-')) - - # top players by score top_scorers = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.score)).\ @@ -74,14 +81,11 @@ def map_info(request): (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.sum(PlayerGameStat.score))).\ group_by(Player.nick).\ - group_by(Player.player_id).all()[0:10] + group_by(Player.player_id).all()[0:leaderboard_count] top_scorers = [(player_id, html_colors(nick), score) \ for (player_id, nick, score) in top_scorers] - for i in range(leaderboard_count-len(top_scorers)): - top_scorers.append(('-', '-', '-')) - # top players by playing time top_players = DBSession.query(Player.player_id, Player.nick, func.sum(PlayerGameStat.alivetime)).\ @@ -93,14 +97,11 @@ def map_info(request): (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.sum(PlayerGameStat.alivetime))).\ group_by(Player.nick).\ - group_by(Player.player_id).all()[0:10] + group_by(Player.player_id).all()[0:leaderboard_count] 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 using/playing this map top_servers = DBSession.query(Server.server_id, Server.name, func.count(Game.game_id)).\ @@ -110,10 +111,7 @@ def map_info(request): (datetime.utcnow() - timedelta(days=leaderboard_lifetime))).\ order_by(expr.desc(func.count(Game.game_id))).\ group_by(Server.name).\ - group_by(Server.server_id).all()[0:10] - - for i in range(leaderboard_count-len(top_servers)): - top_servers.append(('-', '-', '-')) + group_by(Server.server_id).all()[0:leaderboard_count] except Exception as e: gmap = None @@ -123,3 +121,28 @@ def map_info(request): 'top_players':top_players, 'top_servers':top_servers, } + + +def map_info(request): + """ + List the information stored about a given map. + """ + mapinfo_data = _map_info_data(request) + + # FIXME: code clone, should get these from _map_info_data + leaderboard_count = 10 + recent_games_count = 20 + + for i in range(recent_games_count-len(mapinfo_data['recent_games'])): + mapinfo_data['recent_games'].append(('-', '-', '-', '-')) + + for i in range(leaderboard_count-len(mapinfo_data['top_scorers'])): + mapinfo_data['top_scorers'].append(('-', '-', '-')) + + for i in range(leaderboard_count-len(mapinfo_data['top_players'])): + mapinfo_data['top_players'].append(('-', '-', '-')) + + for i in range(leaderboard_count-len(mapinfo_data['top_servers'])): + mapinfo_data['top_servers'].append(('-', '-', '-')) + + return mapinfo_data