From e87740cbd0db209a040f7ddc076d33103a949576 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 30 Sep 2018 22:33:41 +0200 Subject: [PATCH] Ref T372, timestamp list fixed/added offset/delta t min/max/mean plus function in provider --- .../simulation/remoteaircraftprovider.cpp | 6 ++ .../simulation/remoteaircraftprovider.h | 4 ++ src/blackmisc/timestampobjectlist.cpp | 63 ++++++++++++++----- src/blackmisc/timestampobjectlist.h | 14 +++-- 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/src/blackmisc/simulation/remoteaircraftprovider.cpp b/src/blackmisc/simulation/remoteaircraftprovider.cpp index 4a5729b2e..cfa4e7166 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.cpp +++ b/src/blackmisc/simulation/remoteaircraftprovider.cpp @@ -85,6 +85,12 @@ namespace BlackMisc return situations[index]; } + MillisecondsMinMaxMean CRemoteAircraftProvider::remoteAircraftSituationsTimestampDifferenceMinMaxMean(const CCallsign &callsign) const + { + const CAircraftSituationList situations = this->remoteAircraftSituations(callsign); + return situations.getOffsetMinMaxMean(); + } + CAircraftSituationList CRemoteAircraftProvider::latestRemoteAircraftSituations() const { QReadLocker l(&m_lockSituations); diff --git a/src/blackmisc/simulation/remoteaircraftprovider.h b/src/blackmisc/simulation/remoteaircraftprovider.h index dffa008c0..3365623b6 100644 --- a/src/blackmisc/simulation/remoteaircraftprovider.h +++ b/src/blackmisc/simulation/remoteaircraftprovider.h @@ -96,6 +96,10 @@ namespace BlackMisc //! \threadsafe virtual Aviation::CAircraftSituationList remoteAircraftSituations(const Aviation::CCallsign &callsign) const = 0; + //! Average update time + //! \threadsafe + virtual MillisecondsMinMaxMean remoteAircraftSituationsTimestampDifferenceMinMaxMean(const Aviation::CCallsign &callsign) const = 0; + //! Rendered aircraft situations (per callsign and index) //! \remark if situation does not exist, an NULL situation is returned //! \param callsign diff --git a/src/blackmisc/timestampobjectlist.cpp b/src/blackmisc/timestampobjectlist.cpp index d5399a69f..ee08d39e7 100644 --- a/src/blackmisc/timestampobjectlist.cpp +++ b/src/blackmisc/timestampobjectlist.cpp @@ -43,8 +43,6 @@ using namespace BlackConfig; - - namespace BlackMisc { template @@ -346,11 +344,13 @@ namespace BlackMisc { MillisecondsMinMaxMean mmm; mmm.reset(); - if (this->container().size() < 2) { return mmm; } + const CONTAINER &container = this->container(); + if (container.size() < 2) { return mmm; } - if (m_tsSortHint == NoTimestampSortHint) + // Do not confuse with adjusted sort hint! + if (container.m_tsSortHint == NoTimestampSortHint) { - CONTAINER copy(this->container()); + CONTAINER copy(container); copy.sortLatestFirst(); copy.m_tsSortHint = TimestampLatestFirst; return copy.getTimestampDifferenceMinMaxMean(); @@ -362,24 +362,53 @@ namespace BlackMisc int c = 0; OBJ last; - for (const OBJ &object : this->container()) + for (const OBJ &object : container) { + if (c > 0) + { + const ITimestampBased &l = last; + const ITimestampBased &o = object; + const qint64 diff = l.getAbsTimeDifferenceMs(o); + if (diff > mmm.max) { mmm.max = diff; } + if (diff < mmm.min) { mmm.min = diff; } + mean += diff; + } c++; last = object; - if (c < 2) { continue; } - - const ITimestampBased &l = last; - const ITimestampBased &o = object; - const qint64 diff = l.getAbsTimeDifferenceMs(o); - if (diff > mmm.max) { mmm.max = diff; } - if (diff < mmm.min) { mmm.min = diff; } - mean += diff; } mmm.mean = mean / c; return mmm; } + template + MillisecondsMinMaxMean ITimestampWithOffsetObjectList::getOffsetMinMaxMean() const + { + MillisecondsMinMaxMean mmm; + mmm.reset(); + const CONTAINER &container = this->container(); + if (container.size() < 1) { return mmm; } + + mmm.max = std::numeric_limits::min(); + mmm.min = std::numeric_limits::max(); + qint64 mean = 0; + int c = 0; + + for (const ITimestampWithOffsetBased &object : container) + { + if (!object.hasNonZeroOffsetTime()) { continue; } + const qint64 os = object.getTimeOffsetMs(); + if (os > mmm.max) { mmm.max = os; } + if (os < mmm.min) { mmm.min = os; } + mean += os; + c++; + } + + if (c >0) { mmm.mean = mean / c; } + return mmm; + } + + template void ITimestampWithOffsetObjectList::sortAdjustedLatestFirst() { @@ -593,7 +622,7 @@ namespace BlackMisc OBJ ITimestampWithOffsetObjectList::latestAdjustedObject() const { if (this->container().isEmpty()) { return OBJ(); } - if (m_tsAdjustedSortHint == AdjustedTimestampLatestFirst) + if (this->container().m_tsAdjustedSortHint == AdjustedTimestampLatestFirst) { return this->container().front(); } @@ -605,7 +634,7 @@ namespace BlackMisc OBJ ITimestampWithOffsetObjectList::oldestAdjustedObject() const { if (this->container().isEmpty()) { return OBJ(); } - if (m_tsAdjustedSortHint == AdjustedTimestampLatestFirst) + if (this->container().m_tsAdjustedSortHint == AdjustedTimestampLatestFirst) { return this->container().back(); } @@ -646,7 +675,7 @@ namespace BlackMisc template void ITimestampWithOffsetObjectList::setAdjustedSortHint(HintAdjustedTimestampSort hint) { - m_tsAdjustedSortHint = hint; + this->container().m_tsAdjustedSortHint = hint; } // see here for the reason of thess forward instantiations diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index 9c046dc2f..4c394f82f 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -35,7 +35,7 @@ namespace BlackMisc void reset() { min = -1; max = -1; mean = -1;} //! As string - QString asString() const { static const QString s("Min: %1 Max: %2 Mean: %3"); return s.arg(min).arg(max).arg(mean, 0, 'f', 2); } + QString asString() const { static const QString s("Min: %1ms Max: %2ms Mean: %3ms"); return s.arg(min).arg(max).arg(mean, 0, 'f', 2); } }; //! List of objects with timestamp. @@ -146,13 +146,13 @@ namespace BlackMisc //! Adds a time to all values void addMsecs(qint64 msToAdd); - //! Difference of timestamp values - //! \cond timestamp list has to be sorted to get meaninful values - MillisecondsMinMaxMean getTimestampDifferenceMinMaxMean() const; - //! Set the hint void setSortHint(HintTimestampSort hint) { m_tsSortHint = hint; } + //! Difference of timestamp values + //! \cond timestamp list has to be sorted to get meaningful values + MillisecondsMinMaxMean getTimestampDifferenceMinMaxMean() const; + protected: //! Constructor ITimestampObjectList(); @@ -253,6 +253,10 @@ namespace BlackMisc //! Set the hint void setAdjustedSortHint(HintAdjustedTimestampSort hint); + //! Difference of timestamp values + //! \cond timestamp list has to be sorted to get meaningful values + MillisecondsMinMaxMean getOffsetMinMaxMean() const; + protected: //! Constructor ITimestampWithOffsetObjectList();