Add detections to map front end display

This commit is contained in:
30hours 2023-11-27 02:35:42 +00:00
parent 6eddada856
commit 8555f51417
3 changed files with 94 additions and 110 deletions

View file

@ -84,9 +84,9 @@
<body style="background-color:#f78c58;"> <body style="background-color:#f78c58;">
<div style="height: 100vh; width: 90vw" class="container-fluid"> <div style="height: 100vh; width: 95vw" class="container-fluid">
<div style="height: 100vh; width: 90vw" class="row d-flex"> <div style="height: 100vh; width: 95vw" class="row d-flex">
<div class="justify-content-center" id="ddmap"></div> <div class="justify-content-center" id="ddmap"></div>

View file

@ -1,10 +1,70 @@
var timestamp = -1; var timestamp = -1;
var nRows = 3; var nRows = 3;
var nCols = 3;
var host = window.location.hostname; var host = window.location.hostname;
var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112");
// setup API
var urlTimestamp = '';
if (isLocalHost) {
urlTimestamp = '//' + host + ':3000/timestamp?timestamp=' + Date.now();
} else {
urlTimestamp = '//' + host + '/api/timestamp?timestamp=' + Date.now();
}
var urlDetection = '';
if (isLocalHost) {
urlDetection = '//' + host + ':3000/detection?timestamp=' + Date.now();
} else {
urlDetection = '//' + host + '/api/detection?timestamp=' + Date.now();
}
// setup plotly
var layout = {
autosize: false,
margin: {
l: 50,
r: 50,
b: 50,
t: 10,
pad: 0
},
hoverlabel: {
namelength: 0
},
width: document.getElementById('ddmap').offsetWidth,
height: document.getElementById('ddmap').offsetHeight,
plot_bgcolor: "rgba(0,0,0,0)",
paper_bgcolor: "rgba(0,0,0,0)",
annotations: [],
displayModeBar: false,
xaxis: {
title: {
text: 'Bistatic Range (km)',
font: {
size: 24
}
},
ticks: '',
side: 'bottom'
},
yaxis: {
title: {
text: 'Bistatic Doppler (Hz)',
font: {
size: 24
}
},
ticks: '',
ticksuffix: ' ',
autosize: false,
categoryorder: "total descending"
}
};
var config = {
displayModeBar: false,
responsive: true
}
// setup plotly data
var data = [ var data = [
{ {
z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]], z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]],
@ -12,51 +72,11 @@ var data = [
type: 'heatmap' type: 'heatmap'
} }
]; ];
var detection = [];
var urlTimestamp = '';
if (isLocalHost) {
urlTimestamp = '//' + host + ':3000/timestamp?timestamp=' + Date.now();
} else {
urlTimestamp = '//' + host + '/api/timestamp?timestamp=' + Date.now();
}
var layout = {
autosize: false,
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
pad: 0
},
width: document.getElementById('ddmap').offsetWidth,
height: document.getElementById('ddmap').offsetHeight,
plot_bgcolor: "rgba(0,0,0,0)",
paper_bgcolor: "rgba(0,0,0,0)",
annotations: [],
coloraxis: {
cmin: 0,
cmax: 1
},
displayModeBar: false,
xaxis: {
ticks: '',
side: 'bottom'
},
yaxis: {
ticks: '',
ticksuffix: ' ',
autosize: false
}
};
var config = {
displayModeBar: false,
responsive: true
}
Plotly.newPlot('ddmap', data, layout, config); Plotly.newPlot('ddmap', data, layout, config);
// callback function
var intervalId = window.setInterval(function () { var intervalId = window.setInterval(function () {
// check if timestamp is updated // check if timestamp is updated
@ -68,13 +88,17 @@ var intervalId = window.setInterval(function () {
// get new map data // get new map data
var apiData = $.getJSON(urlMap, function () { }) var apiData = $.getJSON(urlMap, function () { })
.done(function (data) { .done(function (data) {
// case draw new plot
if (data.nRows != nRows || data.nCols != nCols) {
nRows = data.nRows;
nCols = data.nCols;
data = [ // get detection data
{ var detectionData = $.getJSON(urlDetection, function () { })
.done(function (data_detection) {
detection = data_detection;
});
// case draw new plot
if (data.nRows != nRows) {
nRows = data.nRows;
var trace1 = {
z: data.data, z: data.data,
x: data.delay, x: data.delay,
y: data.doppler, y: data.doppler,
@ -83,77 +107,37 @@ var intervalId = window.setInterval(function () {
zmin: 0, zmin: 0,
zmax: Math.max(13, data.maxPower), zmax: Math.max(13, data.maxPower),
type: 'heatmap' type: 'heatmap'
}
];
layout = {
autosize: false,
margin: {
l: 50,
r: 50,
b: 50,
t: 50,
pad: 0
},
width: document.getElementById('ddmap').offsetWidth,
height: document.getElementById('ddmap').offsetHeight,
plot_bgcolor: "rgba(0,0,0,0)",
paper_bgcolor: "rgba(0,0,0,0)",
annotations: [],
displayModeBar: false,
xaxis: {
title: {
text: 'Bistatic Range (km)',
font: {
size: 24
}
},
ticks: '',
side: 'bottom'
},
yaxis: {
title: {
text: 'Bistatic Doppler (Hz)',
font: {
size: 24
}
},
ticks: '',
ticksuffix: ' ',
autosize: false,
categoryorder: "total descending"
}
}; };
Plotly.newPlot('ddmap', data, layout, { displayModeBar: false }); var trace2 = {
x: detection.delay,
y: detection.doppler,
mode: 'markers',
type: 'scatter'
};
var data_trace = [trace1, trace2];
Plotly.newPlot('ddmap', data_trace, layout, config);
} }
// case update plot
else { else {
data_update = var trace_update = {
{ x: [data.delay, detection.delay],
'z': [data.data], y: [data.doppler, detection.doppler],
'zmax': Math.max(13, data.maxPower) z: [data.data, []],
zmax: [Math.max(13, data.maxPower), []]
}; };
layout_update = { Plotly.update('ddmap', trace_update);
};
Plotly.update('ddmap', data_update, layout_update, { displayModeBar: false });
} }
}) })
.fail(function () { .fail(function () {
console.log('API Fail');
}) })
.always(function () { .always(function () {
}); });
} }
}) })
.fail(function () { .fail(function () {
console.log('API Fail');
}) })
.always(function () { .always(function () {
}); });
}, 100); }, 100);

View file

@ -84,9 +84,9 @@
<body style="background-color:#f78c58;"> <body style="background-color:#f78c58;">
<div style="height: 100vh; width: 90vw" class="container-fluid"> <div style="height: 100vh; width: 95vw" class="container-fluid">
<div style="height: 100vh; width: 90vw" class="row d-flex"> <div style="height: 100vh; width: 95vw" class="row d-flex">
<div class="justify-content-center" id="ddmap"></div> <div class="justify-content-center" id="ddmap"></div>