Skip to content

Commit f5378f9

Browse files
authored
Merge pull request #296 from projecthorus/testing
Predictions via websockets
2 parents fd5e284 + f680da7 commit f5378f9

File tree

2 files changed

+114
-44
lines changed

2 files changed

+114
-44
lines changed

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ <h2><i class="icon-car rfloat"></i>Chase Mode</h2>
295295
<span class="r"><input type="text" id="cc_callsign" style="width: 140px;"/></span>
296296
</div>
297297
<div class="row">
298-
<span><b>Notice: If you enable this, your location will be uploaded to SondeHub; making it publicly visible on the map.</b></span>
298+
<span><b>Notice: If you enable this, your location will be uploaded to SondeHub; making it publicly visible on the map for up to 12 hours.</b></span>
299299
</div>
300300
<hr>
301301
<div class="row">

js/tracker.js

Lines changed: 113 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var focusID = 0;
5252

5353
var receiverCanvas = null;
5454

55-
var sondePrefix = ["RS92", "RS92-SGP", "RS92-NGP", "RS41", "RS41-SG", "RS41-SGP", "RS41-SGM", "DFM", "DFM06", "DFM09", "DFM17", "M10", "M20", "iMet-1", "iMet-4", "iMet-54", "LMS6", "LMS6-400", "LMS6-1680", "iMS-100", "MRZ", "MTS01", "chase"];
55+
var sondePrefix = ["RS92", "RS92-SGP", "RS92-NGP", "RS41", "RS41-SG", "RS41-SGP", "RS41-SGM", "DFM", "DFM06", "DFM09", "DFM17", "M10", "M20", "iMet-1", "iMet-4", "iMet-54", "LMS6", "LMS6-400", "LMS6-1680", "iMS-100", "MRZ", "MTS01", "WxR-301D", "chase"];
5656
var sondeCodes = {
5757
"07":"iMet-1", "11":"LMS6-403", "13":"RS92", "14":"RS92", "17":"DFM-09", "18":"DFM-06", "19":"MRZ-N1", "22":"RS-11G", "23":"RS41", "24":"RS41", "34":"iMet-4", "35":"iMS-100", "38":"WxR-301D", "41":"RS41", "42":"RS41", "52":"RS92-NGP",
5858
"54":"DFM-17", "62":"MRZ-3MK", "63":"M20", "65":"MTS01", "77":"M10", "82":"LMS6-1680", "84":"iMet-54"
@@ -736,12 +736,16 @@ function sub_to_nearby_sondes(){
736736
// If zoomed in then we sub to specific sondes
737737
for (let vehicle in vehicles){
738738
let topic = "sondes/"+vehicle;
739+
let prediction_topic = "prediction/"+vehicle;
740+
let reverse_topic = "reverse-prediction/"+vehicle;
739741
inside_bounds = bounds.contains(vehicles[vehicle].marker._latlng)
740742
if (inside_bounds){
741743
if (!clientTopic.includes(topic)){
742744
if (sub_logging) console.log("Subbing to " + topic)
743745
if (client.isConnected()) {
744746
client.subscribe(topic);
747+
client.subscribe(prediction_topic);
748+
client.subscribe(reverse_topic);
745749
}
746750
clientTopic.push(topic)
747751
}
@@ -752,7 +756,9 @@ function sub_to_nearby_sondes(){
752756
} else {
753757
if (sub_logging) console.log("unsubbing from " + topic)
754758
if (client.isConnected()) {
755-
client.unsubscribe(topic)
759+
client.unsubscribe(topic);
760+
client.unsubscribe(prediction_topic);
761+
client.unsubscribe(reverse_topic);
756762
}
757763
var topic_index = clientTopic.indexOf(topic)
758764
if (topic_index > -1) {
@@ -790,6 +796,8 @@ function clean_refresh(text, force, history_step) {
790796
if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) {
791797
var topic = "sondes/" + wvar.query;
792798
client.subscribe(topic);
799+
client.subscribe("prediction/"+wvar.query);
800+
client.subscribe("reverse-prediction/"+wvar.query);
793801
clientTopic = [topic];
794802
} else {
795803
client.subscribe("sondes-new/#");
@@ -1161,6 +1169,33 @@ function panTo(vcallsign) {
11611169
set_polyline_visibility(serial,false);
11621170
}
11631171
}
1172+
1173+
// update predictions
1174+
$.ajax({
1175+
type: "GET",
1176+
url: predictions_url + vcallsign,
1177+
data: "",
1178+
dataType: "json",
1179+
serial: vcallsign,
1180+
success: function(response, textStatus) {
1181+
updatePredictions(response);
1182+
set_polyline_visibility(serial,true);
1183+
}
1184+
});
1185+
1186+
var data_str = "duration=" + wvar.mode + "&vehicles=" + vcallsign;
1187+
$.ajax({
1188+
type: "GET",
1189+
url: launch_predictions_url,
1190+
data: data_str,
1191+
dataType: "json",
1192+
serial: vcallsign,
1193+
success: function(response, textStatus) {
1194+
updateLaunchPredictions(response);
1195+
set_polyline_visibility(serial,true);
1196+
}
1197+
});
1198+
11641199
vehicles[vcallsign].polyline_visible = true;
11651200
set_polyline_visibility(vcallsign,true);
11661201
// update lookangles
@@ -1802,6 +1837,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
18021837
if($.type(newPosition.callsign) === "string"){
18031838
// Single callsign entry, as a string (chase cars)
18041839
callsign_list = newPosition.callsign;
1840+
num_callsigns = 1;
18051841
} else {
18061842
// Multiple callsigns, as an object
18071843
for(var rxcall in newPosition.callsign){
@@ -1828,9 +1864,16 @@ function updateVehicleInfo(vcallsign, newPosition) {
18281864
}
18291865
callsign_list.push(_new_call); // catch cases where there are no fields
18301866
}
1867+
num_callsigns = callsign_list.length;
18311868
callsign_list = callsign_list.join("<br>");
18321869
}
18331870

1871+
if (num_callsigns > 1){
1872+
num_callsigns = " (" + num_callsigns + ")";
1873+
} else {
1874+
num_callsigns = "";
1875+
}
1876+
18341877
var timeNow = new Date();
18351878
var timeSent = convert_time(newPosition.server_time);
18361879
var timeChosen = null;
@@ -1882,7 +1925,7 @@ function updateVehicleInfo(vcallsign, newPosition) {
18821925
'</div>' + // right
18831926
'</div>' + // data
18841927
'';
1885-
var c = '<dt class="receivers">Received <i class="friendly-dtime" data-timestamp='+timeChosen+'></i> via:</dt><dd class="receivers">' +
1928+
var c = '<dt class="receivers">Received <i class="friendly-dtime" data-timestamp='+timeChosen+'></i> via' + num_callsigns + ':</dt><dd class="receivers">' +
18861929
callsign_list + '</dd>';
18871930

18881931
if(!newPosition.callsign) c = '';
@@ -3813,6 +3856,8 @@ function liveData() {
38133856
if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) {
38143857
var topic = "sondes/" + wvar.query;
38153858
client.subscribe(topic);
3859+
client.subscribe("prediction/"+wvar.query);
3860+
client.subscribe("reverse-prediction/"+wvar.query);
38163861
clientTopic = [topic];
38173862
} else {
38183863
client.subscribe("sondes-new/#");
@@ -3893,7 +3938,32 @@ function liveData() {
38933938
} else {
38943939
updateReceivers(formatted_frame, single=true);
38953940
}
3941+
} else if (message.topic.startsWith("prediction")) {
3942+
var frame = JSON.parse(message.payloadString.toString());
38963943

3944+
var pred_data = [
3945+
{
3946+
"vehicle": frame.serial,
3947+
"time": frame.datetime,
3948+
"latitude": frame.position[1],
3949+
"longitude": frame.position[0],
3950+
"altitude": frame.altitude,
3951+
"ascent_rate": frame.ascent_rate,
3952+
"descent_rate": frame.descent_rate,
3953+
"burst_altitude": frame.burst_altitude,
3954+
"descending": frame.descending ? 1 : 0,
3955+
"landed": frame.descending ? 1 : 0,
3956+
"data": JSON.stringify(frame.data)
3957+
}
3958+
]
3959+
updatePredictions(pred_data);
3960+
} else if (message.topic.startsWith("reverse-prediction")) {
3961+
var frame = JSON.parse(message.payloadString.toString());
3962+
var serial = frame["serial"];
3963+
var pred_data = {
3964+
}
3965+
pred_data[serial] = frame
3966+
updateLaunchPredictions(pred_data);
38973967
} else {
38983968
var frame = JSON.parse(message.payloadString.toString());
38993969

@@ -4129,45 +4199,45 @@ function refreshRecoveryStats() {
41294199

41304200
var ajax_predictions = null;
41314201

4132-
function refreshPredictions() {
4133-
if(ajax_inprogress) {
4134-
clearTimeout(periodical_predictions);
4135-
periodical_predictions = setTimeout(refreshPredictions, 1000);
4136-
return;
4137-
}
4138-
4139-
ajax_predictions = $.ajax({
4140-
type: "GET",
4141-
url: predictions_url + encodeURIComponent(wvar.query),
4142-
data: "",
4143-
dataType: "json",
4144-
success: function(response, textStatus) {
4145-
updatePredictions(response);
4146-
},
4147-
error: function() {
4148-
},
4149-
complete: function(request, textStatus) {
4150-
clearTimeout(periodical_predictions);
4151-
periodical_predictions = setTimeout(refreshPredictions, 60 * 1000);
4152-
}
4153-
});
4154-
4155-
var data_str = "duration=" + wvar.mode + "&vehicles=" + encodeURIComponent(wvar.query);
4156-
4157-
ajax_predictions = $.ajax({
4158-
type: "GET",
4159-
url: launch_predictions_url,
4160-
data: data_str,
4161-
dataType: "json",
4162-
success: function(response, textStatus) {
4163-
updateLaunchPredictions(response);
4164-
},
4165-
error: function() {
4166-
},
4167-
complete: function(request, textStatus) {
4168-
}
4169-
});
4170-
}
4202+
// function refreshPredictions() {
4203+
// if(ajax_inprogress) {
4204+
// clearTimeout(periodical_predictions);
4205+
// periodical_predictions = setTimeout(refreshPredictions, 1000);
4206+
// return;
4207+
// }
4208+
4209+
// ajax_predictions = $.ajax({
4210+
// type: "GET",
4211+
// url: predictions_url + encodeURIComponent(wvar.query),
4212+
// data: "",
4213+
// dataType: "json",
4214+
// success: function(response, textStatus) {
4215+
// updatePredictions(response);
4216+
// },
4217+
// error: function() {
4218+
// },
4219+
// complete: function(request, textStatus) {
4220+
// clearTimeout(periodical_predictions);
4221+
// periodical_predictions = setTimeout(refreshPredictions, 60 * 1000);
4222+
// }
4223+
// });
4224+
4225+
// var data_str = "duration=" + wvar.mode + "&vehicles=" + encodeURIComponent(wvar.query);
4226+
4227+
// ajax_predictions = $.ajax({
4228+
// type: "GET",
4229+
// url: launch_predictions_url,
4230+
// data: data_str,
4231+
// dataType: "json",
4232+
// success: function(response, textStatus) {
4233+
// updateLaunchPredictions(response);
4234+
// },
4235+
// error: function() {
4236+
// },
4237+
// complete: function(request, textStatus) {
4238+
// }
4239+
// });
4240+
// }
41714241

41724242
var periodical, periodical_focus, periodical_focus_new, periodical_receivers, periodical_listeners, periodical_recoveries;
41734243
var periodical_predictions = null;
@@ -4875,7 +4945,7 @@ function update(response, none) {
48754945

48764946
}
48774947

4878-
if(periodical_predictions === null) refreshPredictions();
4948+
//if(periodical_predictions === null) refreshPredictions();
48794949
},
48804950

48814951
};

0 commit comments

Comments
 (0)