]> de.git.xonotic.org Git - xonotic/xonstat.git/blob - xonstat/templates/player_info.mako
Add favorite map support.
[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           $('#acc-graph').bind("plothover", function (event, pos, item) {
81               if (item) {
82                   if (previousPoint != item.dataIndex) {
83                     previousPoint = item.dataIndex;
84
85                     $("#tooltip").remove();
86                     var x = item.datapoint[0].toFixed(2),
87                         y = item.datapoint[1].toFixed(2);
88
89                     showTooltip(item.pageX, item.pageY, y + "%");
90                   }
91               }
92               else {
93                   $("#tooltip").remove();
94                   previousPoint = null;
95               }
96           });
97
98           $('#dmg-graph').bind("plothover", function (event, pos, item) {
99               if (item) {
100                   if (previousPoint != item.dataIndex) {
101                     previousPoint = item.dataIndex;
102
103                     $("#tooltip").remove();
104                     var x = item.datapoint[0].toFixed(2),
105                         y = item.datapoint[1].toFixed(2);
106
107                     showTooltip(item.pageX, item.pageY, y);
108                   }
109               }
110               else {
111                   $("#tooltip").remove();
112                   previousPoint = null;
113               }
114           });
115
116           // bind click events to the weapon images
117           $(".acc-weap").click(function () {
118               var dataurl = $(this).find('a').attr('href');
119
120               $('.accuracy-nav').find('.weapon-active').removeClass('weapon-active');
121               $(this).addClass('weapon-active');
122
123               $.ajax({
124                   url: dataurl,
125                   method: 'GET',
126                   dataType: 'json',
127                   success: plot_acc_graph
128               });
129           });
130
131           $(".dmg-weap").click(function () {
132               var dataurl = $(this).find('a').attr('href');
133
134               $('.damage-nav').find('.weapon-active').removeClass('weapon-active');
135               $(this).addClass('weapon-active');
136
137               $.ajax({
138                   url: dataurl,
139                   method: 'GET',
140                   dataType: 'json',
141                   success: plot_dmg_graph
142               });
143           });
144
145           // populate the graphs with the default weapons
146           $.ajax({
147               url: '${request.route_url("player_accuracy", id=player.player_id)}',
148               method: 'GET',
149               dataType: 'json',
150               success: plot_acc_graph
151           });
152
153           $.ajax({
154               url: '${request.route_url("player_damage", id=player.player_id)}',
155               method: 'GET',
156               dataType: 'json',
157               success: plot_dmg_graph
158           });
159       })
160       </script>
161     % endif
162 </%block>
163
164 <%block name="title">
165 Player Information
166 </%block>
167
168
169 % if player is None:
170 <h2>This player is so good we couldn't find him!</h2>
171 <p>Seriously though, he probably doesn't exist...just a figment of your imagination. Carry on then!</p>
172
173 % else:
174 <div class="row">
175   <div class="span12">
176     <h2>${player.nick_html_colors()|n}</h2>
177   </div>
178 </div>
179
180 <div class="row">
181   <div class="span6">
182     <p>
183       Member Since: <small>${player.create_dt.strftime('%m/%d/%Y at %I:%M %p')} </small><br />
184
185       Last Seen: <small>${recent_games[0][1].fuzzy_date()} </small><br />
186
187       Playing Time: <small>${total_stats['alivetime']} </small><br />
188
189       <% games_breakdown_str = ', '.join(["{0} {1}".format(ng, gt) for (gt, ng) in games_breakdown]) %>
190       Games Played: <small>${total_games} (${games_breakdown_str})</small><br />
191
192       % if fav_map is not None:
193       Favorite Map: <small><a href="${request.route_url('map_info', id=fav_map.map_id)}" title="view map info">${fav_map.name}</a></small><br />
194       % endif
195     </p>
196   </div>
197   <div class="span6">
198     <p>
199        % if total_games > 0 and total_stats['wins'] is not None:
200        Win Percentage: <small>${round(float(total_stats['wins'])/total_games * 100, 2)}% (${total_stats['wins']} wins, ${total_games - total_stats['wins']} losses) </small><br />
201        % endif
202
203        % if total_stats['kills'] > 0 and total_stats['deaths'] > 0:
204        Kill Ratio: <small>${round(float(total_stats['kills'])/total_stats['deaths'], 3)} (${total_stats['kills']} kills, ${total_stats['deaths']} deaths) </small><br />
205        % endif
206
207        % if elos_display is not None and len(elos_display) > 0:
208        Elo:
209           <small>${', '.join(elos_display)} </small>
210           <br />
211           %if '*' in ', '.join(elos_display):
212               <small><i>*preliminary Elo</i></small><br />
213           %endif
214       % endif
215     </p>
216   </div>
217 </div>
218
219
220 % 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:
221 <div class="row">
222   <div class="span10">
223     <h3>Accuracy</h3>
224     <div id="acc-graph" class="flot" style="width:900px; height:200px;">
225     </div>
226
227     <div class="weapon-nav accuracy-nav">
228       <ul>
229         % if 'nex' in recent_weapons:
230         <li>
231           <div class="acc-weap weapon-active">
232             <img src="${request.static_url("xonstat:static/images/nex.png")}" />
233             <p><small>Nex</small></p>
234             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'nex'})}" title="Show nex accuracy"></a>
235           </div>
236         </li>
237         % endif
238
239         % if 'rifle' in recent_weapons:
240         <li>
241           <div class="acc-weap">
242             <img src="${request.static_url("xonstat:static/images/rifle.png")}" />
243             <p><small>Rifle</small></p>
244             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'rifle'})}" title="Show rifle accuracy"></a>
245           </div>
246         </li>
247         % endif
248
249         % if 'minstanex' in recent_weapons:
250         <li>
251           <div class="acc-weap">
252             <img src="${request.static_url("xonstat:static/images/minstanex.png")}" />
253             <p><small>Minstanex</small></p>
254             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'minstanex'})}" title="Show minstanex accuracy"></a>
255           </div>
256         </li>
257         % endif
258
259         % if 'uzi' in recent_weapons:
260         <li>
261           <div class="acc-weap">
262             <img src="${request.static_url("xonstat:static/images/uzi.png")}" />
263             <p><small>Uzi</small></p>
264             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'uzi'})}" title="Show uzi accuracy"></a>
265           </div>
266         </li>
267         % endif
268
269         % if 'shotgun' in recent_weapons:
270         <li>
271           <div class="acc-weap">
272             <img src="${request.static_url("xonstat:static/images/shotgun.png")}" />
273             <p><small>Shotgun</small></p>
274             <a href="${request.route_url('player_accuracy', id=player.player_id, _query={'weapon':'shotgun'})}" title="Show shotgun accuracy"></a>
275           </div>
276         </li>
277         % endif
278       </ul>
279     </div>
280
281   </div>
282 </div>
283 % endif
284
285
286 % 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:
287 <div class="row">
288   <div class="span10">
289     <h3>Damage Efficiency</h3>
290     <div id="dmg-graph" class="flot" style="width:900px; height:200px;">
291     </div>
292
293     <div class="weapon-nav damage-nav">
294       <ul>
295         % if 'rocketlauncher' in recent_weapons:
296         <li>
297           <div class="dmg-weap weapon-active">
298             <img src="${request.static_url("xonstat:static/images/rocketlauncher.png")}" />
299             <p><small>Rocket</small></p>
300             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'rocketlauncher'})}" title="Show rocket launcher efficiency"></a>
301           </div>
302         </li>
303         % endif
304
305         % if 'grenadelauncher' in recent_weapons:
306         <li>
307           <div class="dmg-weap">
308             <img src="${request.static_url("xonstat:static/images/grenadelauncher.png")}" />
309             <p><small>Mortar</small></p>
310             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'grenadelauncher'})}" title="Show mortar damage efficiency"></a>
311           </div>
312         </li>
313         % endif
314
315         % if 'electro' in recent_weapons:
316         <li>
317           <div class="dmg-weap">
318             <img src="${request.static_url("xonstat:static/images/electro.png")}" />
319             <p><small>Electro</small></p>
320             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'electro'})}" title="Show electro damage efficiency"></a>
321           </div>
322         </li>
323         % endif
324
325         % if 'crylink' in recent_weapons:
326         <li>
327           <div class="dmg-weap">
328             <img src="${request.static_url("xonstat:static/images/crylink.png")}" />
329             <p><small>Crylink</small></p>
330             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'crylink'})}" title="Show crylink damage efficiency"></a>
331           </div>
332         </li>
333         % endif
334
335         % if 'hagar' in recent_weapons:
336         <li>
337           <div class="dmg-weap">
338             <img src="${request.static_url("xonstat:static/images/hagar.png")}" />
339             <p><small>Hagar</small></p>
340             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'hagar'})}" title="Show hagar damage efficiency"></a>
341           </div>
342         </li>
343         % endif
344
345         % if 'laser' in recent_weapons:
346         <li>
347           <div class="dmg-weap">
348             <img src="${request.static_url("xonstat:static/images/laser.png")}" />
349             <p><small>Laser</small></p>
350             <a href="${request.route_url('player_damage', id=player.player_id, _query={'weapon':'laser'})}" title="Show laser damage efficiency"></a>
351           </div>
352         </li>
353         % endif
354
355       </ul>
356     </div>
357
358   </div>
359 </div>
360 % endif
361
362
363 ##### RECENT GAMES (v2) ####
364 % if recent_games:
365 <div class="row">
366   <div class="span12">
367     <h3>Recent Games</h3>
368     <table class="table table-bordered table-condensed">
369       <thead>
370         <tr>
371            <th></th>
372            <th>Type</th>
373            <th>Server</th>
374            <th>Map</th>
375            <th>Result</th>
376            <th>Played</th>
377         </tr>
378       </thead>
379       <tbody>
380       % for (gamestat, game, server, map) in recent_games:
381         <tr>
382            <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>
383            <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>
384            <td>${server.name}</td>
385            <td>${map.name}</td>
386            <td>
387            % if gamestat.team != None:
388              % if gamestat.team == game.winner:
389              Win
390              % else:
391              Loss
392              % endif
393           % else:
394             % if gamestat.rank == 1:
395             Win
396             % else:
397             Loss (#${gamestat.rank})
398             % endif
399           % endif
400            </td>
401            <td>${game.fuzzy_date()}</td>
402         </tr>
403       % endfor
404       </tbody>
405     </table>
406     % if total_games > 10:
407     <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>
408     % endif
409   </div>
410 </div>
411 % endif
412 % endif