5 from pyramid.response import Response
\r
6 from sqlalchemy import desc
\r
7 from webhelpers.paginate import Page, PageURL
\r
8 from xonstat.models import *
\r
9 from xonstat.util import page_url
\r
11 log = logging.getLogger(__name__)
\r
14 def player_index(request):
\r
16 Provides a list of all the current players.
\r
18 if 'page' in request.matchdict:
\r
19 current_page = request.matchdict['page']
\r
24 player_q = DBSession.query(Player).\
\r
25 filter(Player.player_id > 2).\
\r
26 order_by(Player.player_id)
\r
28 players = Page(player_q, current_page, url=page_url)
\r
31 except Exception as e:
\r
34 return {'players':players, }
\r
37 def player_info(request):
\r
39 Provides detailed information on a specific player
\r
41 player_id = int(request.matchdict['id'])
\r
46 player = DBSession.query(Player).filter_by(player_id=player_id).one()
\r
48 weapon_stats = DBSession.query("descr", "weapon_cd", "actual_total",
\r
49 "max_total", "hit_total", "fired_total", "frags_total").\
\r
51 "select cw.descr, cw.weapon_cd, sum(actual) actual_total, "
\r
52 "sum(max) max_total, sum(hit) hit_total, "
\r
53 "sum(fired) fired_total, sum(frags) frags_total "
\r
54 "from xonstat.player_weapon_stats ws, xonstat.cd_weapon cw "
\r
55 "where ws.weapon_cd = cw.weapon_cd "
\r
56 "and player_id = :player_id "
\r
57 "group by descr, cw.weapon_cd "
\r
59 ).params(player_id=player_id).all()
\r
61 recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\
\r
62 filter(PlayerGameStat.player_id == player_id).\
\r
63 filter(PlayerGameStat.game_id == Game.game_id).\
\r
64 filter(Game.server_id == Server.server_id).\
\r
65 filter(Game.map_id == Map.map_id).\
\r
66 order_by(Game.game_id.desc())[0:10]
\r
69 (game_stats['avg_rank'], game_stats['total_kills'],
\r
70 game_stats['total_deaths'], game_stats['total_suicides'],
\r
71 game_stats['total_score'], game_stats['total_time'],
\r
72 game_stats['total_held'], game_stats['total_captures'],
\r
73 game_stats['total_pickups'],game_stats['total_drops'],
\r
74 game_stats['total_returns'], game_stats['total_collects'],
\r
75 game_stats['total_destroys'], game_stats['total_dhk'],
\r
76 game_stats['total_pushes'], game_stats['total_pushed'],
\r
77 game_stats['total_carrier_frags'],
\r
78 game_stats['total_alivetime'],
\r
79 game_stats['total_games_played']) = DBSession.\
\r
80 query("avg_rank", "total_kills", "total_deaths",
\r
81 "total_suicides", "total_score", "total_time", "total_held",
\r
82 "total_captures", "total_pickups", "total_drops",
\r
83 "total_returns", "total_collects", "total_destroys",
\r
84 "total_dhk", "total_pushes", "total_pushed",
\r
85 "total_carrier_frags", "total_alivetime",
\r
86 "total_games_played").\
\r
88 "select round(avg(rank)) avg_rank, sum(kills) total_kills, "
\r
89 "sum(deaths) total_deaths, sum(suicides) total_suicides, "
\r
90 "sum(score) total_score, sum(time) total_time, "
\r
91 "sum(held) total_held, sum(captures) total_captures, "
\r
92 "sum(pickups) total_pickups, sum(drops) total_drops, "
\r
93 "sum(returns) total_returns, sum(collects) total_collects, "
\r
94 "sum(destroys) total_destroys, sum(destroys_holding_key) total_dhk, "
\r
95 "sum(pushes) total_pushes, sum(pushed) total_pushed, "
\r
96 "sum(carrier_frags) total_carrier_frags, "
\r
97 "sum(alivetime) total_alivetime, count(*) total_games_played "
\r
98 "from player_game_stats "
\r
99 "where player_id=:player_id"
\r
100 ).params(player_id=player_id).one()
\r
102 for (key,value) in game_stats.items():
\r
104 game_stats[key] = '-'
\r
106 except Exception as e:
\r
108 weapon_stats = None
\r
110 recent_games = None
\r
112 return {'player':player,
\r
113 'recent_games':recent_games,
\r
114 'weapon_stats':weapon_stats,
\r
115 'game_stats':game_stats}
\r
118 def player_game_index(request):
\r
120 Provides an index of the games in which a particular
\r
121 player was involved. This is ordered by game_id, with
\r
122 the most recent game_ids first. Paginated.
\r
124 player_id = request.matchdict['player_id']
\r
126 if 'page' in request.matchdict:
\r
127 current_page = request.matchdict['page']
\r
132 player = DBSession.query(Player).filter_by(player_id=player_id).one()
\r
134 games_q = DBSession.query(PlayerGameStat, Game, Server, Map).\
\r
135 filter(PlayerGameStat.player_id == player_id).\
\r
136 filter(PlayerGameStat.game_id == Game.game_id).\
\r
137 filter(Game.server_id == Server.server_id).\
\r
138 filter(Game.map_id == Map.map_id).\
\r
139 order_by(Game.game_id.desc())
\r
141 games = Page(games_q, current_page, url=page_url)
\r
144 except Exception as e:
\r
148 return {'player':player,
\r