From: Ant Zucaro Date: Mon, 30 Apr 2012 01:47:58 +0000 (-0400) Subject: Add a toggle-able accuracy selector to the player info page. X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7676d2979e2679f3fdf3089cb6000fc66c435c7b;p=xonotic%2Fxonstat.git Add a toggle-able accuracy selector to the player info page. 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. :( --- diff --git a/xonstat/static/css/style.css b/xonstat/static/css/style.css index f43a3fd..7b1f238 100755 --- a/xonstat/static/css/style.css +++ b/xonstat/static/css/style.css @@ -3454,3 +3454,24 @@ a.thumbnail:hover { .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; +} diff --git a/xonstat/templates/base.mako b/xonstat/templates/base.mako index b3ab5bc..fa33ee4 100755 --- a/xonstat/templates/base.mako +++ b/xonstat/templates/base.mako @@ -20,7 +20,8 @@ <%block name="css"> - + + diff --git a/xonstat/templates/player_info.mako b/xonstat/templates/player_info.mako index d822845..0764fac 100755 --- a/xonstat/templates/player_info.mako +++ b/xonstat/templates/player_info.mako @@ -41,6 +41,9 @@ ${nav.nav('players')} $(".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', @@ -94,33 +97,62 @@ Player Information % if accs is not None:
-

Nex Accuracy

+

Accuracy

-
- Show nex accuracy. - -
- -
- Show rifle accuracy. - -
- -
- Show minstanex accuracy. - -
- -
- Show uzi accuracy. - -
- -
- Show shotgun accuracy. - +
+
    + % if 'nex' in recent_weapons: +
  • +
    + +

    Nex

    + +
    +
  • + % endif + + % if 'rifle' in recent_weapons: +
  • +
    + +

    Rifle

    + +
    +
  • + % endif + + % if 'minstanex' in recent_weapons: +
  • +
    + +

    Minstanex

    + +
    +
  • + % endif + + % if 'uzi' in recent_weapons: +
  • +
    + +

    Uzi

    + +
    +
  • + % endif + + % if 'shotgun' in recent_weapons: +
  • +
    + +

    Shotgun

    + +
    +
  • + % endif +
diff --git a/xonstat/views/player.py b/xonstat/views/player.py index cef4a52..44ea9de 100755 --- a/xonstat/views/player.py +++ b/xonstat/views/player.py @@ -7,7 +7,7 @@ import sqlalchemy.sql.functions as func import time from pyramid.response import Response from pyramid.url import current_route_url -from sqlalchemy import desc +from sqlalchemy import desc, distinct from webhelpers.paginate import Page, PageURL from xonstat.models import * from xonstat.util import page_url @@ -144,8 +144,8 @@ def get_accuracy_stats(player_id, weapon_cd, games): for i in range(len(raw_accs)): accs.append((raw_accs[i][0], round(float(raw_accs[i][1])/raw_accs[i][2]*100, 2))) except: - accs = 0 - avg = 0 + accs = [] + avg = 0.0 return (avg, accs) @@ -184,13 +184,17 @@ def player_info(request): elos_display.append(str.format(round(elo.elo, 3), elo.game_type_cd)) - # data for the accuracy graph, which is converted into a JSON array for - # usage by flot - (avg, accs) = get_accuracy_stats(player_id, 'nex', 20) - - avg = json.dumps(avg) - accs = json.dumps(accs) - + # which weapons have been used in the past 90 days + # and also, used in 5 games or more? + back_then = datetime.datetime.utcnow() - datetime.timedelta(days=90) + recent_weapons = [] + for weapon in DBSession.query(PlayerWeaponStat.weapon_cd, func.count()).\ + filter(PlayerWeaponStat.player_id == player_id).\ + filter(PlayerWeaponStat.create_dt > back_then).\ + group_by(PlayerWeaponStat.weapon_cd).\ + having(func.count() > 4).\ + all(): + recent_weapons.append(weapon[0]) # recent games table, all data recent_games = DBSession.query(PlayerGameStat, Game, Server, Map).\ @@ -207,8 +211,7 @@ def player_info(request): recent_games = None total_games = None games_breakdown = None - avg = None - accs = None + recent_weapons = None return {'player':player, 'elos_display':elos_display, @@ -216,8 +219,7 @@ def player_info(request): 'total_stats':total_stats, 'total_games':total_games, 'games_breakdown':games_breakdown, - 'avg':avg, - 'accs':accs, + 'recent_weapons':recent_weapons, } @@ -290,6 +292,10 @@ def player_accuracy(request): (avg, accs) = get_accuracy_stats(player_id, weapon_cd, games) + # if we don't have enough data for the given weapon + if len(accs) < games: + games = len(accs) + return { 'player_id':player_id, 'player_url':request.route_url('player_info', id=player_id),