From: Ant Zucaro Date: Sat, 28 Apr 2012 22:23:33 +0000 (-0400) Subject: Ajaxify the accuracy graph. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4b13e9b77ff48fcae3419665ee2e2b4bba9d2171;p=xonotic%2Fxonstat.git Ajaxify the accuracy graph. --- diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index bab10c2..5f3071c 100755 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -10,15 +10,42 @@ ${nav.nav('players')} diff --git a/xonstat/views/player.py b/xonstat/views/player.py index 1f06b47..9f2751f 100755 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -125,11 +125,7 @@ def get_accuracy_stats(player_id, weapon_cd, games): filter(PlayerWeaponStat.weapon_cd == weapon_cd).\ one() - raw_avg = round(float(raw_avg[0])/raw_avg[1]*100, 2) - - avg = [] - for i in range(games): - avg.append((i, raw_avg)) + avg = round(float(raw_avg[0])/raw_avg[1]*100, 2) # Determine the raw accuracy (hit, fired) numbers for $games games # This is then enumerated to create parameters for a flot graph @@ -144,16 +140,14 @@ def get_accuracy_stats(player_id, weapon_cd, games): # they come out in opposite order, so flip them in the right direction raw_accs.reverse() - games = [] accs = [] for i in range(len(raw_accs)): - games.append((i, raw_accs[i][0])) - accs.append((i, round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2))) + accs.append((raw_accs[i][0], round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2))) except: accs = 0 avg = 0 - return (games, avg, accs) + return (avg, accs) def player_info(request): @@ -192,7 +186,7 @@ def player_info(request): # data for the accuracy graph, which is converted into a JSON array for # usage by flot - (games, avg, accs) = get_accuracy_stats(player_id, 'nex', 20) + (avg, accs) = get_accuracy_stats(player_id, 'nex', 20) avg = json.dumps(avg) accs = json.dumps(accs) @@ -283,7 +277,25 @@ def player_accuracy(request): if request.params['weapon'] in allowed_weapons: weapon_cd = request.params['weapon'] - (games, avg, accs) = get_accuracy_stats(player_id, weapon_cd, games) - - return {'weapon':weapon_cd, 'games':games, 'avg':avg, 'accs':accs} + if request.params.has_key('games'): + try: + games = request.params['games'] + + if games < 0: + games = 20 + if games > 50: + games = 50 + except: + games = 20 + + (avg, accs) = get_accuracy_stats(player_id, weapon_cd, games) + + return { + 'player_id':player_id, + 'player_url':request.route_url('player_info', id=player_id), + 'weapon':weapon_cd, + 'games':games, + 'avg':avg, + 'accs':accs + }