Fixed bug in "total wins" query - NOTE: other queries (e.g. duel wins) are still...
[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.flot.min.js"></script>
12       <script src="/static/js/bootstrap-tabs.js"></script>
13       <script type="text/javascript">
14       jQuery(document).ready(function ($) {
15           $(".tabs").tabs();
16       });      
17
18       $(function () {
19           // plot the accuracy graph
20           function plot_acc_graph(data) {
21               var games = new Array();
22               var avgs = new Array();
23               var accs = new Array();
24
25               var i=0;
26               for(i=0; i < data.games; i++) {
27                   avgs[i] = [i, data.avg];
28                   accs[i] = [i, data.accs[i][1]];
29                   game_link = '/game/' + data.accs[i][0];
30                   j = data.games - i;
31                   games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
32               }
33
34               $.plot(
35                   $("#acc-graph"), 
36                   [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
37                     { label: 'accuracy', data: accs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
38                   { yaxis: {ticks: 10, min: 0, max: 100 },
39                     xaxis: {ticks: games},
40                     grid: { hoverable: true, clickable: true },
41               });
42           }
43
44           // plot the damage graph
45           function plot_dmg_graph(data) {
46               var games = new Array();
47               var avgs = new Array();
48               var dmgs = new Array();
49
50               var i=0;
51               for(i=0; i < data.games; i++) {
52                   avgs[i] = [i, data.avg];
53                   dmgs[i] = [i, data.dmgs[i][1]];
54                   game_link = '/game/' + data.dmgs[i][0];
55                   j = data.games - i;
56                   games[i] = [i, '<a href="' + game_link + '">' + j + '</a>'];
57               }
58
59               $.plot(
60                   $("#dmg-graph"), 
61                   [ { label: 'average', data: avgs, hoverable: true, clickable: false }, 
62                     { label: 'efficiency', data: dmgs, lines: {show:true}, points: {show:false}, hoverable: true, clickable: true }, ],
63                   { yaxis: {ticks: 10, min: 0 },
64                     xaxis: {ticks: games},
65                     grid: { hoverable: true, clickable: true },
66               });
67           }
68
69           function showTooltip(x, y, contents) {
70             $('<div id="tooltip">' + contents + '</div>').css( {
71                 position: 'absolute',
72                 display: 'none',
73                 top: y - 35,
74                 left: x + 10,
75                 border: '1px solid #fdd',
76                 padding: '2px',
77                 'background-color': '#333333',
78                 opacity: 0.80
79             }).appendTo("body").fadeIn(200);
80           }
81
82           var previousPoint = null;
83           var previousLabel = null;
84           $('#acc-graph').bind("plothover", function (event, pos, item) {
85               if (item) {
86                   if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
87                     previousPoint = item.dataIndex;
88                     previousLabel = item.series.label;
89
90                     $("#tooltip").remove();
91                     var x = item.datapoint[0].toFixed(2),
92                         y = item.datapoint[1].toFixed(2);
93
94                     showTooltip(item.pageX, item.pageY, y + "%");
95                   }
96               }
97               else {
98                   $("#tooltip").remove();
99                   previousPoint = null;
100                   previousLabel = null;
101               }
102           });
103
104           $('#dmg-graph').bind("plothover", function (event, pos, item) {
105               if (item) {
106                   if ((previousLabel != item.series.label) || (previousPoint != item.dataIndex)) {
107                     previousPoint = item.dataIndex;
108                     previousLabel = item.series.label;
109
110                     $("#tooltip").remove();
111                     var x = item.datapoint[0].toFixed(2),
112                         y = item.datapoint[1].toFixed(2);
113
114                     showTooltip(item.pageX, item.pageY, y);
115                   }
116               }
117               else {
118                   $("#tooltip").remove();
119                   previousPoint = null;
120                   previousLabel = null;
121               }
122           });
123
124           // bind click events to the weapon images
125           $(".acc-weap").click(function () {
126               var dataurl = $(this).find('a').attr('href');
127
128               $('.accuracy-nav').find('.weapon-active').removeClass('weapon-active');
129               $(this).addClass('weapon-active');
130
131               $.ajax({
132                   url: dataurl,
133                   method: 'GET',
134                   dataType: 'json',
135                   success: plot_acc_graph
136               });
137           });
138
139           $(".dmg-weap").click(function () {
140               var dataurl = $(this).find('a').attr('href');
141
142               $('.damage-nav').find('.weapon-active').removeClass('weapon-active');
143               $(this).addClass('weapon-active');
144
145               $.ajax({
146                   url: dataurl,
147                   method: 'GET',
148                   dataType: 'json',
149                   success: plot_dmg_graph
150               });
151           });
152
153           // populate the graphs with the default weapons
154           $.ajax({
155               url: '${request.route_url("player_accuracy", id=player.player_id)}',
156               method: 'GET',
157               dataType: 'json',
158               success: plot_acc_graph
159           });
160
161           $.ajax({
162               url: '${request.route_url("player_damage", id=player.player_id)}',
163               method: 'GET',
164               dataType: 'json',
165               success: plot_dmg_graph
166           });
167       })
168       </script>
169       <script src="/static/js/bootstrap-tabs.min.js"></script>
170     % endif
171 </%block>
172
173 <%block name="title">
174 Player Information
175 </%block>
176
177
178 % if player is None:
179 <h2>This player is so good we couldn't find him!</h2>
180 <p>Seriously though, he probably doesn't exist...just a figment of your imagination. Carry on then!</p>
181
182 % else:
183 <div class="row">
184   <div class="span12">
185     <h2>${player.nick_html_colors()|n}</h2>
186   </div>
187 </div>
188
189 <div class="row">
190   <div class="span6">
191     <p>
192       Member Since: <small>${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')} </small><br />
193
194       Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
195
196       Playing Time: <small>${total_stats['alivetime']}
197       % if total_stats['alivetime_month'] and total_stats['alivetime'] > total_stats['alivetime_month']:
198           % if total_stats['alivetime_week'] and total_stats['alivetime_month'] > total_stats['alivetime_week']:
199               <br />(${total_stats['alivetime_month']} this month; ${total_stats['alivetime_week']} this week)
200           % else:
201               <br />(${total_stats['alivetime_month']} this month)
202           % endif
203       % endif
204       </small><br />
205
206       <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in total_stats['games_breakdown'].items()]) %>
207       Games Played: <small>${total_stats['games']}<br />(${games_breakdown_str})</small><br />
208     </p>
209   </div>
210   <div class="span6">
211     <p>
212       % if fav_server is not None:
213       Favorite Server: <small><a href="${request.route_url('server_info', id=fav_server[0]['id'])}" title="view server info">${fav_server[0]['name']}</a></small><br />
214       % endif
215
216       % if fav_map is not None:
217       Favorite Map: <small><a href="${request.route_url('map_info', id=fav_map[0]['id'])}" title="view map info">${fav_map[0]['name']}</a></small><br />
218       % endif
219
220       % if fav_weapon is not None:
221       Favorite Weapon: <small>${fav_weapon[0]['name']}</small><br />
222       % endif
223
224       % if total_stats['games'] > 0 and total_stats['wins'] is not None:
225       Win Percentage: <small>${round(float(total_stats['wins'])/total_stats['games'] * 100, 2)}% (${total_stats['wins']} wins, ${total_stats['games'] - total_stats['wins']} losses) </small><br />
226       % endif
227
228       % if total_stats['kills'] > 0 and total_stats['deaths'] > 0:
229       Kill Ratio: <small>${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths, ${total_stats['suicides']} suicides) </small><br />
230       % endif
231     </p>
232   </div>
233 </div>
234
235 <div class="row">
236   <div class="span12">
237     <p>
238        % if elos_display is not None and len(elos_display) > 0:
239        Elo:
240           <small>${elos_display} </small>
241           %if '*' in elos_display:
242               <small><i>*preliminary Elo</i></small>
243           %endif
244           <br />
245       % endif
246
247       % if ranks_display != '':
248       Ranks: <small>${ranks_display}</small><br />
249       % endif
250     </p>
251   </div>
252 </div>
253
254 % 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:
255 <div class="row">
256   <div class="span10">
257     <h3>Accuracy</h3>
258     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
259     </div>
260
261     <div class="weapon-nav accuracy-nav">
262       <ul>
263         % if 'nex' in recent_weapons:
264         <li>
265           <div class="acc-weap weapon-active">
266             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
267             <p><small>Nex</small></p>
268             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','nex')])}" title="Show nex accuracy"></a>
269           </div>
270         </li>
271         % endif
272
273         % if 'rifle' in recent_weapons:
274         <li>
275           <div class="acc-weap">
276             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
277             <p><small>Rifle</small></p>
278             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','rifle')])}" title="Show rifle accuracy"></a>
279           </div>
280         </li>
281         % endif
282
283         % if 'minstanex' in recent_weapons:
284         <li>
285           <div class="acc-weap">
286             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
287             <p><small>Minstanex</small></p>
288             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','minstanex')])}" title="Show minstanex accuracy"></a>
289           </div>
290         </li>
291         % endif
292
293         % if 'uzi' in recent_weapons:
294         <li>
295           <div class="acc-weap">
296             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
297             <p><small>Uzi</small></p>
298             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','uzi')])}" title="Show uzi accuracy"></a>
299           </div>
300         </li>
301         % endif
302
303         % if 'shotgun' in recent_weapons:
304         <li>
305           <div class="acc-weap">
306             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
307             <p><small>Shotgun</small></p>
308             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','shotgun')])}" title="Show shotgun accuracy"></a>
309           </div>
310         </li>
311         % endif
312       </ul>
313     </div>
314
315   </div>
316 </div>
317 % endif
318
319
320 % 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:
321 <div class="row">
322   <div class="span10">
323     <h3>Damage Efficiency</h3>
324     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
325     </div>
326
327     <div class="weapon-nav damage-nav">
328       <ul>
329         % if 'rocketlauncher' in recent_weapons:
330         <li>
331           <div class="dmg-weap weapon-active">
332             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
333             <p><small>Rocket</small></p>
334             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','rocketlauncher')])}" title="Show rocket launcher efficiency"></a>
335           </div>
336         </li>
337         % endif
338
339         % if 'grenadelauncher' in recent_weapons:
340         <li>
341           <div class="dmg-weap">
342             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
343             <p><small>Mortar</small></p>
344             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','grenadelauncher')])}" title="Show mortar damage efficiency"></a>
345           </div>
346         </li>
347         % endif
348
349         % if 'electro' in recent_weapons:
350         <li>
351           <div class="dmg-weap">
352             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
353             <p><small>Electro</small></p>
354             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','electro')])}" title="Show electro damage efficiency"></a>
355           </div>
356         </li>
357         % endif
358
359         % if 'crylink' in recent_weapons:
360         <li>
361           <div class="dmg-weap">
362             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
363             <p><small>Crylink</small></p>
364             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','crylink')])}" title="Show crylink damage efficiency"></a>
365           </div>
366         </li>
367         % endif
368
369         % if 'hagar' in recent_weapons:
370         <li>
371           <div class="dmg-weap">
372             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
373             <p><small>Hagar</small></p>
374             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','hagar')])}" title="Show hagar damage efficiency"></a>
375           </div>
376         </li>
377         % endif
378
379         % if 'laser' in recent_weapons:
380         <li>
381           <div class="dmg-weap">
382             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
383             <p><small>Laser</small></p>
384             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','laser')])}" title="Show laser damage efficiency"></a>
385           </div>
386         </li>
387         % endif
388
389       </ul>
390     </div>
391
392   </div>
393 </div>
394 % endif
395
396 <div class="row">
397   <div class="span8 tabbable">
398     <h3>Game Breakdown</h3>
399     <ul class="tabs nav nav-pills" data-tabs="tabs">
400     <% gametypes = ['Overall', 'Duel', 'DM', 'TDM', 'CTF'] %>
401     % for gtc in gametypes:
402       % if gtc.lower() == 'overall' or total_stats['games_breakdown'].has_key(gtc.lower()):
403         % if gtc.lower() == 'overall':
404       <li class="active">
405         % else:
406       <li>
407         % endif
408         <a href="#breakdown-${gtc.lower()}" data-toggle="tabs">${gtc}</a>
409       </li>
410       % endif
411     % endfor
412     </ul>
413     <div class="tab-content">
414     % for gtc in gametypes:
415       <% gtc_key = gtc.lower() %>
416       % if gtc_key == "overall":
417         <% total     = total_stats['games'] %>
418         <% alivetime = total_stats['alivetime'] %>
419         <% wins      = total_stats['wins'] %>
420         <% losses    = total - wins %>
421         <% kills     = total_stats['kills'] %>
422         <% deaths    = total_stats['deaths'] %>
423         <% suicides  = total_stats['suicides'] %>
424       % elif total_stats['games_breakdown'].has_key(gtc_key):
425         <% total     = total_stats['games_breakdown'][gtc_key] %>
426         <% alivetime = total_stats['games_alivetime'][gtc_key] %>
427         <% wins      = total_stats[gtc_key+'_wins'] %>
428         <% losses    = total - wins %>
429         % if gtc_key == "ctf":
430           <% caps      = total_stats[gtc_key+'_caps'] %>
431           <% pickups   = total_stats[gtc_key+'_pickups'] %>
432           <% returns   = total_stats[gtc_key+'_returns'] %>
433           <% drops     = total_stats[gtc_key+'_drops'] %>
434           <% fckills   = total_stats[gtc_key+'_fckills'] %>
435         % else:
436           <% kills     = total_stats[gtc_key+'_kills'] %>
437           <% deaths    = total_stats[gtc_key+'_deaths'] %>
438           <% suicides  = total_stats[gtc_key+'_suicides'] %>
439         % endif
440       % endif
441       % if gtc_key == 'overall' or total_stats['games_breakdown'].has_key(gtc_key):
442         % if gtc_key == 'overall':
443       <div class="tab-pane active" id="breakdown-${gtc_key}">
444         % else:
445       <div class="tab-pane" id="breakdown-${gtc_key}">
446         % endif
447         <div style="margin:15px;float:left;"><img title="${gtc}" src="/static/images/icons/48x48/${gtc_key}.png" alt="${gtc}" /></div>
448         <table class="table table-bordered table-condensed">
449           <thead>
450           </thead>
451           <tbody>
452             <tr>
453               <td><b>Games Played:</b></td>
454               <td>${total}</td>
455               % if gtc_key == 'overall':
456               <td></td>
457               % else:
458               <td>${round(float(total)/total_stats['games'] * 100, 2)}% of all games</td>
459               % endif
460             </tr>
461             <tr>
462               <td><b>Playing Time:</b></td>
463               <td>${alivetime} hours</td>
464               % if gtc_key == 'overall':
465               <td></td>
466               % else:
467               <td>${round(float(alivetime.total_seconds())/total_stats['alivetime'].total_seconds() * 100, 2)}% of total playing time</td>
468               % endif
469             </tr>
470             <tr>
471               <td width="30%"><b>Win Percentage:</b></td>
472               <td width="30%">${round(float(wins)/total * 100, 2)}%</td>
473               <td width="40%">${wins} wins, ${losses} losses</td>
474             </tr>
475             % if gtc_key == 'ctf':
476             <tr>
477               <td><b>Caps:</b></td>
478               <td>${round(float(caps)/total, 2)} per game</td>
479               <td>${caps} total</td>
480             </tr>
481             <tr>
482               <td><b>Pickups:</b></td>
483               <td>${round(float(pickups)/total, 2)} per game</td>
484               <td>${pickups} total</td>
485             </tr>
486             <tr>
487               <td><b>Drops:</b></td>
488               <td>${round(float(drops)/total, 2)} per game</td>
489               <td>${drops} total</td>
490             </tr>
491             <tr>
492               <td><b>Returns:</b></td>
493               <td>${round(float(returns)/total, 2)} per game</td>
494               <td>${returns} total</td>
495             </tr>
496             <tr>
497               <td><b>FC Kills:</b></td>
498               <td>${round(float(fckills)/total, 2)} per game</td>
499               <td>${fckills} total</td>
500             </tr>
501             <tr>
502               <td><b>Cap Ratio:</b></td>
503               <td>${round(float(caps)/pickups, 3)}</td>
504               <td></td>
505             </tr>
506             <tr>
507               <td><b>Drop Ratio:</b></td>
508               <td>${round(float(drops)/pickups, 3)}</td>
509               <td></td>
510             </tr>
511             <tr>
512               <td><b>Return Ratio:</b></td>
513               <td>${round(float(returns)/fckills, 3)}</td>
514               <td></td>
515             </tr>
516             % else:
517             <tr>
518               <td><b>Kills:</b></td>
519               <td>${round(float(kills)/total, 2)} per game</td>
520               <td>${kills} total</td>
521             </tr>
522             <tr>
523               <td><b>Deaths:</b></td>
524               <td>${round(float(deaths)/total, 2)} per game</td>
525               <td>${deaths} total</td>
526             </tr>
527             <tr>
528               <td><b>Suicides:</b></td>
529               <td>${round(float(suicides)/total, 2)} per game</td>
530               <td>${suicides} total</td>
531             </tr>
532             <tr>
533               <td><b>Kill Ratio:</b></td>
534               <td>${round(float(kills)/deaths, 3)}</td>
535               <td></td>
536             </tr>
537             <tr>
538               <td><b>Suicide Ratio:</b></td>
539               <td>${round(float(suicides)/deaths, 3)}</td>
540               <td></td>
541             </tr>
542             % endif
543           </tbody>
544         </table>
545       </div>
546       % endif
547     % endfor
548     </div>
549   </div>
550 </div>
551
552
553 ##### RECENT GAMES (v2) ####
554 % if recent_games:
555 <br />
556 <div class="row">
557   <div class="span12">
558     <h3>Recent Games</h3>
559     <table class="table table-bordered table-condensed">
560       <thead>
561         <tr>
562            <th></th>
563            <th>Type</th>
564            <th>Server</th>
565            <th>Map</th>
566            <th>Result</th>
567            <th>Played</th>
568         </tr>
569       </thead>
570       <tbody>
571       % for (gamestat, game, server, map) in recent_games:
572         <tr>
573            <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>
574            <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>
575            <td>${server.name}</td>
576            <td>${map.name}</td>
577            <td>
578            % if gamestat.team != None:
579              % if gamestat.team == game.winner:
580              Win
581              % else:
582              Loss
583              % endif
584           % else:
585             % if gamestat.rank == 1:
586             Win
587             % else:
588             Loss (#${gamestat.rank})
589             % endif
590           % endif
591            </td>
592            <td>${game.fuzzy_date()}</td>
593         </tr>
594       % endfor
595       </tbody>
596     </table>
597     % if total_games > 10:
598     <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>
599     % endif
600   </div>
601 </div>
602 % endif
603 % endif