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