]> git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/templates/player_info.mako
Went back to showing only one favorite map/weapon/server; rearranged layout somewhat
[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 total_stats['games_breakdown'].has_key('duel'):
235        Duel Stats: <small>
236            % if total_stats['duel_wins'] is not None:
237            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)
238            % endif
239
240            % if total_stats['duel_kills'] > 0 and total_stats['duel_deaths'] > 0:
241            | 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)
242            % endif
243        </small><br />
244        % endif
245
246        % if total_stats['games_breakdown'].has_key('dm'):
247        DM Stats: <small>
248            % if total_stats['dm_wins'] is not None:
249            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)
250            % endif
251
252            % if total_stats['dm_kills'] > 0 and total_stats['dm_deaths'] > 0:
253            | 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)
254            % endif
255        </small><br />
256        % endif
257
258        % if total_stats['games_breakdown'].has_key('tdm'):
259        TDM Stats: <small>
260            % if total_stats['tdm_wins'] is not None:
261            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)
262            % endif
263
264            % if total_stats['tdm_kills'] > 0 and total_stats['tdm_deaths'] > 0:
265            | 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)
266            % endif
267        </small><br />
268        % endif
269
270        % if total_stats['games_breakdown'].has_key('ctf'):
271        CTF Stats: <small>
272            % if total_stats['ctf_wins'] is not None:
273            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)
274            % endif
275
276            % if total_stats['ctf_pickups'] > 0 and total_stats['ctf_caps'] > 0:
277            | 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)
278            % endif
279        </small><br />
280        % endif
281
282        % if elos_display is not None and len(elos_display) > 0:
283        Elo:
284           <small>${elos_display} </small>
285           %if '*' in elos_display:
286               <small><i>*preliminary Elo</i></small>
287           %endif
288           <br />
289       % endif
290
291       % if ranks_display != '':
292       Ranks: <small>${ranks_display}</small><br />
293       % endif
294     </p>
295   </div>
296 </div>
297
298 % 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:
299 <div class="row">
300   <div class="span10">
301     <h3>Accuracy</h3>
302     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
303     </div>
304
305     <div class="weapon-nav accuracy-nav">
306       <ul>
307         % if 'nex' in recent_weapons:
308         <li>
309           <div class="acc-weap weapon-active">
310             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
311             <p><small>Nex</small></p>
312             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','nex')])}" title="Show nex accuracy"></a>
313           </div>
314         </li>
315         % endif
316
317         % if 'rifle' in recent_weapons:
318         <li>
319           <div class="acc-weap">
320             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
321             <p><small>Rifle</small></p>
322             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','rifle')])}" title="Show rifle accuracy"></a>
323           </div>
324         </li>
325         % endif
326
327         % if 'minstanex' in recent_weapons:
328         <li>
329           <div class="acc-weap">
330             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
331             <p><small>Minstanex</small></p>
332             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','minstanex')])}" title="Show minstanex accuracy"></a>
333           </div>
334         </li>
335         % endif
336
337         % if 'uzi' in recent_weapons:
338         <li>
339           <div class="acc-weap">
340             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
341             <p><small>Uzi</small></p>
342             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','uzi')])}" title="Show uzi accuracy"></a>
343           </div>
344         </li>
345         % endif
346
347         % if 'shotgun' in recent_weapons:
348         <li>
349           <div class="acc-weap">
350             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
351             <p><small>Shotgun</small></p>
352             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','shotgun')])}" title="Show shotgun accuracy"></a>
353           </div>
354         </li>
355         % endif
356       </ul>
357     </div>
358
359   </div>
360 </div>
361 % endif
362
363
364 % 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:
365 <div class="row">
366   <div class="span10">
367     <h3>Damage Efficiency</h3>
368     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
369     </div>
370
371     <div class="weapon-nav damage-nav">
372       <ul>
373         % if 'rocketlauncher' in recent_weapons:
374         <li>
375           <div class="dmg-weap weapon-active">
376             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
377             <p><small>Rocket</small></p>
378             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','rocketlauncher')])}" title="Show rocket launcher efficiency"></a>
379           </div>
380         </li>
381         % endif
382
383         % if 'grenadelauncher' in recent_weapons:
384         <li>
385           <div class="dmg-weap">
386             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
387             <p><small>Mortar</small></p>
388             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','grenadelauncher')])}" title="Show mortar damage efficiency"></a>
389           </div>
390         </li>
391         % endif
392
393         % if 'electro' in recent_weapons:
394         <li>
395           <div class="dmg-weap">
396             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
397             <p><small>Electro</small></p>
398             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','electro')])}" title="Show electro damage efficiency"></a>
399           </div>
400         </li>
401         % endif
402
403         % if 'crylink' in recent_weapons:
404         <li>
405           <div class="dmg-weap">
406             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
407             <p><small>Crylink</small></p>
408             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','crylink')])}" title="Show crylink damage efficiency"></a>
409           </div>
410         </li>
411         % endif
412
413         % if 'hagar' in recent_weapons:
414         <li>
415           <div class="dmg-weap">
416             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
417             <p><small>Hagar</small></p>
418             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','hagar')])}" title="Show hagar damage efficiency"></a>
419           </div>
420         </li>
421         % endif
422
423         % if 'laser' in recent_weapons:
424         <li>
425           <div class="dmg-weap">
426             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
427             <p><small>Laser</small></p>
428             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','laser')])}" title="Show laser damage efficiency"></a>
429           </div>
430         </li>
431         % endif
432
433       </ul>
434     </div>
435
436   </div>
437 </div>
438 % endif
439
440
441 ##### RECENT GAMES (v2) ####
442 % if recent_games:
443 <div class="row">
444   <div class="span12">
445     <h3>Recent Games</h3>
446     <table class="table table-bordered table-condensed">
447       <thead>
448         <tr>
449            <th></th>
450            <th>Type</th>
451            <th>Server</th>
452            <th>Map</th>
453            <th>Result</th>
454            <th>Played</th>
455         </tr>
456       </thead>
457       <tbody>
458       % for (gamestat, game, server, map) in recent_games:
459         <tr>
460            <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>
461            <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>
462            <td>${server.name}</td>
463            <td>${map.name}</td>
464            <td>
465            % if gamestat.team != None:
466              % if gamestat.team == game.winner:
467              Win
468              % else:
469              Loss
470              % endif
471           % else:
472             % if gamestat.rank == 1:
473             Win
474             % else:
475             Loss (#${gamestat.rank})
476             % endif
477           % endif
478            </td>
479            <td>${game.fuzzy_date()}</td>
480         </tr>
481       % endfor
482       </tbody>
483     </table>
484     % if total_games > 10:
485     <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>
486     % endif
487   </div>
488 </div>
489 % endif
490 % endif