Ref T372, timestamp list fixed/added offset/delta t min/max/mean plus function in provider

This commit is contained in:
Klaus Basan
2018-09-30 22:33:41 +02:00
parent da3b5bb763
commit e87740cbd0
4 changed files with 65 additions and 22 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -43,8 +43,6 @@
using namespace BlackConfig;
namespace BlackMisc
{
template <class OBJ, class CONTAINER>
@@ -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<class OBJ, class CONTAINER>
MillisecondsMinMaxMean ITimestampWithOffsetObjectList<OBJ, CONTAINER>::getOffsetMinMaxMean() const
{
MillisecondsMinMaxMean mmm;
mmm.reset();
const CONTAINER &container = this->container();
if (container.size() < 1) { return mmm; }
mmm.max = std::numeric_limits<qint64>::min();
mmm.min = std::numeric_limits<qint64>::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 <class OBJ, class CONTAINER>
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::sortAdjustedLatestFirst()
{
@@ -593,7 +622,7 @@ namespace BlackMisc
OBJ ITimestampWithOffsetObjectList<OBJ, CONTAINER>::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<OBJ, CONTAINER>::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 <class OBJ, class CONTAINER>
void ITimestampWithOffsetObjectList<OBJ, CONTAINER>::setAdjustedSortHint(HintAdjustedTimestampSort hint)
{
m_tsAdjustedSortHint = hint;
this->container().m_tsAdjustedSortHint = hint;
}
// see here for the reason of thess forward instantiations

View File

@@ -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();