]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/templates/player_info.mako
Updated "favorite map" to show more than one map (three by default); and updated...
[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']} </small><br />
193
194       <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %>
195       Games Played: <small>${total_games} (${games_breakdown_str})</small><br />
196
197       % if fav_map is not None:
198       Favorite Maps: <small>
199       <% map_list = fav_map[:3] %>
200       % for mapinfo in map_list:
201           % if mapinfo != map_list[-1]:
202               <% delim = ", " %>
203           % else:
204               <% delim = "" %>
205           % endif
206           <a href="${request.route_url('map_info', id=mapinfo['id'])}" title="view map info">${mapinfo['name']}</a>${delim}
207       % endfor
208       </small><br />
209       % endif
210
211       % if fav_weapon is not None:
212       Favorite Weapons: <small>
213       <% wpn_list = fav_weapon[:2] %>
214       % for wpninfo in wpn_list:
215           % if wpninfo != wpn_list[-1]:
216               <% delim = ", " %>
217           % else:
218               <% delim = "" %>
219           % endif
220           ${wpninfo['name']}${delim}
221       % endfor
222       </small><br />
223       % endif
224     </p>
225   </div>
226   <div class="span6">
227     <p>
228        % if total_games > 0 and total_stats['wins'] is not None:
229        Win Percentage: <small>${round(float(total_stats['wins'])/total_games * 100, 2)}% (${total_stats['wins']} wins, ${total_games - total_stats['wins']} losses) </small><br />
230        % endif
231
232        % if total_stats['kills'] > 0 and total_stats['deaths'] > 0:
233        Kill Ratio: <small>${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths) </small><br />
234        % endif
235
236        % if elos_display is not None and len(elos_display) > 0:
237        Elo:
238           <small>${', '.join(elos_display)} </small>
239           <br />
240           %if '*' in ', '.join(elos_display):
241               <small><i>*preliminary Elo</i></small><br />
242           %endif
243       % endif
244
245       % if ranks_display != '':
246       Ranks: <small>${ranks_display}</small><br />
247       % endif
248     </p>
249   </div>
250 </div>
251
252
253 % 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:
254 <div class="row">
255   <div class="span10">
256     <h3>Accuracy</h3>
257     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
258     </div>
259
260     <div class="weapon-nav accuracy-nav">
261       <ul>
262         % if 'nex' in recent_weapons:
263         <li>
264           <div class="acc-weap weapon-active">
265             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
266             <p><small>Nex</small></p>
267             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','nex')])}" title="Show nex accuracy"></a>
268           </div>
269         </li>
270         % endif
271
272         % if 'rifle' in recent_weapons:
273         <li>
274           <div class="acc-weap">
275             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
276             <p><small>Rifle</small></p>
277             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','rifle')])}" title="Show rifle accuracy"></a>
278           </div>
279         </li>
280         % endif
281
282         % if 'minstanex' in recent_weapons:
283         <li>
284           <div class="acc-weap">
285             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
286             <p><small>Minstanex</small></p>
287             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','minstanex')])}" title="Show minstanex accuracy"></a>
288           </div>
289         </li>
290         % endif
291
292         % if 'uzi' in recent_weapons:
293         <li>
294           <div class="acc-weap">
295             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
296             <p><small>Uzi</small></p>
297             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','uzi')])}" title="Show uzi accuracy"></a>
298           </div>
299         </li>
300         % endif
301
302         % if 'shotgun' in recent_weapons:
303         <li>
304           <div class="acc-weap">
305             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
306             <p><small>Shotgun</small></p>
307             <a href="${request.route_url('player_accuracy', id=player.player_id, _query=[('weapon','shotgun')])}" title="Show shotgun accuracy"></a>
308           </div>
309         </li>
310         % endif
311       </ul>
312     </div>
313
314   </div>
315 </div>
316 % endif
317
318
319 % 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:
320 <div class="row">
321   <div class="span10">
322     <h3>Damage Efficiency</h3>
323     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
324     </div>
325
326     <div class="weapon-nav damage-nav">
327       <ul>
328         % if 'rocketlauncher' in recent_weapons:
329         <li>
330           <div class="dmg-weap weapon-active">
331             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
332             <p><small>Rocket</small></p>
333             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','rocketlauncher')])}" title="Show rocket launcher efficiency"></a>
334           </div>
335         </li>
336         % endif
337
338         % if 'grenadelauncher' in recent_weapons:
339         <li>
340           <div class="dmg-weap">
341             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
342             <p><small>Mortar</small></p>
343             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','grenadelauncher')])}" title="Show mortar damage efficiency"></a>
344           </div>
345         </li>
346         % endif
347
348         % if 'electro' in recent_weapons:
349         <li>
350           <div class="dmg-weap">
351             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
352             <p><small>Electro</small></p>
353             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','electro')])}" title="Show electro damage efficiency"></a>
354           </div>
355         </li>
356         % endif
357
358         % if 'crylink' in recent_weapons:
359         <li>
360           <div class="dmg-weap">
361             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
362             <p><small>Crylink</small></p>
363             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','crylink')])}" title="Show crylink damage efficiency"></a>
364           </div>
365         </li>
366         % endif
367
368         % if 'hagar' in recent_weapons:
369         <li>
370           <div class="dmg-weap">
371             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
372             <p><small>Hagar</small></p>
373             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','hagar')])}" title="Show hagar damage efficiency"></a>
374           </div>
375         </li>
376         % endif
377
378         % if 'laser' in recent_weapons:
379         <li>
380           <div class="dmg-weap">
381             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
382             <p><small>Laser</small></p>
383             <a href="${request.route_url('player_damage', id=player.player_id, _query=[('weapon','laser')])}" title="Show laser damage efficiency"></a>
384           </div>
385         </li>
386         % endif
387
388       </ul>
389     </div>
390
391   </div>
392 </div>
393 % endif
394
395
396 ##### RECENT GAMES (v2) ####
397 % if recent_games:
398 <div class="row">
399   <div class="span12">
400     <h3>Recent Games</h3>
401     <table class="table table-bordered table-condensed">
402       <thead>
403         <tr>
404            <th></th>
405            <th>Type</th>
406            <th>Server</th>
407            <th>Map</th>
408            <th>Result</th>
409            <th>Played</th>
410         </tr>
411       </thead>
412       <tbody>
413       % for (gamestat, game, server, map) in recent_games:
414         <tr>
415            <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>
416            <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>
417            <td>${server.name}</td>
418            <td>${map.name}</td>
419            <td>
420            % if gamestat.team != None:
421              % if gamestat.team == game.winner:
422              Win
423              % else:
424              Loss
425              % endif
426           % else:
427             % if gamestat.rank == 1:
428             Win
429             % else:
430             Loss (#${gamestat.rank})
431             % endif
432           % endif
433            </td>
434            <td>${game.fuzzy_date()}</td>
435         </tr>
436       % endfor
437       </tbody>
438     </table>
439     % if total_games > 10:
440     <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>
441     % endif
442   </div>
443 </div>
444 % endif
445 % endif