You can choose which weapon to show accuracy stats for. The only weapons shown are those that the player has used in 5 or more games in the past 90 days. This is still a work in progress, as I don't have labels or nice hovers for the datapoints. :(
.game tr:hover {
background-color: #222;
}
+.weapon-nav {
+ height: 70px;
+ margin-bottom: 20px;
+}
+.weapon-nav ul {
+ display: block;
+ list-style: none outside none;
+}
+.weapon-nav li {
+ float: left;
+ margin-right: 10px;
+}
+.weapon-nav li:hover {
+ border-bottom: 2px solid #001021;
+}
+.weapon-nav .weapon-active {
+ border-bottom: 2px solid #436688;
+}
+.weapon-nav p {
+ text-align: center;
+}
<%block name="css">
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
- <link href="/static/css/style.min.css" rel="stylesheet">
+ <!-- <link href="/static/css/style.min.css" rel="stylesheet"> -->
+ <link href="/static/css/style.css" rel="stylesheet">
</%block>
</head>
$(".acc-weap").click(function () {
var dataurl = $(this).find('a').attr('href');
+ $('.weapon-active').removeClass('weapon-active');
+ $(this).addClass('weapon-active');
+
$.ajax({
url: dataurl,
method: 'GET',
% if accs is not None:
<div class="row">
<div class="span10">
- <h3>Nex Accuracy</h3>
+ <h3>Accuracy</h3>
<div id="acc-graph" style="width:800px; height:200px;">
</div>
- <div class="acc-weap">
- Show nex accuracy.
- <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'nex'})}" title="Show nex accuracy"></a>
- </div>
-
- <div class="acc-weap">
- Show rifle accuracy.
- <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'rifle'})}" title="Show rifle accuracy"></a>
- </div>
-
- <div class="acc-weap">
- Show minstanex accuracy.
- <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'minstanex'})}" title="Show minstanex accuracy"></a>
- </div>
-
- <div class="acc-weap">
- Show uzi accuracy.
- <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'uzi'})}" title="Show uzi accuracy"></a>
- </div>
-
- <div class="acc-weap">
- Show shotgun accuracy.
- <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'shotgun'})}" title="Show shotgun accuracy"></a>
+ <div class="weapon-nav">
+ <ul>
+ % if 'nex' in recent_weapons:
+ <li>
+ <div class="acc-weap weapon-active">
+ <img src="${request.static_url("xonstat:static/images/nex.png")}" />
+ <p><small>Nex</small></p>
+ <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'nex'})}" title="Show nex accuracy"></a>
+ </div>
+ </li>
+ % endif
+
+ % if 'rifle' in recent_weapons:
+ <li>
+ <div class="acc-weap">
+ <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
+ <p><small>Rifle</small></p>
+ <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'rifle'})}" title="Show rifle accuracy"></a>
+ </div>
+ </li>
+ % endif
+
+ % if 'minstanex' in recent_weapons:
+ <li>
+ <div class="acc-weap">
+ <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
+ <p><small>Minstanex</small></p>
+ <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'minstanex'})}" title="Show minstanex accuracy"></a>
+ </div>
+ </li>
+ % endif
+
+ % if 'uzi' in recent_weapons:
+ <li>
+ <div class="acc-weap">
+ <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
+ <p><small>Uzi</small></p>
+ <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'uzi'})}" title="Show uzi accuracy"></a>
+ </div>
+ </li>
+ % endif
+
+ % if 'shotgun' in recent_weapons:
+ <li>
+ <div class="acc-weap">
+ <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
+ <p><small>Shotgun</small></p>
+ <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'shotgun'})}" title="Show shotgun accuracy"></a>
+ </div>
+ </li>
+ % endif
+ </ul>
</div>
</div>
import time\r
from pyramid.response import Response\r
from pyramid.url import current_route_url\r
-from sqlalchemy import desc\r
+from sqlalchemy import desc, distinct\r
from webhelpers.paginate import Page, PageURL\r
from xonstat.models import *\r
from xonstat.util import page_url\r
for i in range(len(raw_accs)):\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
+ accs = []\r
+ avg = 0.0\r
\r
return (avg, accs)\r
\r
elos_display.append(str.format(round(elo.elo, 3),\r
elo.game_type_cd))\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
-\r
- avg = json.dumps(avg)\r
- accs = json.dumps(accs)\r
-\r
+ # which weapons have been used in the past 90 days\r
+ # and also, used in 5 games or more?\r
+ back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90)\r
+ recent_weapons = []\r
+ for weapon in DBSession.query(PlayerWeaponStat.weapon_cd, func.count()).\\r
+ filter(PlayerWeaponStat.player_id == player_id).\\r
+ filter(PlayerWeaponStat.create_dt > back_then).\\r
+ group_by(PlayerWeaponStat.weapon_cd).\\r
+ having(func.count() > 4).\\r
+ all():\r
+ recent_weapons.append(weapon[0])\r
\r
# recent games table, all data\r
recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\\r
recent_games = None\r
total_games = None\r
games_breakdown = None\r
- avg = None\r
- accs = None\r
+ recent_weapons = None\r
\r
return {'player':player,\r
'elos_display':elos_display,\r
'total_stats':total_stats,\r
'total_games':total_games,\r
'games_breakdown':games_breakdown,\r
- 'avg':avg,\r
- 'accs':accs,\r
+ 'recent_weapons':recent_weapons,\r
}\r
\r
\r
\r
(avg, accs) = get_accuracy_stats(player_id, weapon_cd, games)\r
\r
+ # if we don't have enough data for the given weapon\r
+ if len(accs) < games:\r
+ games = len(accs)\r
+\r
return {\r
'player_id':player_id, \r
'player_url':request.route_url('player_info', id=player_id), \r