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