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 players = DBSession.query(Player)
\r
20 return {'players':players}
\r
22 def player_info(request):
\r
24 Provides detailed information on a specific player
\r
26 player_id = request.matchdict['id']
\r
28 player = DBSession.query(Player).filter_by(player_id=player_id).one()
\r
30 weapon_stats = DBSession.query("descr", "weapon_cd", "actual_total",
\r
31 "max_total", "hit_total", "fired_total", "frags_total").\
\r
33 "select cw.descr, cw.weapon_cd, sum(actual) actual_total, "
\r
34 "sum(max) max_total, sum(hit) hit_total, "
\r
35 "sum(fired) fired_total, sum(frags) frags_total "
\r
36 "from xonstat.player_weapon_stats ws, xonstat.cd_weapon cw "
\r
37 "where ws.weapon_cd = cw.weapon_cd "
\r
38 "and player_id = :player_id "
\r
39 "group by descr, cw.weapon_cd "
\r
41 ).params(player_id=player_id).all()
\r
43 recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\
\r
44 filter(PlayerGameStat.player_id == player_id).\
\r
45 filter(PlayerGameStat.game_id == Game.game_id).\
\r
46 filter(Game.server_id == Server.server_id).\
\r
47 filter(Game.map_id == Map.map_id).\
\r
48 order_by(Game.game_id.desc())[0:10]
\r
51 (game_stats['avg_rank'], game_stats['total_kills'],
\r
52 game_stats['total_deaths'], game_stats['total_suicides'],
\r
53 game_stats['total_score'], game_stats['total_time'],
\r
54 game_stats['total_held'], game_stats['total_captures'],
\r
55 game_stats['total_pickups'],game_stats['total_drops'],
\r
56 game_stats['total_returns'], game_stats['total_collects'],
\r
57 game_stats['total_destroys'], game_stats['total_dhk'],
\r
58 game_stats['total_pushes'], game_stats['total_pushed'],
\r
59 game_stats['total_carrier_frags'],
\r
60 game_stats['total_alivetime']) = DBSession.\
\r
61 query("avg_rank", "total_kills", "total_deaths",
\r
62 "total_suicides", "total_score", "total_time", "total_held",
\r
63 "total_captures", "total_pickups", "total_drops",
\r
64 "total_returns", "total_collects", "total_destroys",
\r
65 "total_dhk", "total_pushes", "total_pushed",
\r
66 "total_carrier_frags", "total_alivetime").\
\r
68 "select round(avg(rank)) avg_rank, sum(kills) total_kills, "
\r
69 "sum(deaths) total_deaths, sum(suicides) total_suicides, "
\r
70 "sum(score) total_score, sum(time) total_time, "
\r
71 "sum(held) total_held, sum(captures) total_captures, "
\r
72 "sum(pickups) total_pickups, sum(drops) total_drops, "
\r
73 "sum(returns) total_returns, sum(collects) total_collects, "
\r
74 "sum(destroys) total_destroys, sum(destroys_holding_key) total_dhk, "
\r
75 "sum(pushes) total_pushes, sum(pushed) total_pushed, "
\r
76 "sum(carrier_frags) total_carrier_frags, "
\r
77 "sum(alivetime) total_alivetime "
\r
78 "from player_game_stats "
\r
79 "where player_id=:player_id"
\r
80 ).params(player_id=player_id).one()
\r
82 for (key,value) in game_stats.items():
\r
84 game_stats[key] = '-'
\r
86 except Exception as e:
\r
92 return {'player':player,
\r
93 'recent_games':recent_games,
\r
94 'weapon_stats':weapon_stats,
\r
95 'game_stats':game_stats}
\r
98 def player_game_index(request):
\r
100 Provides an index of the games in which a particular
\r
101 player was involved. This is ordered by game_id, with
\r
102 the most recent game_ids first. Paginated.
\r
104 player_id = request.matchdict['player_id']
\r
106 if 'page' in request.matchdict:
\r
107 current_page = request.matchdict['page']
\r
112 player = DBSession.query(Player).filter_by(player_id=player_id).one()
\r
114 games_q = DBSession.query(PlayerGameStat, Game, Server, Map).\
\r
115 filter(PlayerGameStat.player_id == player_id).\
\r
116 filter(PlayerGameStat.game_id == Game.game_id).\
\r
117 filter(Game.server_id == Server.server_id).\
\r
118 filter(Game.map_id == Map.map_id).\
\r
119 order_by(Game.game_id.desc())
\r
121 games = Page(games_q, current_page, url=page_url)
\r
124 except Exception as e:
\r
128 return {'player':player,
\r