From: Ant Zucaro Date: Sun, 30 Dec 2018 00:04:49 +0000 (-0500) Subject: Return actual data in the /map/ JSON views. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cf9226da5cd4e8e8f1841a6f6f5e0ae7c18038b5;p=xonotic%2Fxonstat.git Return actual data in the /map/ JSON views. --- diff --git a/xonstat/templates/map_info.mako b/xonstat/templates/map_info.mako index 339525c..c58f74a 100644 --- a/xonstat/templates/map_info.mako +++ b/xonstat/templates/map_info.mako @@ -36,7 +36,7 @@ <% i = 1 %> - % for (score_player_id, score_nick, score_value) in top_scorers: + % for (score_player_id, score_nick, score_value, _) in top_scorers: ${i} % if score_player_id != '-': @@ -64,7 +64,7 @@ <% i = 1 %> - % for (player_id, nick, alivetime) in top_players: + % for (player_id, nick, alivetime, _) in top_players: ${i} % if player_id != '-': diff --git a/xonstat/views/map.py b/xonstat/views/map.py index d6eb584..75c3373 100644 --- a/xonstat/views/map.py +++ b/xonstat/views/map.py @@ -336,8 +336,8 @@ def _map_info_data(request): group_by(Player.nick).\ 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] + top_scorers = [(player_id, html_colors(nick), score, nick) + for (player_id, nick, score) in top_scorers] # top players by playing time top_players = DBSession.query(Player.player_id, Player.nick, @@ -352,8 +352,8 @@ def _map_info_data(request): group_by(Player.nick).\ 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] + top_players = [(player_id, html_colors(nick), score, nick) + for (player_id, nick, score) in top_players] # top servers using/playing this map top_servers = DBSession.query(Server.server_id, Server.name, @@ -416,7 +416,45 @@ def map_info_json(request): """ List the information stored about a given map. JSON. """ - return [{'status':'not implemented'}] + data = _map_info_data(request) + + # convert the top scorers to a dict + def top_scorers_dict(tp): + return { + "player_id": tp[0], + "nick": tp[3], + "score": tp[2], + } + + top_scorers = [top_scorers_dict(ts) for ts in data["top_scorers"]] + + # convert the top players to a dict + def top_players_dict(tp): + return { + "player_id": tp[0], + "nick": tp[3], + "alivetime": tp[2].total_seconds(), + } + + top_players = [top_players_dict(tp) for tp in data["top_players"]] + + def top_servers_dict(ts): + return { + "server_id": ts[0], + "server_name": ts[1], + "games": ts[2], + } + + top_servers = [top_servers_dict(ts) for ts in data["top_servers"]] + + return { + 'map': data["gmap"].to_dict(), + 'recent_games': [rg.to_dict() for rg in data["recent_games"]], + 'top_scorers': top_scorers, + 'top_players': top_players, + 'top_servers':top_servers, + # 'captimes':captimes, + } def map_captimes_data(request):