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');
|
||||
|
||||
var nCpi = 20;
|
||||
var iqdata = '';
|
||||
var spectrum = [];
|
||||
frequency = [];
|
||||
var timestamp = [];
|
||||
var detection = '';
|
||||
var ts = '';
|
||||
var output = [];
|
||||
const options_timestamp = {
|
||||
|
@ -49,6 +47,12 @@ function update_data() {
|
|||
frequency.shift();
|
||||
}
|
||||
output.frequency = frequency;
|
||||
// timestamp
|
||||
timestamp.push(output.timestamp);
|
||||
if (timestamp.length > nCpi) {
|
||||
timestamp.shift();
|
||||
}
|
||||
output.timestamp = timestamp;
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
|
|
|
@ -97,6 +97,15 @@ var intervalId = window.setInterval(function () {
|
|||
if (data.nRows != 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 = {
|
||||
x: data[xVariable],
|
||||
y: data[yVariable],
|
||||
|
@ -109,6 +118,14 @@ var intervalId = window.setInterval(function () {
|
|||
}
|
||||
// case update plot
|
||||
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 = {
|
||||
x: [data[xVariable]],
|
||||
y: [data[yVariable]]
|
||||
|
|
|
@ -56,7 +56,6 @@ var layout = {
|
|||
var config = {
|
||||
responsive: true,
|
||||
displayModeBar: false
|
||||
//scrollZoom: true
|
||||
}
|
||||
|
||||
// setup plotly data
|
||||
|
@ -88,13 +87,16 @@ var intervalId = window.setInterval(function () {
|
|||
// case draw new plot
|
||||
if (data.nRows != 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 = {
|
||||
y: data.timestamp,
|
||||
z: data.spectrum,
|
||||
colorscale: 'Jet',
|
||||
zauto: false,
|
||||
//zmin: 0,
|
||||
//zmax: Math.max(13, data.maxPower),
|
||||
type: 'heatmap'
|
||||
};
|
||||
|
||||
|
@ -103,9 +105,14 @@ var intervalId = window.setInterval(function () {
|
|||
}
|
||||
// case update plot
|
||||
else {
|
||||
// timestamp posix to js
|
||||
for (i = 0; i < data.timestamp.length; i++)
|
||||
{
|
||||
data.timestamp[i] = new Date(data.timestamp[i]);
|
||||
}
|
||||
var trace_update = {
|
||||
y: [data.timestamp],
|
||||
z: [data.spectrum]
|
||||
//zmax: [Math.max(13, data.maxPower), []]
|
||||
};
|
||||
Plotly.update('data', trace_update);
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
// output map data
|
||||
mapJson = map->to_json();
|
||||
mapJson = map->to_json(t0/1000);
|
||||
mapJson = map->delay_bin_to_km(mapJson, fs);
|
||||
if (saveMap)
|
||||
{
|
||||
|
@ -279,7 +279,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
// output detection data
|
||||
detectionJson = detection->to_json();
|
||||
detectionJson = detection->to_json(t0/1000);
|
||||
detectionJson = detection->delay_bin_to_km(detectionJson, fs);
|
||||
for (int i = 0; i < (detectionJson.size() + MTU - 1) / MTU; i++)
|
||||
{
|
||||
|
|
|
@ -36,7 +36,7 @@ size_t Detection::get_nDetections()
|
|||
return delay.size();
|
||||
}
|
||||
|
||||
std::string Detection::to_json()
|
||||
std::string Detection::to_json(uint64_t timestamp)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
|
@ -63,10 +63,7 @@ std::string Detection::to_json()
|
|||
arraySnr.PushBack(snr[i], allocator);
|
||||
}
|
||||
|
||||
// get posix time
|
||||
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("timestamp", timestamp, allocator);
|
||||
document.AddMember("delay", arrayDelay, allocator);
|
||||
document.AddMember("doppler", arrayDoppler, allocator);
|
||||
document.AddMember("snr", arraySnr, allocator);
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
/// @brief Generate JSON of the detections and metadata.
|
||||
/// @return JSON string.
|
||||
std::string to_json();
|
||||
std::string to_json(uint64_t timestamp);
|
||||
|
||||
/// @brief Update JSON to convert delay bins to km.
|
||||
/// @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>
|
||||
std::string Map<T>::to_json()
|
||||
std::string Map<T>::to_json(uint64_t timestamp)
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
|
@ -144,10 +144,7 @@ std::string Map<T>::to_json()
|
|||
arrayDoppler.PushBack(doppler[i], allocator);
|
||||
}
|
||||
|
||||
// get posix time
|
||||
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("timestamp", timestamp, allocator);
|
||||
document.AddMember("nRows", nRows, allocator);
|
||||
document.AddMember("nCols", nCols, allocator);
|
||||
document.AddMember("noisePower", noisePower, allocator);
|
||||
|
|
|
@ -96,7 +96,7 @@ public:
|
|||
|
||||
/// @brief Generate JSON of the map and metadata.
|
||||
/// @return JSON string.
|
||||
std::string to_json();
|
||||
std::string to_json(uint64_t timestamp);
|
||||
|
||||
/// @brief Update JSON to convert delay bins to km.
|
||||
/// @param json Input JSON string with delay field.
|
||||
|
|
Loading…
Reference in a new issue