Skip to content

Commit 33eed36

Browse files
committed
Update reporting logic, add recovery pane
1 parent f416b2d commit 33eed36

File tree

3 files changed

+126
-62
lines changed

3 files changed

+126
-62
lines changed

index.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
<ol class="nav noselect">
4848
<li class="home"><i class="icon-habhub"></i></li>
4949
<li class="chasecar" style="display: none"><i class="icon-car"></i></li>
50+
<li class="recoveries"><i class="icon-habhub"></i></li>
5051
<li class="settings"><i class="icon-settings"></i></li>
5152
<li class="weather">
5253
<svg width="100%" height="100%" viewbox="0 0 35 40" xmlns="http://www.w3.org/2000/svg" version="1.1" version="1.1">
@@ -86,6 +87,15 @@ <h2>Embed tracker
8687
</p>
8788
</div>
8889
</div>
90+
<div id="recoveriesbox" style="display: none" class="flatpage">
91+
<div class="slimContainer">
92+
<h2>Recoveries</h2>
93+
<hr/>
94+
<p>Recovery reports can be added on the Chase-Car pane.</p>
95+
<hr/>
96+
<div id="recovery-list">No recent recoveries :-(</div>
97+
</div>
98+
</div>
8999
<div id="aboutbox" style="display: none" class="flatpage">
90100
<div class="slimContainer">
91101
<h2><i class="icon-question rfloat"></i>Welcome</h2>
@@ -313,7 +323,7 @@ <h2>Chase car mode</h2>
313323
<h3>Report Recovery</h3>
314324
<hr>
315325
<div class="row">
316-
<span>You can report a recovery here. Enter the serial number (no type code, e.g. 'S1234567'), tick recovered/not recovered, and add some notes. You must have location enabled, a callsign set above, and be within 50km of the radiosonde position.</span>
326+
<span>You can report a recovery here. Enter the serial number (no type code, e.g. 'S1234567'), tick recovered/not recovered, and add some notes. You must have location enabled, and a callsign set above. If the sonde is currently on the map, you must be located within 50km of it.</span>
317327
</div>
318328
<div class="row">
319329
<span><b>Serial</b></span>

js/chasecar.lib.js

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -51,61 +51,80 @@ ChaseCar.markRecovered = function(){
5151
// Get the serial number to be marked recovered
5252
_serial = $("#pr_serial").val().trim();
5353

54+
_notes = $("#pr_notes").val().trim();
55+
5456
// Check it exists.
5557
if(_serial.includes("chase") && _run_checks){
5658
$('#pr_last_report').text("Invalid sonde callsign.");
5759
return;
5860
}
59-
if(!vehicles.hasOwnProperty(_serial) && _run_checks){
60-
$('#pr_last_report').text("Invalid sonde callsign.");
61-
return;
62-
}
63-
64-
// Now get the last position of the sonde.
65-
_sonde = {
66-
'lat':vehicles[_serial].curr_position['gps_lat'],
67-
'lon':vehicles[_serial].curr_position['gps_lon'],
68-
'alt':0.0
69-
};
70-
71-
// Now get the chaser position.
72-
_chaser = {
73-
'lat': parseFloat($('#cc_lat').text()),
74-
'lon': parseFloat($('#cc_lon').text()),
75-
'alt': 0.0
76-
};
77-
78-
// Calculate the distance from the sonde
79-
_lookangles = calculate_lookangles(_chaser, _sonde);
80-
81-
if( (_lookangles.range > _range_limit ) && _run_checks){
82-
$('#pr_last_report').text("Outside distance limit.");
83-
return;
84-
}
8561

86-
// We are close enough!
8762
_callsign = $("#cc_callsign").val().trim();
8863
if (_callsign == "" || _callsign == undefined || _callsign.length == 0)
8964
{
90-
$('#pr_last_report').text("Enter a callsign!");
65+
$('#pr_last_report').text("Enter a Chase-Car callsign!");
9166
return;
9267
}
93-
94-
_notes = $("#pr_notes").val().trim();
9568

96-
if($("#sw_use_car_pos").hasClass('on')){
97-
_recov_lat = parseFloat($('#cc_lat').text());
98-
_recov_lon = parseFloat($('#cc_lon').text());
69+
_recov_lat = 0.0;
70+
_recov_lon = 0.0;
71+
_recov_alt = 0.0;
72+
73+
if(!vehicles.hasOwnProperty(_serial)){
74+
// Sonde is not on the map, so we need to use the chaser position.
75+
if($("#sw_use_car_pos").hasClass('on')){
76+
_recov_lat = parseFloat($('#cc_lat').text());
77+
_recov_lon = parseFloat($('#cc_lon').text());
78+
79+
if (_recov_lat == 0.0 && _recov_lon == 0.0){
80+
$('#pr_last_report').text("Location Reporting must be enabled!");
81+
return;
82+
}
83+
84+
} else {
85+
$('#pr_last_report').text("Sonde not on map, select 'Use Car Position' and try again.");
86+
return;
87+
}
88+
9989
} else {
90+
// Sonde is on the map, so run some additional checks.
10091
_recov_lat = vehicles[_serial].curr_position['gps_lat'];
10192
_recov_lon = vehicles[_serial].curr_position['gps_lon'];
93+
94+
// Now get the last position of the sonde.
95+
_sonde = {
96+
'lat':_recov_lat,
97+
'lon':_recov_lon,
98+
'alt':0.0
99+
};
100+
101+
// Now get the chaser position.
102+
_chaser = {
103+
'lat': parseFloat($('#cc_lat').text()),
104+
'lon': parseFloat($('#cc_lon').text()),
105+
'alt': 0.0
106+
};
107+
108+
// Calculate the distance from the sonde
109+
_lookangles = calculate_lookangles(_chaser, _sonde);
110+
111+
if( (_lookangles.range > _range_limit ) && _run_checks){
112+
$('#pr_last_report').text("Outside distance limit.");
113+
return;
114+
}
115+
116+
if($("#sw_use_car_pos").hasClass('on')){
117+
_recov_lat = parseFloat($('#cc_lat').text());
118+
_recov_lon = parseFloat($('#cc_lon').text());
119+
}
102120
}
103121

122+
104123
var _doc = {
105124
"serial": _serial,
106125
"lat": _recov_lat,
107126
"lon": _recov_lon,
108-
"alt": vehicles[_serial].curr_position['gps_alt'],
127+
"alt": 0.0,
109128
"recovered": $("#sw_recovery_ok").hasClass('on'),
110129
"recovered_by": _callsign,
111130
"description": _notes

js/tracker.js

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2591,35 +2591,28 @@ function refreshRecoveries() {
25912591
}
25922592
});
25932593

2594-
// Test data
2595-
// var test_recovery = [
2596-
// {
2597-
// "serial": "S1234567",
2598-
// "lat": -34.0,
2599-
// "lon": 138.0,
2600-
// "alt": 100.0,
2601-
// "datetime": "2021-06-04T12:00Z",
2602-
// "recovered": true,
2603-
// "recovered_by": "VK5QI",
2604-
// "description": "In a gigantic tree. <script>alert('xssfox');</script> But I had a pole."
2605-
// },
2606-
// {
2607-
// "serial": "S1112234",
2608-
// "lat": -34.1,
2609-
// "lon": 138.1,
2610-
// "alt": 100.0,
2611-
// "recovered": false,
2612-
// "recovered_by": "VK5FAIL",
2613-
// "datetime": "2021-06-04T13:00Z",
2614-
// "description": "In a gigantic tree. But I didn't have a pole. Yo listen up here's a story, about a little guy that lives in a blue world, and all day and all night and everything he sees is blue."
2615-
// },
2616-
// ];
2617-
// updateRecoveries(test_recovery);
2618-
// periodical_recoveries = setTimeout(refreshRecoveries, 60 * 1000);
2619-
26202594
}
26212595

26222596

2597+
function initRecoveryPane() {
2598+
2599+
$.ajax({
2600+
type: "GET",
2601+
url: recovered_sondes_url,
2602+
data: "",
2603+
dataType: "json",
2604+
success: function(response, textStatus) {
2605+
updateRecoveryPane(response);
2606+
},
2607+
error: function() {
2608+
},
2609+
complete: function(request, textStatus) {
2610+
periodical_recovery_pane = setTimeout(initRecoveryPane, 600 * 1000);
2611+
}
2612+
});
2613+
2614+
}
2615+
26232616
var ajax_predictions = null;
26242617

26252618
function refreshPredictions() {
@@ -2832,6 +2825,7 @@ function startAjax() {
28322825
//periodical_listeners = setInterval(refreshReceivers, 60 * 1000);
28332826
refreshReceivers();
28342827
refreshRecoveries();
2828+
initRecoveryPane();
28352829
}
28362830

28372831
function stopAjax() {
@@ -3004,7 +2998,6 @@ function updateRecoveryMarker(recovery) {
30042998
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(recovery.alt)) : parseInt(recovery.alt)).toLocaleString("us");
30052999
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
30063000

3007-
html += "<div><b>Altitude:&nbsp;</b>"+text_alt+"</div>";
30083001
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(recovery.datetime))+"</div>";
30093002
html += "<div><b>Reported by:&nbsp;</b>"+recovery.recovered_by+"</div>";
30103003
html += "<div><b>Notes:&nbsp;</b>"+$('<div>').text(recovery.description).html()+"</div>";
@@ -3080,6 +3073,48 @@ function updateRecoveryMarker(recovery) {
30803073

30813074
}
30823075

3076+
function updateRecoveryPane(r){
3077+
if(!r) return;
3078+
ls_recoveries = true;
3079+
3080+
html = "";
3081+
3082+
var i = 0, ii = r.length;
3083+
for(; i < ii; i++) {
3084+
var lat = parseFloat(r[i].lat);
3085+
var lon = parseFloat(r[i].lon);
3086+
var alt = parseFloat(r[i].alt);
3087+
3088+
if(lat < -90 || lat > 90 || lon < -180 || lon > 180) continue;
3089+
3090+
var r_index = $.inArray(r[i].serial, recovery_names);
3091+
3092+
if(r_index == -1) {
3093+
recovery_names.push(r[i].serial);
3094+
r_index = recovery_names.length - 1;
3095+
recoveries[r_index] = {marker: null, infobox: null};
3096+
}
3097+
3098+
html += "<div style='line-height:16px;position:relative;'>";
3099+
html += "<div><b><u>"+r[i].serial+(r[i].recovered ? " Recovered by " : " Not Recovered by ")+r[i].recovered_by+"</u></b></div>";
3100+
html += "<div style='margin-bottom:5px;'><b><i class='icon-location'></i>&nbsp;</b>"+roundNumber(lat, 5) + ',&nbsp;' + roundNumber(lon, 5)+"</div>";
3101+
3102+
var imp = offline.get('opt_imperial');
3103+
var text_alt = Number((imp) ? Math.floor(3.2808399 * parseInt(alt)) : parseInt(alt)).toLocaleString("us");
3104+
text_alt += "&nbsp;" + ((imp) ? 'ft':'m');
3105+
3106+
html += "<div><b>Time:&nbsp;</b>"+formatDate(stringToDateUTC(r[i].datetime))+"</div>";
3107+
html += "<div><b>Reported by:&nbsp;</b>"+r[i].recovered_by+"</div>";
3108+
html += "<div><b>Notes:&nbsp;</b>"+$('<div>').text(r[i].description).html()+"</div>";
3109+
html += "<div><b>Flight Path:&nbsp;</b><a href='https://sondehub.org/card/"+r[i].serial+"' target='_blank'>"+r[i].serial+"</a></div>";
3110+
html += "<hr style='margin:5px 0px'>";
3111+
html += "</div>";
3112+
}
3113+
3114+
$("#recovery-list").html(html);
3115+
3116+
}
3117+
30833118
function updatePredictions(r) {
30843119
if(!r) return;
30853120
ls_pred = true;

0 commit comments

Comments
 (0)