Skip to content

Commit 2cffc2e

Browse files
committed
prediction improvements
1 parent b25be8b commit 2cffc2e

File tree

2 files changed

+136
-93
lines changed

2 files changed

+136
-93
lines changed

js/tracker.js

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ function setTimeValue() {
639639
}, 100);
640640
}
641641

642-
function launchSitePredictions(times, station, marker) {
642+
function launchSitePredictions(times, station, properties, marker) {
643643
var popup = launches.getLayer(marker).getPopup();
644644
var popupContent = popup.getContent();
645645
var popupContentSplit = popupContent.split("<button onclick='launchSitePredictions(")[0];
@@ -651,6 +651,7 @@ function launchSitePredictions(times, station, marker) {
651651
}
652652
times = times.split(",");
653653
position = station.split(",");
654+
properties = properties.split(":");
654655
var now = new Date();
655656
var maxCount = 7
656657
var count = 0;
@@ -667,6 +668,7 @@ function launchSitePredictions(times, station, marker) {
667668
date.setUTCMinutes(time[2]);
668669
date.setSeconds(0);
669670
date.setMilliseconds(0);
671+
date.setMinutes( date.getMinutes() - 45 );
670672
if (date < now) {
671673
if (time[0] == 0) {
672674
date.setDate(date.getDate() + 1);
@@ -692,8 +694,9 @@ function launchSitePredictions(times, station, marker) {
692694
}
693695
var completed = 0;
694696
for (var i = 0; i < dates.length; i++) {
695-
//var url = "http://predict.cusf.co.uk/api/v1/?launch_latitude=" + position[0] + "&launch_longitude=" + position[1] + "&launch_datetime=" + dates[i] + "&ascent_rate=5&burst_altitude=26000&descent_rate=6";
696-
var url = "https://api.v2.sondehub.org/tawhiri?launch_latitude=" + position[0] + "&launch_longitude=" + position[1] + "&launch_datetime=" + dates[i] + "&ascent_rate=5&burst_altitude=26000&descent_rate=6";
697+
var lon = ((360 + (position[1] % 360)) % 360)
698+
var url = "http://predict.cusf.co.uk/api/v1/?launch_latitude=" + position[0] + "&launch_longitude=" + lon + "&launch_datetime=" + dates[i] + "&ascent_rate=" + properties[0] + "&burst_altitude=" + properties[2] + "&descent_rate=" + properties[1];
699+
//var url = "https://api.v2.sondehub.org/tawhiri?launch_latitude=" + position[0] + "&launch_longitude=" + lon + "&launch_datetime=" + dates[i] + "&ascent_rate=" + properties[0] + "&burst_altitude=" + properties[2] + "&descent_rate=" + properties[1];
697700
showPrediction(url).done(handleData).fail(handleError);
698701
}
699702
function handleData(data) {
@@ -725,10 +728,20 @@ function plotPrediction (data, dates, marker) {
725728
descent = data.prediction[1].trajectory;
726729
var predictionPath = [];
727730
for (var i = 0; i < ascent.length; i++) {
728-
predictionPath.push([ascent[i].latitude, ascent[i].longitude]);
731+
if (ascent[i].longitude > 180.0) {
732+
var longitude = ascent[i].longitude - 360.0;
733+
} else {
734+
var longitude = ascent[i].longitude;
735+
}
736+
predictionPath.push([ascent[i].latitude, longitude]);
729737
};
730738
for (var x = 0; x < descent.length; x++) {
731-
predictionPath.push([descent[x].latitude, descent[x].longitude]);
739+
if (descent[x].longitude > 180.0) {
740+
var longitude = descent[x].longitude - 360.0;
741+
} else {
742+
var longitude = descent[x].longitude;
743+
}
744+
predictionPath.push([descent[x].latitude, longitude]);
732745
};
733746
var burstPoint = ascent[ascent.length-1];
734747
var landingPoint = descent[descent.length-1];
@@ -743,15 +756,27 @@ function plotPrediction (data, dates, marker) {
743756
iconAnchor: [10, 10],
744757
});
745758

746-
plot.burstMarker = new L.marker([burstPoint.latitude, burstPoint.longitude], {
759+
if (burstPoint.longitude > 180.0) {
760+
var burstLongitude = burstPoint.longitude - 360.0;
761+
} else {
762+
var burstLongitude = burstPoint.longitude;
763+
}
764+
765+
plot.burstMarker = new L.marker([burstPoint.latitude, burstLongitude], {
747766
icon: burstIcon
748767
}).addTo(map);
749768

750769
var burstTime = new Date(burstPoint.datetime);
751770
var burstTooltip = "<b>Time: </b>" + burstTime.toLocaleString() + "<br><b>Altitude: </b>" + Math.round(burstPoint.altitude) + "m";
752771
plot.burstMarker.bindTooltip(burstTooltip, {offset: [5,0]});
753772

754-
plot.landingMarker = new L.marker([landingPoint.latitude, landingPoint.longitude], {
773+
if (landingPoint.longitude > 180.0) {
774+
var landingLongitude = landingPoint.longitude - 360.0;
775+
} else {
776+
var landingLongitude = landingPoint.longitude;
777+
}
778+
779+
plot.landingMarker = new L.marker([landingPoint.latitude, landingLongitude], {
755780
icon: new L.NumberedDivIcon({number: dates.indexOf(data.request.launch_datetime)+1})
756781
}).addTo(map);
757782

@@ -834,6 +859,7 @@ function showLaunchSites() {
834859
date.setUTCHours(time[1]);
835860
date.setUTCMinutes(time[2]);
836861
date.setSeconds(0);
862+
date.setMinutes( date.getMinutes() - 45 );
837863
if (date < now) {
838864
if (time[0] == 0) {
839865
date.setDate(date.getDate() + 1);
@@ -851,7 +877,24 @@ function showLaunchSites() {
851877
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondes + "<br><b>Next launch:</b> " + date.toString();
852878
}
853879
}
854-
popupContent += "<br><button onclick='launchSitePredictions(\"" + json[key]['times'].toString() + "\", \"" + latlon.toString() + "\", \"" + launches.getLayerId(marker) + "\")' style='margin-bottom:0;'>Generate Predictions</button>";
880+
var ascent_rate = 5;
881+
var descent_rate = 6;
882+
var burst_altitude = 26000;
883+
if (json[key].rs_types.includes("11") || json[key].rs_types.includes("82")) { //LMS6
884+
ascent_rate = 5;
885+
descent_rate = 3;
886+
burst_altitude = 26000;
887+
}
888+
if (json[key].hasOwnProperty('ascent_rate')) {
889+
ascent_rate = json[key]["ascent_rate"];
890+
}
891+
if (json[key].hasOwnProperty('descent_rate')) {
892+
descent_rate = json[key]["descent_rate"];
893+
}
894+
if (json[key].hasOwnProperty('burst_altitude')) {
895+
burst_altitude = json[key]["burst_altitude"];
896+
}
897+
popupContent += "<br><button onclick='launchSitePredictions(\"" + json[key]['times'].toString() + "\", \"" + latlon.toString() + "\", \"" + ascent_rate + ":" + descent_rate + ":" + burst_altitude + "\", \"" + launches.getLayerId(marker) + "\")' style='margin-bottom:0;'>Generate Predictions</button>";
855898
} else {
856899
popupContent = "<font style='font-size: 13px'>" + json[key].station_name + "</font><br><br><b>Sondes launched:</b> " + sondes;
857900
}
@@ -964,7 +1007,7 @@ function habitat_data(jsondata, alternative) {
9641007
"temperature_internal": "&deg;C",
9651008
"temperature_external": "&deg;C",
9661009
"temperature_radio": "&deg;C",
967-
"pressure": " Pa",
1010+
"pressure": " hPa",
9681011
"voltage_solar_1": " V",
9691012
"voltage_solar_2": " V",
9701013
"battery_percent": "%",

0 commit comments

Comments
 (0)