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