Add output to JSON for tracker

This commit is contained in:
30hours 2023-12-27 09:17:43 +00:00
parent 955e6b366f
commit 8305c2d269
3 changed files with 44 additions and 30 deletions

View file

@ -45,6 +45,7 @@
<li class="py-1 title">API</li> <li class="py-1 title">API</li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/map">Map data</a></li> <li class="py-1"><a class="text-reset text-decoration-none" href="/api/map">Map data</a></li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/detection">Detection data</a></li> <li class="py-1"><a class="text-reset text-decoration-none" href="/api/detection">Detection data</a></li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/tracker">Tracker data</a></li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/timing">Timing data</a></li> <li class="py-1"><a class="text-reset text-decoration-none" href="/api/timing">Timing data</a></li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/iqdata">IQ metadata</a></li> <li class="py-1"><a class="text-reset text-decoration-none" href="/api/iqdata">IQ metadata</a></li>
<li class="py-1"><a class="text-reset text-decoration-none" href="/api/timestamp">Latest timestamp</a></li> <li class="py-1"><a class="text-reset text-decoration-none" href="/api/timestamp">Latest timestamp</a></li>

View file

@ -53,25 +53,12 @@ void Track::set_nInactive(uint64_t index, uint64_t n)
nInactive.at(index) = n; nInactive.at(index) = n;
} }
uint64_t Track::get_nActive() uint64_t Track::get_nState(std::string _state)
{ {
uint64_t n = 0; uint64_t n = 0;
for (size_t i = 0; i < id.size(); i++) for (size_t i = 0; i < id.size(); i++)
{ {
if (get_state(i) == STATE_ACTIVE) if (get_state(i) == _state)
{
n++;
}
}
return n;
}
uint64_t Track::get_nTentative()
{
uint64_t n = 0;
for (size_t i = 0; i < id.size(); i++)
{
if (get_state(i) == STATE_TENTATIVE)
{ {
n++; n++;
} }
@ -160,23 +147,52 @@ std::string Track::to_json(uint64_t timestamp)
document.SetObject(); document.SetObject();
rapidjson::Document::AllocatorType &allocator = document.GetAllocator(); rapidjson::Document::AllocatorType &allocator = document.GetAllocator();
// store array for non-tentative tracks // store track data
rapidjson::Value arrayId(rapidjson::kArrayType); rapidjson::Value dataArray(rapidjson::kArrayType);
rapidjson::Value value;
for (int i = 0; i < get_n(); i++) for (int i = 0; i < get_n(); i++)
{ {
if (get_state(i) != STATE_TENTATIVE) if (get_state(i) != STATE_TENTATIVE)
{ {
value = rapidjson::StringRef(id.at(i).c_str()); rapidjson::Value object1(rapidjson::kObjectType);
arrayId.PushBack(value, allocator); object1.AddMember("id", rapidjson::Value(id.at(i).c_str(),
document.GetAllocator()).Move(), document.GetAllocator());
object1.AddMember("state", rapidjson::Value(
state.at(i).at(state.at(i).size()-1).c_str(),
document.GetAllocator()).Move(), document.GetAllocator());
object1.AddMember("delay",
current.at(i).get_delay().at(0),
document.GetAllocator());
object1.AddMember("doppler",
current.at(i).get_doppler().at(0),
document.GetAllocator());
object1.AddMember("acceleration",
acceleration.at(i), document.GetAllocator());
object1.AddMember("n", associated.at(i).size(),
document.GetAllocator());
rapidjson::Value associatedDelay(rapidjson::kArrayType);
rapidjson::Value associatedDoppler(rapidjson::kArrayType);
for (size_t j = 0; j < associated.at(i).size(); j++)
{
associatedDelay.PushBack(associated.at(i).at(j).get_delay().at(0),
document.GetAllocator());
associatedDoppler.PushBack(associated.at(i).at(j).get_doppler().at(0),
document.GetAllocator());
}
object1.AddMember("associated_delay",
associatedDelay, document.GetAllocator());
object1.AddMember("associated_doppler",
associatedDoppler, document.GetAllocator());
dataArray.PushBack(object1, document.GetAllocator());
} }
} }
document.AddMember("timestamp", timestamp, allocator); document.AddMember("timestamp", timestamp, allocator);
document.AddMember("n", get_n(), allocator); document.AddMember("n", get_n(), allocator);
document.AddMember("nActive", get_nActive(), allocator); document.AddMember("nTentative", get_nState(STATE_TENTATIVE), allocator);
document.AddMember("nTentative", get_nTentative(), allocator); document.AddMember("nAssociated", get_nState(STATE_ASSOCIATED), allocator);
document.AddMember("id", arrayId, allocator); document.AddMember("nActive", get_nState(STATE_ACTIVE), allocator);
document.AddMember("nCoasting", get_nState(STATE_COASTING), allocator);
document.AddMember("data", dataArray, document.GetAllocator());
rapidjson::StringBuffer strbuf; rapidjson::StringBuffer strbuf;
rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf); rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);

View file

@ -97,13 +97,10 @@ public:
/// @return Void. /// @return Void.
void set_nInactive(uint64_t index, uint64_t n); void set_nInactive(uint64_t index, uint64_t n);
/// @brief Get number of active tracks. /// @brief Get number of tracks with specified state.
/// @return Number of active tracks. /// @param state State to check.
uint64_t get_nActive(); /// @return Number of tracks with specified state.
uint64_t get_nState(std::string state);
/// @brief Get number of tentative tracks.
/// @return Number of tentative tracks.
uint64_t get_nTentative();
/// @brief Get number of total tracks. /// @brief Get number of total tracks.
/// @return Number of total tracks. /// @return Number of total tracks.