]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Return actual data in the /map/<map id> JSON views.
authorAnt Zucaro <azucaro@gmail.com>
Sun, 30 Dec 2018 00:04:49 +0000 (19:04 -0500)
committerAnt Zucaro <azucaro@gmail.com>
Sun, 30 Dec 2018 00:04:49 +0000 (19:04 -0500)
xonstat/templates/map_info.mako
xonstat/views/map.py

index 339525cde4a8c1405e76b2ca67380560313faac0..c58f74a642f8d5827eef9888a1df0573ef46b554 100644 (file)
@@ -36,7 +36,7 @@
         </thead>
         <tbody>
           <% i = 1 %>
-          % for (score_player_id, score_nick, score_value) in top_scorers:
+          % for (score_player_id, score_nick, score_value, _) in top_scorers:
             <tr>
               <td>${i}</td>
               % if score_player_id != '-':
@@ -64,7 +64,7 @@
         </thead>
         <tbody>
         <% i = 1 %>
-        % for (player_id, nick, alivetime) in top_players:
+        % for (player_id, nick, alivetime, _) in top_players:
           <tr>
             <td>${i}</td>
             % if player_id != '-':
index d6eb58468565f96a389cfbfd58b98b7b1e0fd170..75c3373359f95ce7ccb212f671cad7ed46b232c9 100644 (file)
@@ -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):