From cf9226da5cd4e8e8f1841a6f6f5e0ae7c18038b5 Mon Sep 17 00:00:00 2001 From: Ant Zucaro Date: Sat, 29 Dec 2018 19:04:49 -0500 Subject: [PATCH] Return actual data in the /map/ JSON views. --- xonstat/templates/map_info.mako | 4 +-- xonstat/views/map.py | 48 +++++++++++++++++++++++++++++---- 2 files changed, 45 insertions(+), 7 deletions(-) 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): -- 2.39.2