]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/templates/player_info.mako
Merge branch 'pickupbot' into approved
[xonotic/xonstat.git] / xonstat / templates / player_info.mako
1 <%inherit file="base.mako"/>
2 <%namespace name="nav" file="nav.mako" />
3 <%namespace file="accuracy.mako" import="accuracy" />
4
5 <%block name="navigation">
6 ${nav.nav('players')}
7 </%block>
8
9 <%block name="js">
10     % if player is not None:
11       <script src="/static/js/jquery-1.7.1.min.js"></script>
12       <script src="/static/js/jquery.flot.min.js"></script>
13       <script src="/static/js/bootstrap-tab.js"></script>
14       <script type="text/javascript">
15       $(function () {
16         $('#gbtab').click(function(e) {
17             e.preventDefault();
18             $(this).tab('show');
19         })
20       })
21       </script>
22
23       <script type="text/javascript">
24       $(function () {
25           // plot the accuracy graph
26           function plot_acc_graph(data) {
27               var games = new Array();
28               var avgs = new Array();
29               var accs = new Array();
30
31               var i=0;
32               for(i=0; i < data.games; i++) {
33                   avgs[i] = [i, data.avg];
34                   accs[i] = [i, data.accs[i][1]];
35                   game_link = '/game/' + data.accs[i][0];
36                   j = data.games - i;
37                   games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
38               }
39
40               $.plot(
41                   $("#acc-graph"), 
42                   [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
43                     { label: 'accuracy', data: accs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
44                   { yaxis: {ticks: 10, min: 0, max: 100 },
45                     xaxis: {ticks: games},
46                     grid: { hoverable: true, clickable: true },
47               });
48           }
49
50           // plot the damage graph
51           function plot_dmg_graph(data) {
52               var games = new Array();
53               var avgs = new Array();
54               var dmgs = new Array();
55
56               var i=0;
57               for(i=0; i < data.games; i++) {
58                   avgs[i] = [i, data.avg];
59                   dmgs[i] = [i, data.dmgs[i][1]];
60                   game_link = '/game/' + data.dmgs[i][0];
61                   j = data.games - i;
62                   games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
63               }
64
65               $.plot(
66                   $("#dmg-graph"), 
67                   [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
68                     { label: 'efficiency', data: dmgs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
69                   { yaxis: {ticks: 10, min: 0 },
70                     xaxis: {ticks: games},
71                     grid: { hoverable: true, clickable: true },
72               });
73           }
74
75           function showTooltip(x, y, contents) {
76             $('<div id="tooltip">' + contents + '</div>').css( {
77                 position: 'absolute',
78                 display: 'none',
79                 top: y - 35,
80                 left: x + 10,
81                 border: '1px solid #fdd',
82                 padding: '2px',
83                 'background-color': '#333333',
84                 opacity: 0.80
85             }).appendTo("body").fadeIn(200);
86           }
87
88           var previousPoint = null;
89           var previousLabel = null;
90           $('#acc-graph').bind("plothover", function (event, pos, item) {
91               if (item) {
92                 if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
93                     previousLabel = item.series.label;
94                     previousPoint = item.dataIndex;
95
96                     $("#tooltip").remove();
97                     var x = item.datapoint[0].toFixed(2),
98                         y = item.datapoint[1].toFixed(2);
99
100                     showTooltip(item.pageX, item.pageY, y + "%");
101                   }
102               }
103               else {
104                   $("#tooltip").remove();
105                   previousPoint = null;
106                   previousLabel = null;
107               }
108           });
109
110           $('#dmg-graph').bind("plothover", function (event, pos, item) {
111               if (item) {
112                 if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
113                     previousPoint = item.dataIndex;
114                     previousLabel = item.series.label;
115
116                     $("#tooltip").remove();
117                     var x = item.datapoint[0].toFixed(2),
118                         y = item.datapoint[1].toFixed(2);
119
120                     showTooltip(item.pageX, item.pageY, y);
121                   }
122               }
123               else {
124                   $("#tooltip").remove();
125                   previousPoint = null;
126                   previousLabel = null;
127               }
128           });
129
130           // bind click events to the weapon images
131           $(".acc-weap").click(function () {
132               var dataurl = $(this).find('a').attr('href');
133
134               $('.accuracy-nav').find('.weapon-active').removeClass('weapon-active');
135               $(this).addClass('weapon-active');
136
137               $.ajax({
138                   url: dataurl,
139                   method: 'GET',
140                   dataType: 'json',
141                   success: plot_acc_graph
142               });
143           });
144
145           $(".dmg-weap").click(function () {
146               var dataurl = $(this).find('a').attr('href');
147
148               $('.damage-nav').find('.weapon-active').removeClass('weapon-active');
149               $(this).addClass('weapon-active');
150
151               $.ajax({
152                   url: dataurl,
153                   method: 'GET',
154                   dataType: 'json',
155                   success: plot_dmg_graph
156               });
157           });
158
159           // populate the graphs with the default weapons
160           $.ajax({
161               url: '${request.route_url("player_accuracy", id=player.player_id)}',
162               method: 'GET',
163               dataType: 'json',
164               success: plot_acc_graph
165           });
166
167           $.ajax({
168               url: '${request.route_url("player_damage", id=player.player_id)}',
169               method: 'GET',
170               dataType: 'json',
171               success: plot_dmg_graph
172           });
173       })
174       </script>
175     % endif
176 </%block>
177
178 <%block name="title">
179 Player Information
180 </%block>
181
182
183 % if player is None:
184 <h2>This player is so good we couldn't find him!</h2>
185 <p>Seriously though, he probably doesn't exist...just a figment of your imagination. Carry on then!</p>
186
187 % else:
188 <div class="row">
189   <div class="span12">
190     <h2>${player.nick_html_colors()|n}</h2>
191   </div>
192 </div>
193
194 <div class="row">
195   <div class="tabbable tabs-right">
196       <ul id="gbtab" class="nav nav-tabs">
197       % for g in games_played:
198         <li><a href="#tab-${g.game_type_cd}" data-toggle="tab">${g.game_type_cd} (${g.games})</a></li>
199       % endfor
200       </ul>
201
202       <div class="tab-content">
203       % for g in games_played:
204         <div class="tab-pane fade in 
205         % if g.game_type_cd == 'overall':
206           active
207         % endif
208         " id="tab-${g.game_type_cd}">
209           <div class="span5">
210             % if g.game_type_cd in overall_stats:
211             Last Played: ${overall_stats[g.game_type_cd].last_played} <br />
212             % endif
213
214             Games Played: ${g.games} <br />
215
216             % if g.game_type_cd in fav_maps:
217             Favorite Map: ${fav_maps[g.game_type_cd].map_name} <br />
218             % endif
219
220             Win Percentage: ${round(g.win_pct,2)}% (${g.wins} wins, ${g.losses} losses) <br />
221
222             % if g.game_type_cd in overall_stats:
223             Kill Ratio: ${round(overall_stats[g.game_type_cd].k_d_ratio,2)} (${overall_stats[g.game_type_cd].total_kills} kills, ${overall_stats[g.game_type_cd].total_deaths} deaths) <br />
224             % endif
225
226             % if g.game_type_cd in elos:
227             Elo: ${round(elos[g.game_type_cd].elo,2)} (${elos[g.game_type_cd].games} games) <br />
228             % endif
229
230             % if g.game_type_cd in ranks:
231             Rank: ${ranks[g.game_type_cd].rank} of ${ranks[g.game_type_cd].max_rank} <br />
232             % endif
233
234           </div>
235         </div>
236       % endfor
237       </div>
238   </div>
239 </div>
240
241
242 % if 'nex' in recent_weapons or 'rifle' in recent_weapons or 'minstanex' in recent_weapons or 'uzi' in recent_weapons or 'shotgun' in recent_weapons:
243 <div class="row">
244   <div class="span10">
245     <h3>Accuracy</h3>
246     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
247     </div>
248
249     <div class="weapon-nav accuracy-nav">
250       <ul>
251         % if 'nex' in recent_weapons:
252         <li>
253           <div class="acc-weap weapon-active">
254             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
255             <p><small>Nex</small></p>
256             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'nex'})}" title="Show nex accuracy"></a>
257           </div>
258         </li>
259         % endif
260
261         % if 'rifle' in recent_weapons:
262         <li>
263           <div class="acc-weap">
264             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
265             <p><small>Rifle</small></p>
266             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'rifle'})}" title="Show rifle accuracy"></a>
267           </div>
268         </li>
269         % endif
270
271         % if 'minstanex' in recent_weapons:
272         <li>
273           <div class="acc-weap">
274             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
275             <p><small>Minstanex</small></p>
276             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'minstanex'})}" title="Show minstanex accuracy"></a>
277           </div>
278         </li>
279         % endif
280
281         % if 'uzi' in recent_weapons:
282         <li>
283           <div class="acc-weap">
284             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
285             <p><small>Uzi</small></p>
286             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'uzi'})}" title="Show uzi accuracy"></a>
287           </div>
288         </li>
289         % endif
290
291         % if 'shotgun' in recent_weapons:
292         <li>
293           <div class="acc-weap">
294             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
295             <p><small>Shotgun</small></p>
296             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'shotgun'})}" title="Show shotgun accuracy"></a>
297           </div>
298         </li>
299         % endif
300       </ul>
301     </div>
302
303   </div>
304 </div>
305 % endif
306
307
308 % if 'rocketlauncher' in recent_weapons or 'grenadelauncher' in recent_weapons or 'electro' in recent_weapons or 'crylink' in recent_weapons or 'laser' in recent_weapons:
309 <div class="row">
310   <div class="span10">
311     <h3>Damage Efficiency</h3>
312     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
313     </div>
314
315     <div class="weapon-nav damage-nav">
316       <ul>
317         % if 'rocketlauncher' in recent_weapons:
318         <li>
319           <div class="dmg-weap weapon-active">
320             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
321             <p><small>Rocket</small></p>
322             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'rocketlauncher'})}" title="Show rocket launcher efficiency"></a>
323           </div>
324         </li>
325         % endif
326
327         % if 'grenadelauncher' in recent_weapons:
328         <li>
329           <div class="dmg-weap">
330             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
331             <p><small>Mortar</small></p>
332             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'grenadelauncher'})}" title="Show mortar damage efficiency"></a>
333           </div>
334         </li>
335         % endif
336
337         % if 'electro' in recent_weapons:
338         <li>
339           <div class="dmg-weap">
340             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
341             <p><small>Electro</small></p>
342             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'electro'})}" title="Show electro damage efficiency"></a>
343           </div>
344         </li>
345         % endif
346
347         % if 'crylink' in recent_weapons:
348         <li>
349           <div class="dmg-weap">
350             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
351             <p><small>Crylink</small></p>
352             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'crylink'})}" title="Show crylink damage efficiency"></a>
353           </div>
354         </li>
355         % endif
356
357         % if 'hagar' in recent_weapons:
358         <li>
359           <div class="dmg-weap">
360             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
361             <p><small>Hagar</small></p>
362             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'hagar'})}" title="Show hagar damage efficiency"></a>
363           </div>
364         </li>
365         % endif
366
367         % if 'laser' in recent_weapons:
368         <li>
369           <div class="dmg-weap">
370             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
371             <p><small>Laser</small></p>
372             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'laser'})}" title="Show laser damage efficiency"></a>
373           </div>
374         </li>
375         % endif
376
377       </ul>
378     </div>
379
380   </div>
381 </div>
382 % endif
383
384
385 ##### RECENT GAMES (v2) ####
386 % if recent_games:
387 <div class="row">
388   <div class="span12">
389     <h3>Recent Games</h3>
390     <table class="table table-bordered table-condensed">
391       <thead>
392         <tr>
393            <th></th>
394            <th>Type</th>
395            <th>Server</th>
396            <th>Map</th>
397            <th>Result</th>
398            <th>Played</th>
399         </tr>
400       </thead>
401       <tbody>
402       % for (gamestat, game, server, map) in recent_games:
403         <tr>
404            <td><a class="btn btn-primary btn-small" href="${request.route_url('game_info', id=game.game_id)}" title="View detailed information about this game">view</a></td>
405            <td style="width:20px;"><img title="${game.game_type_cd}" src="/static/images/icons/24x24/${game.game_type_cd}.png" alt="${game.game_type_cd}" /></td>
406            <td>${server.name}</td>
407            <td>${map.name}</td>
408            <td>
409            % if gamestat.team != None:
410              % if gamestat.team == game.winner:
411              Win
412              % else:
413              Loss
414              % endif
415           % else:
416             % if gamestat.rank == 1:
417             Win
418             % else:
419             Loss (#${gamestat.rank})
420             % endif
421           % endif
422            </td>
423            <td><span class="abstime" data-epoch="${game.epoch()}" title="${game.create_dt.strftime('%a, %d %b %Y %H:%M:%S UTC')}">${game.fuzzy_date()}</span></td>
424         </tr>
425       % endfor
426       </tbody>
427     </table>
428     % if total_games > 10:
429     <a href="${request.route_url("player_game_index", player_id=player.player_id, page=1)}" title="Game index for ${player.nick}">More games played by ${player.nick_html_colors()|n}...</a>
430     % endif
431   </div>
432 </div>
433 % endif
434 % endif