Skip to content

Commit 3299674

Browse files
authored
Merge pull request #97 from LukePrior/testing
leaderboard
2 parents f7fc7f7 + a8e5744 commit 3299674

File tree

2 files changed

+75
-25
lines changed

2 files changed

+75
-25
lines changed

index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
</header>
5959

6060
<div id="recoveriesbox" style="display: none" class="flatpage">
61+
<div class="slimContainer">
62+
<h2>Leaderboard</h2>
63+
<hr/>
64+
<p>This is a record of who has recovered the most sondes.</p>
65+
<hr/>
66+
<div id="leaderboard-list">No leaderboard data :-(</div>
67+
</div>
6168
<div class="slimContainer">
6269
<h2>Recoveries</h2>
6370
<hr/>

js/tracker.js

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,13 +3282,15 @@ function refreshRecoveries() {
32823282
$.ajax({
32833283
type: "GET",
32843284
url: recovered_sondes_url,
3285-
data: "",
3285+
data: "last=0",
32863286
dataType: "json",
32873287
success: function(response, textStatus) {
32883288
if(offline.get('opt_hide_recoveries')) {
32893289
updateRecoveryPane(response);
3290+
updateLeaderboardPane(response);
32903291
} else {
32913292
updateRecoveryPane(response);
3293+
updateLeaderboardPane(response);
32923294
updateRecoveries(response);
32933295
}
32943296
},
@@ -3661,42 +3663,83 @@ function updateRecoveryPane(r){
36613663

36623664
html = "";
36633665

3666+
var dateNow = Date.now();
3667+
36643668
var i = 0, ii = r.length;
36653669
for(; i < ii; i++) {
3666-
var lat = parseFloat(r[i].lat);
3667-
var lon = parseFloat(r[i].lon);
3668-
var alt = parseFloat(r[i].alt);
3670+
var date = Date.parse(r[i].datetime);
3671+
if (((dateNow - date) / 86400000) < 3) {
3672+
var lat = parseFloat(r[i].lat);
3673+
var lon = parseFloat(r[i].lon);
3674+
var alt = parseFloat(r[i].alt);
36693675

3670-
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
3676+
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
36713677

3672-
var r_index = $.inArray(r[i].serial, recovery_names);
3678+
var r_index = $.inArray(r[i].serial, recovery_names);
36733679

3674-
if(r_index == -1) {
3675-
recovery_names.push(r[i].serial);
3676-
r_index = recovery_names.length - 1;
3677-
recoveries[r_index] = {marker: null, infobox: null};
3678-
}
3680+
if(r_index == -1) {
3681+
recovery_names.push(r[i].serial);
3682+
r_index = recovery_names.length - 1;
3683+
recoveries[r_index] = {marker: null, infobox: null};
3684+
}
36793685

3680-
html += "<div style='line-height:16px;position:relative;'>";
3681-
html += "<div><b><u>"+r[i].serial+(r[i].recovered ? " Recovered by " : " Not Recovered by ")+r[i].recovered_by+"</u></b></div>";
3682-
html += "<div style='margin-bottom:5px;'><b><button style='margin-bottom:0px;' onclick='panToRecovery(\"" + r[i].serial + "\")'><i class='icon-location'></i></button>&nbsp;</b>"+roundNumber(lat, 5) + ',&nbsp;' + roundNumber(lon, 5)+"</div>";
3683-
3684-
var imp = offline.get('opt_imperial');
3685-
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(alt)) : parseInt(alt)).toLocaleString("us");
3686-
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
3687-
3688-
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(r[i].datetime))+"</div>";
3689-
html += "<div><b>Reported by:&nbsp;</b>"+r[i].recovered_by+"</div>";
3690-
html += "<div><b>Notes:&nbsp;</b>"+$('<div>').text(r[i].description).html()+"</div>";
3691-
html += "<div><b>Flight Path:&nbsp;</b><a href='https://sondehub.org/card/"+r[i].serial+"' target='_blank' rel='noopener'>"+r[i].serial+"</a></div>";
3692-
html += "<hr style='margin:5px 0px'>";
3693-
html += "</div>";
3686+
html += "<div style='line-height:16px;position:relative;'>";
3687+
html += "<div><b><u>"+r[i].serial+(r[i].recovered ? " Recovered by " : " Not Recovered by ")+r[i].recovered_by+"</u></b></div>";
3688+
html += "<div style='margin-bottom:5px;'><b><button style='margin-bottom:0px;' onclick='panToRecovery(\"" + r[i].serial + "\")'><i class='icon-location'></i></button>&nbsp;</b>"+roundNumber(lat, 5) + ',&nbsp;' + roundNumber(lon, 5)+"</div>";
3689+
3690+
var imp = offline.get('opt_imperial');
3691+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(alt)) : parseInt(alt)).toLocaleString("us");
3692+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
3693+
3694+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(r[i].datetime))+"</div>";
3695+
html += "<div><b>Reported by:&nbsp;</b>"+r[i].recovered_by+"</div>";
3696+
html += "<div><b>Notes:&nbsp;</b>"+$('<div>').text(r[i].description).html()+"</div>";
3697+
html += "<div><b>Flight Path:&nbsp;</b><a href='https://sondehub.org/card/"+r[i].serial+"' target='_blank' rel='noopener'>"+r[i].serial+"</a></div>";
3698+
html += "<hr style='margin:5px 0px'>";
3699+
html += "</div>";
3700+
}
36943701
}
36953702

36963703
$("#recovery-list").html(html);
36973704

36983705
}
36993706

3707+
function updateLeaderboardPane(r){
3708+
if(!r) return;
3709+
3710+
html = "";
3711+
var leaderboard = [];
3712+
3713+
var i = 0, ii = r.length;
3714+
for(; i < ii; i++) {
3715+
if (r[i].recovered) {
3716+
if (leaderboard.hasOwnProperty(r[i].recovered_by)) {
3717+
leaderboard[r[i].recovered_by] = leaderboard[r[i].recovered_by] + 1;
3718+
} else {
3719+
leaderboard[r[i].recovered_by] = 1
3720+
}
3721+
}
3722+
}
3723+
3724+
var sortable = [];
3725+
for (var score in leaderboard) {
3726+
sortable.push([score, leaderboard[score]]);
3727+
}
3728+
3729+
sortable.sort(function(a, b) {
3730+
return b[1] - a[1];
3731+
});
3732+
3733+
var list = sortable.slice(0,5);
3734+
3735+
for (var i = 0; i < list.length; i++) {
3736+
html += "<div><b>" + (parseInt(i)+1) + ". </b>" + list[i][0] + " - " + list[i][1] + "</div>";
3737+
}
3738+
3739+
$("#leaderboard-list").html(html);
3740+
3741+
}
3742+
37003743
function updatePredictions(r) {
37013744
if(!r) return;
37023745
ls_pred = true;

0 commit comments

Comments
 (0)