-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
275 lines (223 loc) · 9.88 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<html>
<head>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/css/bootstrap2/bootstrap-switch.min.css" />
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-switch/3.3.2/js/bootstrap-switch.min.js"></script>
<script>
var team1 = ['Highway11','Crust','xorrbit','Armand9x'];
var team2 = ['TundraKing','Thradis','FliegerFPV','Airmonos','QuadSquared','jkrueger188'];
iconTeam1 = "<img src='https://s3-us-west-2.amazonaws.com/slack-files2/avatars/2016-09-20/81758093536_03d6a2b9c7605d31529f_132.jpg' style='height:23px;margin-right:5px;'>";
iconTeam2 = "<img src='https://s3-us-west-2.amazonaws.com/slack-files2/avatars/2016-08-22/71669244807_1feba85d12ebdb8a3d70_132.jpg' style='height:23px;margin-right:5px;'>";
var maps = ["gates-of-hell-shipyard","gates-of-hell-city","gates-of-hell-woods","gates-of-hell","miami-lights","lapocalypse","bell-labs","bell-labs-project-noob","bell-labs-trinity-test","ohio-crash-site","ohio-crash-site-confirm-nor-deny","ohio-crash-site-restricted-area","detroit","drl-sandbox","drl-sandbox-straight-line"];
var numMaps = maps.length;
var mapsRetrieved = 0;
var allTables = "";
var pilots = {};
function getTime(value) {
time = 999999999 - parseInt(value)
return (time);
}
function msToTime(s) {
var ms = s % 1000;
s = (s - ms) / 1000;
var secs = s % 60;
s = (s - secs) / 60;
var mins = s % 60;
var hrs = (s - mins) / 60;
return mins + ':' + ("00" + secs).substr(-2,2) + '.' + ('00' + ms).slice(-3);
}
function setProgressBar(currentMap,totalMaps) {
$('#current-map-loading').html(currentMap);
$('#total-map-count').html(totalMaps);
$('#progress-bar').width(((currentMap/totalMaps) * 100) + "%");
if (currentMap == totalMaps)
{
$('#progress-bar').removeClass('active');
$('#progress-bar').removeClass('progress-bar-striped');
$('#progress-bar').html(" All " + totalMaps + " maps loaded");
}
}
function isOnTeam(nameToCheck,team) {
//check to see if this leaderboard entry is part of the local leaderboard
isTeamMember = false;
team.forEach(function (name) {
if (name == nameToCheck)
{
isTeamMember = true;
}
});
return isTeamMember;
}
function convertMapToTitle(map) {
//capitalize first letter of each word
title = map.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
//replace - with a space
title = title.replace(/-/g, ' ');
return title;
}
function generateTable(map) {
//generate a table for the specified map
tableHtml = "";
tableHtml += "<table class='table' style='max-width:500px'>";
tableHtml += "<tbody>";
tableHtml += "<tr>";
tableHtml += "<th data-toggle='collapse' data-target='#accordion-" + map + "' class='clickable' colspan=3 style='cursor:hand'>" + convertMapToTitle(map) + "<div id='" + map + "-total-entries' style='color:#777;font-size:12px;font-style:italic;float:right'></div></th></tr>";
tableHtml += "<tr><td colspan='3'>"
tableHtml += "<div style='margin-left:20px' id='accordion-" + map + "' class='collapse in'><table class='table table-condensed table-hover' style='max-width:500px'>";
tableHtml += "<thead><tr><th colspan=5><input type='checkbox' name='' class='toggleCheckbox' checked data-map='" + map + "' data-on-text='Local' data-off-text='Global'></th>";
tableHtml += "<tr><th>Local<br>Rank<th>Global<br>Rank<th>Top %<th>Name <th>Time</thead><tbody id='" + map + "'></tbody></table></div>";
tableHtml += "</td>"
tableHtml += "</tr>";
tableHtml += "<tr id='loading-" + map + "'><td colspan=5 style='text-align:center'><img src='https://i1.wp.com/cdnjs.cloudflare.com/ajax/libs/galleriffic/2.0.1/css/loader.gif'></td></tr>";
tableHtml += "</tbody>";
tableHtml += "</table>";
return tableHtml;
}
function generateCumulativeLeaderboard() {
//create array of all pilots that have completed all maps
cumulativePilots = [];
$.each(pilots, function( index, value ) {
//console.log( index + ": " + value["mapCount"] );
if (value.mapCount == numMaps)
{
cumulativePilots.push({name:index, cumulativeTime:value.cumulativeTime});
//console.log("adding to cumulative");
}
});
//sort array of pilots by time
cumulativePilots.sort(function(a, b) {
return parseFloat(a.cumulativeTime) - parseFloat(b.cumulativeTime);
});
teamMemberCount = 0;
count = 1;
entries = [];
//generate table row for each pilot
cumulativePilots.forEach( function (item)
{
if (isOnTeam(item.name,team1))
{
teamMemberCount += 1;
tableRow = "<tr class = 'success local-cumulative'><td>" + teamMemberCount;
tableRow += " <td> " + count + "<td>" + iconTeam1 + item.name + "<td>" + msToTime(item.cumulativeTime) + "</tr>";
}
else if (isOnTeam(item.name,team2))
{
teamMemberCount += 1;
tableRow = "<tr class = 'danger local-cumulative'><td>" + teamMemberCount;
tableRow += " <td> " + count + "<td>" + iconTeam2 + item.name + "<td>" + msToTime(item.cumulativeTime) + "</tr>";
}
else
{
tableRow = "<tr class='global-cumulative' style='display:none'><td> ";
tableRow += " <td> " + count + "<td>" + item.name + "<td>" + msToTime(item.cumulativeTime) + "</tr>";
}
entries.push( tableRow );
count += 1;
});
$('#cumulative').html(entries.join(""));
$('#cumulative-total-entries' ).html("" + cumulativePilots.length + " pilots");
}
$( document ).ready(function() {
//generate a table for each map in the array
maps.forEach(function (map) {
allTables += generateTable(map);
});
$('body').append(allTables);
$(".toggleCheckbox").bootstrapSwitch();
$(".toggleCheckbox").on('switchChange.bootstrapSwitch', function(event, state) {
$('.global-' + $(this).attr('data-map')).toggle();
});
setProgressBar(1,numMaps);
//retrieve leaderboard json for each map
maps.forEach(function (map) {
var teamMemberCount = 0;
var entries = [];
url = "http://winnipegfpv.club/drl/drlol.py?map=" + map;
$.getJSON( url, function( data )
{
obj = data;
totalEntries = obj["data"]["Leaderboard"].length;
obj["data"]["Leaderboard"].forEach( function (item)
{
rank = (parseInt(item.Position) + 1);
percentRank = parseInt(((1 - ((totalEntries - rank) / totalEntries)) * 100));
if (isOnTeam(item.DisplayName,team1))
{
teamMemberCount += 1;
tableRow = "<tr class = 'success local-" + map + "'><td>" + teamMemberCount;
tableRow += " <td> " + rank + "<td>" + percentRank + "%<td>" + iconTeam1 + item.DisplayName + "<td>" + msToTime(getTime(item.StatValue)) + "</tr>";
}
else if (isOnTeam(item.DisplayName,team2))
{
teamMemberCount += 1;
tableRow = "<tr class = 'danger local-" + map + "'><td>" + teamMemberCount;
tableRow += " <td> " + rank + "<td>" + percentRank + "%<td>" + iconTeam2 + item.DisplayName + "<td>" + msToTime(getTime(item.StatValue)) + "</tr>";
}
else
{
tableRow = "<tr class='global-" + map + "' style='display:none'><td> ";
tableRow += " <td> " + rank + "<td>" + percentRank + "%<td>" + item.DisplayName + "<td>" + msToTime(getTime(item.StatValue)) + "</tr>";
}
//add all times to cumulative leaderboard (except campaign and bud-light-2017)
if (map != 'campaign' && map != 'bud-light-2017-tryouts')
{
if (typeof(pilots[item.DisplayName]) === "undefined")
{
pilots[item.DisplayName] = {};
}
if (pilots[item.DisplayName]["mapCount"])
{
pilots[item.DisplayName]["mapCount"] += 1;
pilots[item.DisplayName]["cumulativeTime"] += getTime(item.StatValue);
}
else
{
pilots[item.DisplayName]["mapCount"] = 1;
pilots[item.DisplayName]["cumulativeTime"] = getTime(item.StatValue);
}
}
entries.push( tableRow );
});
//add the table rows to the table for this map
$('#' + map ).html(entries.join(""));
$('#' + map + '-total-entries' ).html("" + totalEntries + " pilots");
$('#loading-' + map ).hide();
//generate cumulative leaderboard once all map leaderboards have been generated
mapsRetrieved += 1;
setProgressBar(mapsRetrieved,numMaps);
if (mapsRetrieved == numMaps)
{
generateCumulativeLeaderboard();
}
});
});
});
</script>
<body>
<a href="http://thedroneracingleague.com/simulator/download/" target="_blank">Download DRL Simulator Here</a><br/><br/>
<div class="progress" style="max-width:500px">
<div id="progress-bar" class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="0"
aria-valuemin="0" aria-valuemax="100" style="width:1%">
Loading Map <span id='current-map-loading'></span> of <span id='total-map-count'></span>
</div>
</div>
<table class='table' style='max-width:500px'>
<tbody>
<tr>
<th data-toggle='collapse' data-target='#accordion-cumulative' class='clickable' colspan=3 style='cursor:hand'> Cumulative (all maps) <div id='cumulative-total-entries' style='color:#777;font-size:12px;font-style:italic;float:right'></div></th></tr>
<tr><td colspan='3'>
<div style='margin-left:20px' id='accordion-cumulative' class='collapse in'><table class='table table-condensed table-hover' style='max-width:500px'>
<thead><tr><th colspan=5><input type='checkbox' name='' class='toggleCheckbox' checked data-map='cumulative' data-on-text='Local' data-off-text='Global'></th>
<tr><th>Local<br>Rank<th>Global<br>Rank<th>Name <th>Time</thead><tbody id='cumulative'></tbody></table></div>
</td>
</tr>
</tbody>
</table>
</body>
</html>