<script src="/static/js/jquery-1.7.1.min.js"></script>
<script src="/static/js/jquery.flot.min.js"></script>
<script type="text/javascript">
- var avg = ${avg};
- var accs = ${accs};
+ $(function () {
+ function plot_acc_graph(data) {
+ var games = new Array();
+ var avgs = new Array();
+ var accs = new Array();
- $.plot($("#acc-graph"), [
- { data: avg },
- { data: accs },
- ],
- { yaxis: {ticks: 10, min: 0, max: 100 },
+ var i=0;
+ for(i=0; i < data.games; i++) {
+ avgs[i] = [i, data.avg];
+ accs[i] = [i, data.accs[i][1]];
+ games[i] = [i, data.accs[i][0]];
+ }
+
+ $.plot(
+ $("#acc-graph"),
+ [ { data: avgs }, { data: accs }, ],
+ { yaxis: {ticks: 10, min: 0, max: 100 },
+ });
+ }
+
+ $.ajax({
+ url: '${request.route_url("player_accuracy", id=player.player_id)}',
+ method: 'GET',
+ dataType: 'json',
+ success: plot_acc_graph
});
+ })
+ // var avg = ${avg};
+ // var accs = ${accs};
+
+ // $.plot($("#acc-graph"), [
+ // { data: avg },
+ // { data: accs },
+ // ],
+ // { yaxis: {ticks: 10, min: 0, max: 100 },
+ // });
</script>
</%block>
filter(PlayerWeaponStat.weapon_cd == weapon_cd).\\r
one()\r
\r
- raw_avg = round(float(raw_avg[0])/raw_avg[1]*100, 2)\r
-\r
- avg = []\r
- for i in range(games):\r
- avg.append((i, raw_avg))\r
+ avg = round(float(raw_avg[0])/raw_avg[1]*100, 2)\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
# 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
- games.append((i, raw_accs[i][0]))\r
- accs.append((i, round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2)))\r
+ accs.append((raw_accs[i][0], round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2)))\r
except:\r
accs = 0\r
avg = 0\r
\r
- return (games, avg, accs)\r
+ return (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
- (games, avg, accs) = get_accuracy_stats(player_id, 'nex', 20)\r
+ (avg, accs) = get_accuracy_stats(player_id, 'nex', 20)\r
\r
avg = json.dumps(avg)\r
accs = json.dumps(accs)\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
+ if request.params.has_key('games'):\r
+ try:\r
+ games = request.params['games']\r
+\r
+ if games < 0:\r
+ games = 20\r
+ if games > 50:\r
+ games = 50\r
+ except:\r
+ games = 20\r
+\r
+ (avg, accs) = get_accuracy_stats(player_id, weapon_cd, games)\r
+\r
+ return {\r
+ 'player_id':player_id, \r
+ 'player_url':request.route_url('player_info', id=player_id), \r
+ 'weapon':weapon_cd, \r
+ 'games':games, \r
+ 'avg':avg, \r
+ 'accs':accs\r
+ }\r
\r