]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/templates/player_info.mako
Restructured player_info page to now include more detailed stats for specific gametyp...
[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       % if fav_server is not None:
193       Favorite Server: <small>
194       <% srv_list = fav_server[:1] %>
195       % for srvinfo in srv_list:
196           % if srvinfo != srv_list[-1]:
197               <% delim = ", " %>
198           % else:
199               <% delim = "" %>
200           % endif
201           <a href="${request.route_url('server_info', id=srvinfo['id'])}" title="view server info">${srvinfo['name']}</a>${delim}
202       % endfor
203       </small><br />
204       % endif
205
206       % if fav_map is not None:
207       Favorite Maps: <small>
208       <% map_list = fav_map[:3] %>
209       % for mapinfo in map_list:
210           % if mapinfo != map_list[-1]:
211               <% delim = ", " %>
212           % else:
213               <% delim = "" %>
214           % endif
215           <a href="${request.route_url('map_info', id=mapinfo['id'])}" title="view map info">${mapinfo['name']}</a>${delim}
216       % endfor
217       </small><br />
218       % endif
219
220       % if fav_weapon is not None:
221       Favorite Weapons: <small>
222       <% wpn_list = fav_weapon[:3] %>
223       % for wpninfo in wpn_list:
224           % if wpninfo != wpn_list[-1]:
225               <% delim = ", " %>
226           % else:
227               <% delim = "" %>
228           % endif
229           ${wpninfo['name']}${delim}
230       % endfor
231       </small><br />
232       % endif
233     </p>
234   </div>
235   <div class="span6">
236     <p>
237       Playing Time: <small>${total_stats['alivetime']} hours
238       % if total_stats['alivetime'] > total_stats['alivetime_month']:
239           % if total_stats['alivetime_month'] > total_stats['alivetime_week']:
240               (${total_stats['alivetime_month']} hours this month; ${total_stats['alivetime_week']} hours this week)
241           % else:
242               (${total_stats['alivetime_month']} hours this month)
243           % endif
244       % endif
245       </small><br />
246
247       <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in total_stats['games_breakdown'].items()]) %>
248       Games Played: <small>${total_stats['games']} (${games_breakdown_str})</small><br />
249
250        % if total_stats['games'] > 0 and total_stats['wins'] is not None:
251        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 />
252        % endif
253
254        % if total_stats['kills'] > 0 and total_stats['deaths'] > 0:
255        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 />
256        % endif
257     </p>
258   </div>
259 </div>
260
261 <div class="row">
262   <div class="span10">
263     <p>
264        % if total_stats['games_breakdown'].has_key('duel'):
265        Duel Stats: <small>
266            % if total_stats['duel_wins'] is not None:
267            Win Percentage ${round(float(total_stats['duel_wins'])/total_stats['games_breakdown']['duel'] * 100, 2)}%  (${total_stats['duel_wins']} wins, ${total_stats['games_breakdown']['duel'] - total_stats['duel_wins']} losses)
268            % endif
269
270            % if total_stats['duel_kills'] > 0 and total_stats['duel_deaths'] > 0:
271            | Kill Ratio ${round(float(total_stats['duel_kills'])/total_stats['duel_deaths'], 3)} (${total_stats['duel_kills']} kills, ${total_stats['duel_deaths']} deaths, ${total_stats['duel_suicides']} suicides)
272            % endif
273        </small><br />
274        % endif
275
276        % if total_stats['games_breakdown'].has_key('dm'):
277        DM Stats: <small>
278            % if total_stats['dm_wins'] is not None:
279            Win Percentage ${round(float(total_stats['dm_wins'])/total_stats['games_breakdown']['dm'] * 100, 2)}%  (${total_stats['dm_wins']} wins, ${total_stats['games_breakdown']['dm'] - total_stats['dm_wins']} losses)
280            % endif
281
282            % if total_stats['dm_kills'] > 0 and total_stats['dm_deaths'] > 0:
283            | Kill Ratio ${round(float(total_stats['dm_kills'])/total_stats['dm_deaths'], 3)} (${total_stats['dm_kills']} kills, ${total_stats['dm_deaths']} deaths, ${total_stats['dm_suicides']} suicides)
284            % endif
285        </small><br />
286        % endif
287
288        % if total_stats['games_breakdown'].has_key('tdm'):
289        TDM Stats: <small>
290            % if total_stats['tdm_wins'] is not None:
291            Win Percentage ${round(float(total_stats['tdm_wins'])/total_stats['games_breakdown']['tdm'] * 100, 2)}%  (${total_stats['tdm_wins']} wins, ${total_stats['games_breakdown']['tdm'] - total_stats['tdm_wins']} losses)
292            % endif
293
294            % if total_stats['tdm_kills'] > 0 and total_stats['tdm_deaths'] > 0:
295            | Kill Ratio ${round(float(total_stats['tdm_kills'])/total_stats['tdm_deaths'], 3)} (${total_stats['tdm_kills']} kills, ${total_stats['tdm_deaths']} deaths, ${total_stats['tdm_suicides']} suicides)
296            % endif
297        </small><br />
298        % endif
299
300        % if total_stats['games_breakdown'].has_key('ctf'):
301        CTF Stats: <small>
302            % if total_stats['ctf_wins'] is not None:
303            Win Percentage ${round(float(total_stats['ctf_wins'])/total_stats['games_breakdown']['ctf'] * 100, 2)}%  (${total_stats['ctf_wins']} wins, ${total_stats['games_breakdown']['ctf'] - total_stats['ctf_wins']} losses)
304            % endif
305
306            % if total_stats['ctf_pickups'] > 0 and total_stats['tdm_captures'] > 0:
307            | Cap Ratio ${round(float(total_stats['ctf_caps'])/total_stats['ctf_pickups'], 3)} (${total_stats['ctf_caps']} caps, ${total_stats['ctf_pickups']} pickups, ${total_stats['ctf_returns']} returns, ${total_stats['ctf_fckills']} fckills)
308            % endif
309        </small><br />
310        % endif
311
312        % if elos_display is not None and len(elos_display) > 0:
313        Elo:
314           <small>${elos_display} </small>
315           %if '*' in elos_display:
316               <small><i>*preliminary Elo</i></small>
317           %endif
318           <br />
319       % endif
320
321       % if ranks_display != '':
322       Ranks: <small>${ranks_display}</small><br />
323       % endif
324     </p>
325   </div>
326 </div>
327
328 % 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:
329 <div class="row">
330   <div class="span10">
331     <h3>Accuracy</h3>
332     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
333     </div>
334
335     <div class="weapon-nav accuracy-nav">
336       <ul>
337         % if 'nex' in recent_weapons:
338         <li>
339           <div class="acc-weap weapon-active">
340             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
341             <p><small>Nex</small></p>
342             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','nex')])}" title="Show nex accuracy"></a>
343           </div>
344         </li>
345         % endif
346
347         % if 'rifle' in recent_weapons:
348         <li>
349           <div class="acc-weap">
350             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
351             <p><small>Rifle</small></p>
352             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','rifle')])}" title="Show rifle accuracy"></a>
353           </div>
354         </li>
355         % endif
356
357         % if 'minstanex' in recent_weapons:
358         <li>
359           <div class="acc-weap">
360             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
361             <p><small>Minstanex</small></p>
362             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','minstanex')])}" title="Show minstanex accuracy"></a>
363           </div>
364         </li>
365         % endif
366
367         % if 'uzi' in recent_weapons:
368         <li>
369           <div class="acc-weap">
370             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
371             <p><small>Uzi</small></p>
372             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','uzi')])}" title="Show uzi accuracy"></a>
373           </div>
374         </li>
375         % endif
376
377         % if 'shotgun' in recent_weapons:
378         <li>
379           <div class="acc-weap">
380             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
381             <p><small>Shotgun</small></p>
382             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','shotgun')])}" title="Show shotgun accuracy"></a>
383           </div>
384         </li>
385         % endif
386       </ul>
387     </div>
388
389   </div>
390 </div>
391 % endif
392
393
394 % 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:
395 <div class="row">
396   <div class="span10">
397     <h3>Damage Efficiency</h3>
398     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
399     </div>
400
401     <div class="weapon-nav damage-nav">
402       <ul>
403         % if 'rocketlauncher' in recent_weapons:
404         <li>
405           <div class="dmg-weap weapon-active">
406             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
407             <p><small>Rocket</small></p>
408             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','rocketlauncher')])}" title="Show rocket launcher efficiency"></a>
409           </div>
410         </li>
411         % endif
412
413         % if 'grenadelauncher' in recent_weapons:
414         <li>
415           <div class="dmg-weap">
416             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
417             <p><small>Mortar</small></p>
418             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','grenadelauncher')])}" title="Show mortar damage efficiency"></a>
419           </div>
420         </li>
421         % endif
422
423         % if 'electro' in recent_weapons:
424         <li>
425           <div class="dmg-weap">
426             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
427             <p><small>Electro</small></p>
428             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','electro')])}" title="Show electro damage efficiency"></a>
429           </div>
430         </li>
431         % endif
432
433         % if 'crylink' in recent_weapons:
434         <li>
435           <div class="dmg-weap">
436             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
437             <p><small>Crylink</small></p>
438             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','crylink')])}" title="Show crylink damage efficiency"></a>
439           </div>
440         </li>
441         % endif
442
443         % if 'hagar' in recent_weapons:
444         <li>
445           <div class="dmg-weap">
446             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
447             <p><small>Hagar</small></p>
448             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','hagar')])}" title="Show hagar damage efficiency"></a>
449           </div>
450         </li>
451         % endif
452
453         % if 'laser' in recent_weapons:
454         <li>
455           <div class="dmg-weap">
456             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
457             <p><small>Laser</small></p>
458             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','laser')])}" title="Show laser damage efficiency"></a>
459           </div>
460         </li>
461         % endif
462
463       </ul>
464     </div>
465
466   </div>
467 </div>
468 % endif
469
470
471 ##### RECENT GAMES (v2) ####
472 % if recent_games:
473 <div class="row">
474   <div class="span12">
475     <h3>Recent Games</h3>
476     <table class="table table-bordered table-condensed">
477       <thead>
478         <tr>
479            <th></th>
480            <th>Type</th>
481            <th>Server</th>
482            <th>Map</th>
483            <th>Result</th>
484            <th>Played</th>
485         </tr>
486       </thead>
487       <tbody>
488       % for (gamestat, game, server, map) in recent_games:
489         <tr>
490            <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>
491            <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>
492            <td>${server.name}</td>
493            <td>${map.name}</td>
494            <td>
495            % if gamestat.team != None:
496              % if gamestat.team == game.winner:
497              Win
498              % else:
499              Loss
500              % endif
501           % else:
502             % if gamestat.rank == 1:
503             Win
504             % else:
505             Loss (#${gamestat.rank})
506             % endif
507           % endif
508            </td>
509            <td>${game.fuzzy_date()}</td>
510         </tr>
511       % endfor
512       </tbody>
513     </table>
514     % if total_games > 10:
515     <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>
516     % endif
517   </div>
518 </div>
519 % endif
520 % endif