config.add_view(player_info, route_name="player_info",
renderer="player_info.mako")
+ config.add_route("player_accuracy", "/player/{id:\d+}/accuracy")
+ config.add_view(player_accuracy, route_name="player_accuracy",
+ renderer="json")
+
# GAME ROUTES
config.add_route("game_index", "/games")
config.add_view(game_index, route_name="game_index",
from xonstat.views.submission import stats_submit\r
from xonstat.views.player import player_index, player_info, player_game_index\r
+from xonstat.views.player import player_accuracy\r
from xonstat.views.game import game_index, game_info, rank_index\r
from xonstat.views.map import map_info, map_index\r
from xonstat.views.server import server_info, server_game_index, server_index\r
\r
# Determine the raw accuracy (hit, fired) numbers for $games games\r
# This is then enumerated to create parameters for a flot graph\r
- raw_accs = DBSession.query(PlayerWeaponStat.hit, PlayerWeaponStat.fired).\\r
+ raw_accs = DBSession.query(PlayerWeaponStat.game_id, \r
+ PlayerWeaponStat.hit, PlayerWeaponStat.fired).\\r
filter(PlayerWeaponStat.player_id == player_id).\\r
filter(PlayerWeaponStat.weapon_cd == weapon_cd).\\r
- order_by(PlayerWeaponStat.create_dt).\\r
+ order_by(PlayerWeaponStat.game_id.desc()).\\r
limit(games).\\r
all()\r
\r
+ # they come out in opposite order, so flip them in the right direction\r
+ raw_accs.reverse()\r
+\r
+ games = []\r
accs = []\r
for i in range(len(raw_accs)):\r
- accs.append((i, round(float(raw_accs[i][0])/raw_accs[i][1]*100, 2)))\r
+ games.append((i, raw_accs[i][0]))\r
+ accs.append((i, round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2)))\r
except:\r
accs = 0\r
avg = 0\r
\r
- return (avg, accs)\r
+ return (games, avg, accs)\r
\r
\r
def player_info(request):\r
\r
# data for the accuracy graph, which is converted into a JSON array for\r
# usage by flot\r
- (avg, accs) = get_accuracy_stats(player_id, 'nex', 20)\r
+ (games, avg, accs) = get_accuracy_stats(player_id, 'nex', 20)\r
\r
avg = json.dumps(avg)\r
accs = json.dumps(accs)\r
return {'player_id':player_id,\r
'games':games,\r
'pgstats':pgstats}\r
+\r
+def player_accuracy(request):\r
+ """\r
+ Provides a JSON response representing the accuracy for the given weapon.\r
+\r
+ Parameters:\r
+ weapon = which weapon to display accuracy for. Valid values are 'nex',\r
+ 'shotgun', 'uzi', and 'minstanex'.\r
+ games = over how many games to display accuracy. Can be up to 50.\r
+ """\r
+ player_id = request.matchdict['id']\r
+ allowed_weapons = ['nex', 'shotgun', 'uzi', 'minstanex']\r
+ weapon_cd = 'nex'\r
+ games = 20\r
+\r
+ if request.params.has_key('weapon'):\r
+ if request.params['weapon'] in allowed_weapons:\r
+ weapon_cd = request.params['weapon']\r
+\r
+ (games, avg, accs) = get_accuracy_stats(player_id, weapon_cd, games)\r
+\r
+ return {'weapon':weapon_cd, 'games':games, 'avg':avg, 'accs':accs}\r
+\r