mirror of
https://github.com/30hours/blah2.git
synced 2024-11-18 12:33:58 +00:00
Add timestamp to to_json and fix timestamp display
This commit is contained in:
parent
a02f4d80dd
commit
abe0991dda
8 changed files with 43 additions and 21 deletions
|
@ -1,11 +1,9 @@
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
|
|
||||||
var nCpi = 20;
|
var nCpi = 20;
|
||||||
var iqdata = '';
|
|
||||||
var spectrum = [];
|
var spectrum = [];
|
||||||
frequency = [];
|
frequency = [];
|
||||||
var timestamp = [];
|
var timestamp = [];
|
||||||
var detection = '';
|
|
||||||
var ts = '';
|
var ts = '';
|
||||||
var output = [];
|
var output = [];
|
||||||
const options_timestamp = {
|
const options_timestamp = {
|
||||||
|
@ -49,6 +47,12 @@ function update_data() {
|
||||||
frequency.shift();
|
frequency.shift();
|
||||||
}
|
}
|
||||||
output.frequency = frequency;
|
output.frequency = frequency;
|
||||||
|
// timestamp
|
||||||
|
timestamp.push(output.timestamp);
|
||||||
|
if (timestamp.length > nCpi) {
|
||||||
|
timestamp.shift();
|
||||||
|
}
|
||||||
|
output.timestamp = timestamp;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,15 @@ var intervalId = window.setInterval(function () {
|
||||||
if (data.nRows != nRows) {
|
if (data.nRows != nRows) {
|
||||||
nRows = data.nRows;
|
nRows = data.nRows;
|
||||||
|
|
||||||
|
// timestamp posix to js
|
||||||
|
if (xVariable === "timestamp")
|
||||||
|
{
|
||||||
|
for (i = 0; i < data[xVariable].length; i++)
|
||||||
|
{
|
||||||
|
data[xVariable][i] = new Date(data[xVariable][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var trace1 = {
|
var trace1 = {
|
||||||
x: data[xVariable],
|
x: data[xVariable],
|
||||||
y: data[yVariable],
|
y: data[yVariable],
|
||||||
|
@ -109,6 +118,14 @@ var intervalId = window.setInterval(function () {
|
||||||
}
|
}
|
||||||
// case update plot
|
// case update plot
|
||||||
else {
|
else {
|
||||||
|
// timestamp posix to js
|
||||||
|
if (xVariable === "timestamp")
|
||||||
|
{
|
||||||
|
for (i = 0; i < data[xVariable].length; i++)
|
||||||
|
{
|
||||||
|
data[xVariable][i] = new Date(data[xVariable][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
var trace_update = {
|
var trace_update = {
|
||||||
x: [data[xVariable]],
|
x: [data[xVariable]],
|
||||||
y: [data[yVariable]]
|
y: [data[yVariable]]
|
||||||
|
|
|
@ -56,7 +56,6 @@ var layout = {
|
||||||
var config = {
|
var config = {
|
||||||
responsive: true,
|
responsive: true,
|
||||||
displayModeBar: false
|
displayModeBar: false
|
||||||
//scrollZoom: true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup plotly data
|
// setup plotly data
|
||||||
|
@ -88,13 +87,16 @@ var intervalId = window.setInterval(function () {
|
||||||
// case draw new plot
|
// case draw new plot
|
||||||
if (data.nRows != nRows) {
|
if (data.nRows != nRows) {
|
||||||
nRows = data.nRows;
|
nRows = data.nRows;
|
||||||
|
// timestamp posix to js
|
||||||
|
for (i = 0; i < data.timestamp.length; i++)
|
||||||
|
{
|
||||||
|
data.timestamp[i] = new Date(data.timestamp[i]);
|
||||||
|
}
|
||||||
var trace1 = {
|
var trace1 = {
|
||||||
|
y: data.timestamp,
|
||||||
z: data.spectrum,
|
z: data.spectrum,
|
||||||
colorscale: 'Jet',
|
colorscale: 'Jet',
|
||||||
zauto: false,
|
zauto: false,
|
||||||
//zmin: 0,
|
|
||||||
//zmax: Math.max(13, data.maxPower),
|
|
||||||
type: 'heatmap'
|
type: 'heatmap'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -103,9 +105,14 @@ var intervalId = window.setInterval(function () {
|
||||||
}
|
}
|
||||||
// case update plot
|
// case update plot
|
||||||
else {
|
else {
|
||||||
|
// timestamp posix to js
|
||||||
|
for (i = 0; i < data.timestamp.length; i++)
|
||||||
|
{
|
||||||
|
data.timestamp[i] = new Date(data.timestamp[i]);
|
||||||
|
}
|
||||||
var trace_update = {
|
var trace_update = {
|
||||||
|
y: [data.timestamp],
|
||||||
z: [data.spectrum]
|
z: [data.spectrum]
|
||||||
//zmax: [Math.max(13, data.maxPower), []]
|
|
||||||
};
|
};
|
||||||
Plotly.update('data', trace_update);
|
Plotly.update('data', trace_update);
|
||||||
}
|
}
|
||||||
|
|
|
@ -266,7 +266,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// output map data
|
// output map data
|
||||||
mapJson = map->to_json();
|
mapJson = map->to_json(t0/1000);
|
||||||
mapJson = map->delay_bin_to_km(mapJson, fs);
|
mapJson = map->delay_bin_to_km(mapJson, fs);
|
||||||
if (saveMap)
|
if (saveMap)
|
||||||
{
|
{
|
||||||
|
@ -279,7 +279,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// output detection data
|
// output detection data
|
||||||
detectionJson = detection->to_json();
|
detectionJson = detection->to_json(t0/1000);
|
||||||
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
|
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
|
||||||
for (int i = 0; i < (detectionJson.size() + MTU - 1) / MTU; i++)
|
for (int i = 0; i < (detectionJson.size() + MTU - 1) / MTU; i++)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,7 +36,7 @@ size_t Detection::get_nDetections()
|
||||||
return delay.size();
|
return delay.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Detection::to_json()
|
std::string Detection::to_json(uint64_t timestamp)
|
||||||
{
|
{
|
||||||
rapidjson::Document document;
|
rapidjson::Document document;
|
||||||
document.SetObject();
|
document.SetObject();
|
||||||
|
@ -63,10 +63,7 @@ std::string Detection::to_json()
|
||||||
arraySnr.PushBack(snr[i], allocator);
|
arraySnr.PushBack(snr[i], allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get posix time
|
document.AddMember("timestamp", timestamp, allocator);
|
||||||
uint64_t timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
||||||
|
|
||||||
document.AddMember("timestamp", timestamp/1000, allocator);
|
|
||||||
document.AddMember("delay", arrayDelay, allocator);
|
document.AddMember("delay", arrayDelay, allocator);
|
||||||
document.AddMember("doppler", arrayDoppler, allocator);
|
document.AddMember("doppler", arrayDoppler, allocator);
|
||||||
document.AddMember("snr", arraySnr, allocator);
|
document.AddMember("snr", arraySnr, allocator);
|
||||||
|
|
|
@ -47,7 +47,7 @@ public:
|
||||||
|
|
||||||
/// @brief Generate JSON of the detections and metadata.
|
/// @brief Generate JSON of the detections and metadata.
|
||||||
/// @return JSON string.
|
/// @return JSON string.
|
||||||
std::string to_json();
|
std::string to_json(uint64_t timestamp);
|
||||||
|
|
||||||
/// @brief Update JSON to convert delay bins to km.
|
/// @brief Update JSON to convert delay bins to km.
|
||||||
/// @param json Input JSON string with delay field.
|
/// @param json Input JSON string with delay field.
|
||||||
|
|
|
@ -112,7 +112,7 @@ uint32_t Map<T>::doppler_hz_to_bin(double dopplerHz)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::string Map<T>::to_json()
|
std::string Map<T>::to_json(uint64_t timestamp)
|
||||||
{
|
{
|
||||||
rapidjson::Document document;
|
rapidjson::Document document;
|
||||||
document.SetObject();
|
document.SetObject();
|
||||||
|
@ -144,10 +144,7 @@ std::string Map<T>::to_json()
|
||||||
arrayDoppler.PushBack(doppler[i], allocator);
|
arrayDoppler.PushBack(doppler[i], allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get posix time
|
document.AddMember("timestamp", timestamp, allocator);
|
||||||
uint64_t timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
|
||||||
|
|
||||||
document.AddMember("timestamp", timestamp/1000, allocator);
|
|
||||||
document.AddMember("nRows", nRows, allocator);
|
document.AddMember("nRows", nRows, allocator);
|
||||||
document.AddMember("nCols", nCols, allocator);
|
document.AddMember("nCols", nCols, allocator);
|
||||||
document.AddMember("noisePower", noisePower, allocator);
|
document.AddMember("noisePower", noisePower, allocator);
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
|
|
||||||
/// @brief Generate JSON of the map and metadata.
|
/// @brief Generate JSON of the map and metadata.
|
||||||
/// @return JSON string.
|
/// @return JSON string.
|
||||||
std::string to_json();
|
std::string to_json(uint64_t timestamp);
|
||||||
|
|
||||||
/// @brief Update JSON to convert delay bins to km.
|
/// @brief Update JSON to convert delay bins to km.
|
||||||
/// @param json Input JSON string with delay field.
|
/// @param json Input JSON string with delay field.
|
||||||
|
|
Loading…
Reference in a new issue