refs #895, also log when parts are empty

* added empty flag
* move logging into own function (because it is called in multiple places now)
This commit is contained in:
Klaus Basan
2017-03-04 21:51:49 +01:00
committed by Mathew Sutcliffe
parent aa14c564b0
commit a27717cf8b
4 changed files with 26 additions and 10 deletions

View File

@@ -228,7 +228,7 @@ namespace BlackMisc
QLatin1String("<td>") % log.callsign.asString() % QLatin1String("</td>") %
QLatin1String("<td>") % msSinceEpochToTime(log.timestamp) % QLatin1String("</td>") %
(changedParts ? QLatin1String("<td class=\"changed\">*</td>") : QLatin1String("<td></td>")) %
QLatin1String("<td>") % log.parts.toQString() % QLatin1String("</td>");
QLatin1String("<td>") % (log.empty ? QLatin1String("empty") : log.parts.toQString()) % QLatin1String("</td>");
}
tableRows += QLatin1String("</tbody>\n");
return QLatin1String("<table class=\"small\">\n") % tableHeader % tableRows % QLatin1String("</table>\n");

View File

@@ -78,6 +78,7 @@ namespace BlackMisc
qint64 timestamp = -1; //!< current timestamp
BlackMisc::Aviation::CCallsign callsign; //!< current callsign
BlackMisc::Aviation::CAircraftParts parts; //!< parts to be logged
bool empty = false;
};
//! Log current interpolation cycle, only stores in memory, for performance reasons

View File

@@ -182,6 +182,14 @@ namespace BlackMisc
partsStatus.reset();
if (currentTimeMsSinceEpoch < 0) { currentTimeMsSinceEpoch = QDateTime::currentMSecsSinceEpoch(); }
// log for empty parts aircraft parts
if (m_aircraftParts.isEmpty())
{
static const CAircraftParts emptyParts;
this->logParts(currentTimeMsSinceEpoch, emptyParts, true, log);
emptyParts;
}
// find the first parts not in the correct order, keep only the parts before that one
const auto end = std::is_sorted_until(m_aircraftParts.begin(), m_aircraftParts.end(), [](auto && a, auto && b) { return b.getAdjustedMSecsSinceEpoch() < a.getAdjustedMSecsSinceEpoch(); });
const auto validParts = makeRange(m_aircraftParts.begin(), end);
@@ -226,18 +234,22 @@ namespace BlackMisc
}
while (false);
if (m_logger && log)
{
CInterpolationLogger::PartsLog log;
log.callsign = m_callsign;
log.timestamp = currentTimeMsSinceEpoch;
log.parts = currentParts;
m_logger->logParts(log);
}
this->logParts(currentTimeMsSinceEpoch, currentParts, false, log);
return currentParts;
}
template<typename Derived>
void CInterpolator<Derived>::logParts(qint64 timestamp, const CAircraftParts &parts, bool empty, bool log)
{
if (!log || !m_logger) { return; }
CInterpolationLogger::PartsLog logInfo;
logInfo.callsign = m_callsign;
logInfo.timestamp = timestamp;
logInfo.parts = parts;
logInfo.empty = empty;
m_logger->logParts(logInfo);
}
template <typename Derived>
void CInterpolator<Derived>::addAircraftSituation(const CAircraftSituation &situation)
{

View File

@@ -88,6 +88,9 @@ namespace BlackMisc
private:
CInterpolationLogger *m_logger = nullptr;
//! Log parts
void logParts(qint64 timestamp, const Aviation::CAircraftParts &parts, bool empty, bool log);
Derived *derived() { return static_cast<Derived *>(this); }
const Derived *derived() const { return static_cast<const Derived *>(this); }
};