Skip to content

Commit 4b0a5c6

Browse files
authored
Merge pull request #104 from projecthorus/testing
Update stations
2 parents 1d95050 + d4dff05 commit 4b0a5c6

File tree

3 files changed

+824
-754
lines changed

3 files changed

+824
-754
lines changed

index.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ <h2>Recoveries</h2>
6363
<hr/>
6464
<p>Recovery reports can be added on the Chase-Car pane.</p>
6565
<hr/>
66-
<div id="recovery-list">No recent recoveries :-(</div>
66+
<div id="recovery-list"><img style="width:90px;height:30px;display:block;margin:auto;" src="img/hab-spinner.gif"/><br></div>
67+
</div>
68+
<div class="slimContainer">
69+
<h2>Statistics</h2>
70+
<hr/>
71+
<div id="leaderboard-list"><img style="width:90px;height:30px;display:block;margin:auto;" src="img/hab-spinner.gif"/><br></div>
6772
</div>
6873
</div>
6974
<div id="aboutbox" style="display: none" class="flatpage">

js/tracker.js

Lines changed: 114 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3282,17 +3282,21 @@ 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
},
32953297
error: function() {
3298+
updateRecoveryPane([]);
3299+
updateLeaderboardPane([]);
32963300
},
32973301
complete: function(request, textStatus) {
32983302
periodical_recoveries = setTimeout(refreshRecoveries, 600 * 1000);
@@ -3603,34 +3607,40 @@ function updateRecoveryMarker(recovery) {
36033607

36043608
if(!r) return;
36053609
ls_recoveries = true;
3610+
3611+
var dateNow = Date.now();
3612+
36063613

36073614
var i = 0, ii = r.length;
36083615
for(; i < ii; i++) {
3609-
var lat = parseFloat(r[i].lat);
3610-
var lon = parseFloat(r[i].lon);
3611-
3612-
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
3613-
3614-
var r_index = $.inArray(r[i].serial, recovery_names);
3615-
3616-
if(r_index == -1) {
3617-
recovery_names.push(r[i].serial);
3618-
r_index = recovery_names.length - 1;
3619-
recoveries[r_index] = {marker: null, infobox: null};
3620-
}
3621-
3622-
var recovery = recoveries[r_index];
3623-
recovery.serial = r[i].serial;
3624-
recovery.lat = lat;
3625-
recovery.lon = lon;
3626-
recovery.recovered_by = r[i].recovered_by;
3627-
recovery.alt = parseFloat(r[i].alt);
3628-
recovery.recovered = r[i].recovered;
3629-
recovery.description = r[i].description;
3630-
recovery.datetime = r[i].datetime;
3631-
recovery.fresh = true;
3632-
3633-
updateRecoveryMarker(recovery);
3616+
var date = Date.parse(r[i].datetime);
3617+
if (((dateNow - date) / 86400000) < 3) {
3618+
var lat = parseFloat(r[i].lat);
3619+
var lon = parseFloat(r[i].lon);
3620+
3621+
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
3622+
3623+
var r_index = $.inArray(r[i].serial, recovery_names);
3624+
3625+
if(r_index == -1) {
3626+
recovery_names.push(r[i].serial);
3627+
r_index = recovery_names.length - 1;
3628+
recoveries[r_index] = {marker: null, infobox: null};
3629+
}
3630+
3631+
var recovery = recoveries[r_index];
3632+
recovery.serial = r[i].serial;
3633+
recovery.lat = lat;
3634+
recovery.lon = lon;
3635+
recovery.recovered_by = r[i].recovered_by;
3636+
recovery.alt = parseFloat(r[i].alt);
3637+
recovery.recovered = r[i].recovered;
3638+
recovery.description = r[i].description;
3639+
recovery.datetime = r[i].datetime;
3640+
recovery.fresh = true;
3641+
3642+
updateRecoveryMarker(recovery);
3643+
}
36343644
}
36353645

36363646
// clear old recovery markers
@@ -3661,42 +3671,97 @@ function updateRecoveryPane(r){
36613671

36623672
html = "";
36633673

3674+
var dateNow = Date.now();
3675+
36643676
var i = 0, ii = r.length;
36653677
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);
3678+
var date = Date.parse(r[i].datetime);
3679+
if (((dateNow - date) / 86400000) < 3) {
3680+
var lat = parseFloat(r[i].lat);
3681+
var lon = parseFloat(r[i].lon);
3682+
var alt = parseFloat(r[i].alt);
36693683

3670-
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
3684+
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
36713685

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

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};
3688+
if(r_index == -1) {
3689+
recovery_names.push(r[i].serial);
3690+
r_index = recovery_names.length - 1;
3691+
recoveries[r_index] = {marker: null, infobox: null};
3692+
}
3693+
3694+
html += "<div style='line-height:16px;position:relative;'>";
3695+
html += "<div><b><u>"+r[i].serial+(r[i].recovered ? " Recovered by " : " Not Recovered by ")+r[i].recovered_by+"</u></b></div>";
3696+
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>";
3697+
3698+
var imp = offline.get('opt_imperial');
3699+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(alt)) : parseInt(alt)).toLocaleString("us");
3700+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
3701+
3702+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(r[i].datetime))+"</div>";
3703+
html += "<div><b>Reported by:&nbsp;</b>"+r[i].recovered_by+"</div>";
3704+
html += "<div><b>Notes:&nbsp;</b>"+$('<div>').text(r[i].description).html()+"</div>";
3705+
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>";
3706+
html += "<hr style='margin:5px 0px'>";
3707+
html += "</div>";
36783708
}
3709+
}
36793710

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>";
3711+
if (html == "") {
3712+
html = "<div>No recent recoveries :-(</div>"
36943713
}
36953714

36963715
$("#recovery-list").html(html);
36973716

36983717
}
36993718

3719+
function updateLeaderboardPane(r){
3720+
if(!r) return;
3721+
3722+
html = "";
3723+
var leaderboard = {};
3724+
var recovered = 0;
3725+
3726+
var i = 0, ii = r.length;
3727+
for(; i < ii; i++) {
3728+
if (r[i].recovered) {
3729+
recovered+=1;
3730+
if (leaderboard.hasOwnProperty(r[i].recovered_by)) {
3731+
leaderboard[r[i].recovered_by] = leaderboard[r[i].recovered_by] + 1;
3732+
} else {
3733+
leaderboard[r[i].recovered_by] = 1
3734+
}
3735+
}
3736+
}
3737+
3738+
var sortable = [];
3739+
for (var score in leaderboard) {
3740+
sortable.push([score, leaderboard[score]]);
3741+
}
3742+
3743+
sortable.sort(function(a, b) {
3744+
return b[1] - a[1];
3745+
});
3746+
3747+
var list = sortable.slice(0,5);
3748+
3749+
html += "<div><b>Total sondes recovered: " + recovered + "/" + r.length + "</b></div>";
3750+
html += "<div><b>Total hunters: " + sortable.length + "</b></div><br>";
3751+
html += "<div><b>Leaderboard: </b></div>";
3752+
3753+
for (var i = 0; i < list.length; i++) {
3754+
html += "<div><b>" + (parseInt(i)+1) + ". </b>" + list[i][0] + " - " + list[i][1] + "</div>";
3755+
}
3756+
3757+
if (r.length == 0) {
3758+
html = "<div>No recent recoveries :-(</div>"
3759+
}
3760+
3761+
$("#leaderboard-list").html(html);
3762+
3763+
}
3764+
37003765
function updatePredictions(r) {
37013766
if(!r) return;
37023767
ls_pred = true;

0 commit comments

Comments
 (0)