2023-05-04 11:25:37 +00:00
|
|
|
var timestamp = -1;
|
|
|
|
var nRows = 3;
|
|
|
|
var host = window.location.hostname;
|
2024-02-18 12:26:17 +00:00
|
|
|
var isLocalHost = is_localhost(host);
|
2023-11-27 11:19:47 +00:00
|
|
|
var range_x = [];
|
|
|
|
var range_y = [];
|
2023-10-25 13:18:03 +00:00
|
|
|
|
2023-11-27 02:35:42 +00:00
|
|
|
// setup API
|
2023-12-19 09:37:42 +00:00
|
|
|
var urlTimestamp;
|
|
|
|
var urlDetection;
|
2024-02-11 14:24:23 +00:00
|
|
|
var urlAdsb;
|
2024-02-12 09:04:13 +00:00
|
|
|
var urlAdsbLink;
|
2024-02-11 14:24:23 +00:00
|
|
|
var urlConfig;
|
2023-11-25 22:46:10 +00:00
|
|
|
if (isLocalHost) {
|
2023-12-19 09:37:42 +00:00
|
|
|
urlTimestamp = '//' + host + ':3000/api/timestamp';
|
2023-11-25 22:46:10 +00:00
|
|
|
} else {
|
2023-12-19 09:37:42 +00:00
|
|
|
urlTimestamp = '//' + host + '/api/timestamp';
|
2023-11-25 22:46:10 +00:00
|
|
|
}
|
2023-11-27 02:35:42 +00:00
|
|
|
if (isLocalHost) {
|
2023-12-17 06:16:36 +00:00
|
|
|
urlDetection = '//' + host + ':3000/api/detection';
|
2023-11-27 02:35:42 +00:00
|
|
|
} else {
|
2023-12-17 06:16:36 +00:00
|
|
|
urlDetection = '//' + host + '/api/detection';
|
|
|
|
}
|
|
|
|
if (isLocalHost) {
|
|
|
|
urlMap = '//' + host + ':3000' + urlMap;
|
|
|
|
} else {
|
|
|
|
urlMap = '//' + host + urlMap;
|
2023-11-27 02:35:42 +00:00
|
|
|
}
|
2024-02-11 14:24:23 +00:00
|
|
|
if (isLocalHost) {
|
2024-02-12 09:04:13 +00:00
|
|
|
urlAdsbLink = '//' + host + ':3000/api/adsb2dd';
|
2024-02-11 14:24:23 +00:00
|
|
|
} else {
|
2024-02-12 09:04:13 +00:00
|
|
|
urlAdsbLink = '//' + host + '/api/adsb2dd';
|
2024-02-11 14:24:23 +00:00
|
|
|
}
|
|
|
|
if (isLocalHost) {
|
|
|
|
urlConfig = '//' + host + ':3000/api/config';
|
|
|
|
} else {
|
|
|
|
urlConfig = '//' + host + '/api/config';
|
|
|
|
}
|
2023-11-25 22:46:10 +00:00
|
|
|
|
2024-02-11 14:24:23 +00:00
|
|
|
// get truth flag
|
|
|
|
var isTruth = false;
|
2024-02-18 12:26:17 +00:00
|
|
|
$.getJSON(urlConfig, function () { })
|
2024-02-11 14:24:23 +00:00
|
|
|
.done(function (data_config) {
|
|
|
|
if (data_config.truth.adsb.enabled === true) {
|
|
|
|
isTruth = true;
|
2024-02-18 12:26:17 +00:00
|
|
|
$.getJSON(urlAdsbLink, function () { })
|
2024-02-12 09:04:13 +00:00
|
|
|
.done(function (data) {
|
|
|
|
urlAdsb = data.url;
|
2024-02-18 12:26:17 +00:00
|
|
|
if (!is_localhost(new URL(urlAdsb).hostname)) {
|
2024-02-18 01:48:50 +00:00
|
|
|
urlAdsb = urlAdsb.replace(/^http:/, 'https:');
|
|
|
|
}
|
2024-02-12 09:04:13 +00:00
|
|
|
})
|
2024-02-11 14:24:23 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-11-27 02:35:42 +00:00
|
|
|
// setup plotly
|
2023-05-04 11:25:37 +00:00
|
|
|
var layout = {
|
2023-12-06 14:40:34 +00:00
|
|
|
autosize: true,
|
2023-05-04 11:25:37 +00:00
|
|
|
margin: {
|
|
|
|
l: 50,
|
|
|
|
r: 50,
|
|
|
|
b: 50,
|
2023-11-27 02:35:42 +00:00
|
|
|
t: 10,
|
2023-05-04 11:25:37 +00:00
|
|
|
pad: 0
|
|
|
|
},
|
2023-11-27 02:35:42 +00:00
|
|
|
hoverlabel: {
|
|
|
|
namelength: 0
|
|
|
|
},
|
2023-05-04 11:25:37 +00:00
|
|
|
plot_bgcolor: "rgba(0,0,0,0)",
|
|
|
|
paper_bgcolor: "rgba(0,0,0,0)",
|
|
|
|
annotations: [],
|
|
|
|
displayModeBar: false,
|
|
|
|
xaxis: {
|
2023-11-27 02:35:42 +00:00
|
|
|
title: {
|
|
|
|
text: 'Bistatic Range (km)',
|
|
|
|
font: {
|
|
|
|
size: 24
|
|
|
|
}
|
|
|
|
},
|
2023-05-04 11:25:37 +00:00
|
|
|
ticks: '',
|
|
|
|
side: 'bottom'
|
|
|
|
},
|
|
|
|
yaxis: {
|
2023-11-27 02:35:42 +00:00
|
|
|
title: {
|
|
|
|
text: 'Bistatic Doppler (Hz)',
|
|
|
|
font: {
|
|
|
|
size: 24
|
|
|
|
}
|
|
|
|
},
|
2023-05-04 11:25:37 +00:00
|
|
|
ticks: '',
|
|
|
|
ticksuffix: ' ',
|
2023-11-27 02:35:42 +00:00
|
|
|
autosize: false,
|
|
|
|
categoryorder: "total descending"
|
2024-02-11 14:24:23 +00:00
|
|
|
},
|
|
|
|
showlegend: false
|
2023-05-04 11:25:37 +00:00
|
|
|
};
|
|
|
|
var config = {
|
2023-12-06 14:40:34 +00:00
|
|
|
responsive: true,
|
|
|
|
displayModeBar: false
|
|
|
|
//scrollZoom: true
|
2023-05-04 11:25:37 +00:00
|
|
|
}
|
|
|
|
|
2023-11-27 02:35:42 +00:00
|
|
|
// setup plotly data
|
|
|
|
var data = [
|
|
|
|
{
|
|
|
|
z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
|
|
|
|
colorscale: 'Jet',
|
|
|
|
type: 'heatmap'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
var detection = [];
|
2024-02-11 14:24:23 +00:00
|
|
|
var adsb = {};
|
2023-11-27 02:35:42 +00:00
|
|
|
|
2023-12-05 13:14:00 +00:00
|
|
|
Plotly.newPlot('data', data, layout, config);
|
2023-05-04 11:25:37 +00:00
|
|
|
|
2023-11-27 02:35:42 +00:00
|
|
|
// callback function
|
2023-05-04 11:25:37 +00:00
|
|
|
var intervalId = window.setInterval(function () {
|
2023-11-14 12:13:14 +00:00
|
|
|
|
|
|
|
// check if timestamp is updated
|
2024-02-18 12:26:17 +00:00
|
|
|
$.get(urlTimestamp, function () { })
|
2023-05-04 11:25:37 +00:00
|
|
|
|
|
|
|
.done(function (data) {
|
2023-11-14 12:13:14 +00:00
|
|
|
if (timestamp != data) {
|
|
|
|
timestamp = data;
|
2023-11-29 09:41:46 +00:00
|
|
|
|
|
|
|
// get detection data (no detection lag)
|
2024-02-18 12:26:17 +00:00
|
|
|
$.getJSON(urlDetection, function () { })
|
2023-11-29 09:41:46 +00:00
|
|
|
.done(function (data_detection) {
|
|
|
|
detection = data_detection;
|
|
|
|
});
|
|
|
|
|
2024-02-11 14:24:23 +00:00
|
|
|
// get ADS-B data if enabled in config
|
|
|
|
if (isTruth) {
|
2024-02-18 12:26:17 +00:00
|
|
|
$.getJSON(urlAdsb, function () { })
|
2024-02-11 14:24:23 +00:00
|
|
|
.done(function (data_adsb) {
|
|
|
|
adsb['delay'] = [];
|
|
|
|
adsb['doppler'] = [];
|
|
|
|
adsb['flight'] = [];
|
|
|
|
for (const aircraft in data_adsb) {
|
|
|
|
if ('doppler' in data_adsb[aircraft]) {
|
|
|
|
adsb['delay'].push(data_adsb[aircraft]['delay'])
|
|
|
|
adsb['doppler'].push(data_adsb[aircraft]['doppler'])
|
|
|
|
adsb['flight'].push(data_adsb[aircraft]['flight'])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-14 12:13:14 +00:00
|
|
|
// get new map data
|
2024-02-18 12:26:17 +00:00
|
|
|
$.getJSON(urlMap, function () { })
|
2023-11-14 12:13:14 +00:00
|
|
|
.done(function (data) {
|
2023-11-27 02:35:42 +00:00
|
|
|
|
2023-11-14 12:13:14 +00:00
|
|
|
// case draw new plot
|
2023-11-27 02:35:42 +00:00
|
|
|
if (data.nRows != nRows) {
|
2023-11-14 12:13:14 +00:00
|
|
|
nRows = data.nRows;
|
2023-11-27 11:19:47 +00:00
|
|
|
|
|
|
|
// lock range before other trace
|
|
|
|
var layout_update = {
|
|
|
|
'xaxis.range': [data.delay[0], data.delay.slice(-1)[0]],
|
|
|
|
'yaxis.range': [data.doppler[0], data.doppler.slice(-1)[0]]
|
|
|
|
};
|
2023-12-05 13:14:00 +00:00
|
|
|
Plotly.relayout('data', layout_update);
|
2023-11-27 11:19:47 +00:00
|
|
|
|
2023-11-27 02:35:42 +00:00
|
|
|
var trace1 = {
|
2023-11-14 12:13:14 +00:00
|
|
|
z: data.data,
|
|
|
|
x: data.delay,
|
|
|
|
y: data.doppler,
|
2024-05-15 14:54:44 +00:00
|
|
|
colorscale: 'Viridis',
|
2023-11-14 12:13:14 +00:00
|
|
|
zauto: false,
|
|
|
|
zmin: 0,
|
|
|
|
zmax: Math.max(13, data.maxPower),
|
|
|
|
type: 'heatmap'
|
|
|
|
};
|
2023-11-27 02:35:42 +00:00
|
|
|
var trace2 = {
|
|
|
|
x: detection.delay,
|
|
|
|
y: detection.doppler,
|
|
|
|
mode: 'markers',
|
2023-11-27 11:19:47 +00:00
|
|
|
type: 'scatter',
|
|
|
|
marker: {
|
|
|
|
size: 16,
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
2023-11-27 02:35:42 +00:00
|
|
|
};
|
2024-02-11 14:24:23 +00:00
|
|
|
var trace3 = {
|
|
|
|
x: adsb.delay,
|
|
|
|
y: adsb.doppler,
|
|
|
|
mode: 'markers',
|
|
|
|
type: 'scatter',
|
|
|
|
marker: {
|
|
|
|
size: 16,
|
|
|
|
opacity: 0.6
|
|
|
|
}
|
|
|
|
};
|
2023-11-27 02:35:42 +00:00
|
|
|
|
2024-02-11 14:24:23 +00:00
|
|
|
var data_trace = [trace1, trace2, trace3];
|
2023-12-05 13:14:00 +00:00
|
|
|
Plotly.newPlot('data', data_trace, layout, config);
|
2023-11-14 12:13:14 +00:00
|
|
|
}
|
2023-11-27 02:35:42 +00:00
|
|
|
// case update plot
|
2023-11-14 12:13:14 +00:00
|
|
|
else {
|
2023-11-27 02:35:42 +00:00
|
|
|
var trace_update = {
|
2024-02-11 14:24:23 +00:00
|
|
|
x: [data.delay, detection.delay, adsb.delay],
|
|
|
|
y: [data.doppler, detection.doppler, adsb.doppler],
|
|
|
|
z: [data.data, [], []],
|
|
|
|
zmax: [Math.max(13, data.maxPower), [], []],
|
|
|
|
text: [[], [], adsb.flight]
|
2023-11-14 12:13:14 +00:00
|
|
|
};
|
2023-12-05 13:14:00 +00:00
|
|
|
Plotly.update('data', trace_update);
|
2023-11-14 12:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
.fail(function () {
|
|
|
|
})
|
|
|
|
.always(function () {
|
|
|
|
});
|
|
|
|
}
|
2023-05-04 11:25:37 +00:00
|
|
|
})
|
|
|
|
.fail(function () {
|
|
|
|
})
|
|
|
|
.always(function () {
|
|
|
|
});
|
2023-11-17 12:27:32 +00:00
|
|
|
}, 100);
|