From: Ant Zucaro Date: Sat, 15 Dec 2018 18:22:03 +0000 (-0500) Subject: Return something useful for a game's JSON view. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f0f55403d0405bf14e035133c21832afd0ba05ce;p=xonotic%2Fxonstat.git Return something useful for a game's JSON view. --- diff --git a/xonstat/views/game.py b/xonstat/views/game.py index 479b645..693416b 100644 --- a/xonstat/views/game.py +++ b/xonstat/views/game.py @@ -121,7 +121,34 @@ def game_info_json(request): """ List the game stats (scoreboard) for a particular game. Paginated. JSON. """ - return [{'status':'not implemented'}] + data = _game_info_data(request) + + # convert pwstats into a more JSON-friendly format + pwstats = {} + for pgstat_id, pwstat_list in data["pwstats"].items(): + l = [] + for pwstat in pwstat_list: + l.append({ + "player_game_stat_id": pgstat_id, + "weapon_cd": pwstat[1], + "actual": pwstat[2], + "max": pwstat[3], + "hit": pwstat[4], + "fired": pwstat[5], + "frags": pwstat[6], + }) + + pwstats[int(pgstat_id)] = l + + return { + "game": data["game"].to_dict(), + "server": data["server"].to_dict(), + "map": data["map"].to_dict(), + 'pgstats': [pgstat.to_dict() for pgstat in data["pgstats"]], + 'pwstats': pwstats, + 'tgstats': [tgstat.to_dict() for tgstat in data["tgstats"]], + # 'captimes': [captime.to_dict() for captime in data["captimes"]], + } def _rank_index_data(request): @@ -216,7 +243,7 @@ def game_finder_data(request): try: recent_games = [RecentGame(row) for row in rgs_q.limit(20).all()] - + if len(recent_games) > 0: query['start_game_id'] = recent_games[-1].game_id + 1