mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 16:56:53 +08:00
Ref T261, aircraft changes class reflecting delta/average values
* math utils for standard deviation etc. * CAircraftSituationChange value class
This commit is contained in:
committed by
Roland Winklmeier
parent
d1f5635bd1
commit
784cf29af5
212
src/blackmisc/aviation/aircraftsituationchange.cpp
Normal file
212
src/blackmisc/aviation/aircraftsituationchange.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
/* Copyright (C) 2018
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/aviation/aircraftsituationchange.h"
|
||||
#include "blackmisc/aviation/aircraftsituationlist.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/pq/length.h"
|
||||
#include "blackmisc/pq/angle.h"
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/math/mathutils.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/verify.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackconfig/buildconfig.h"
|
||||
#include "QStringBuilder"
|
||||
#include <QtGlobal>
|
||||
#include <QPair>
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Math;
|
||||
using namespace BlackConfig;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
CAircraftSituationChange::CAircraftSituationChange() {}
|
||||
|
||||
CAircraftSituationChange::CAircraftSituationChange(const CAircraftSituation &s1, const CAircraftSituation &s2) :
|
||||
CAircraftSituationChange::CAircraftSituationChange(CAircraftSituationList({s1, s2})) {}
|
||||
|
||||
CAircraftSituationChange::CAircraftSituationChange(const CAircraftSituationList &situations, bool alreadySortedLatestFirst, bool calcStdDeviations)
|
||||
{
|
||||
if (situations.size() < 2) { return; }
|
||||
const CAircraftSituationList sorted(alreadySortedLatestFirst ? situations : situations.getSortedAdjustedLatestFirst());
|
||||
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
Q_ASSERT_X(sorted.isSortedAdjustedLatestFirstWithoutNullPositions(), Q_FUNC_INFO, "Wrong sort order or NULL position");
|
||||
}
|
||||
|
||||
const CAircraftSituation latest(sorted.front());
|
||||
const CAircraftSituation oldest(sorted.back());
|
||||
const CCallsign cs(latest.getCallsign());
|
||||
|
||||
m_situationsCount = situations.size();
|
||||
m_correspondingCallsign = cs;
|
||||
m_timestampMSecsSinceEpoch = latest.getMSecsSinceEpoch();
|
||||
m_timeOffsetMs = latest.getTimeOffsetMs();
|
||||
m_oldestTimestampMSecsSinceEpoch = oldest.getMSecsSinceEpoch();
|
||||
m_latestAdjustedTimestampMSecsSinceEpoch = latest.getAdjustedMSecsSinceEpoch();
|
||||
m_oldestAdjustedTimestampMSecsSinceEpoch = oldest.getAdjustedMSecsSinceEpoch();
|
||||
m_constAscending = sorted.isConstAscending(true);
|
||||
m_constDescending = sorted.isConstDescending(true);
|
||||
m_constOnGround = sorted.isConstOnGround();
|
||||
m_constNotOnGround = sorted.isConstNotOnGround();
|
||||
m_justTakeoff = sorted.isJustTakingOff(true);
|
||||
m_justTouchdown = sorted.isJustTouchingDown(true);
|
||||
m_constAccelerating = sorted.isConstAccelerating(true);
|
||||
m_constDecelerating = sorted.isConstDecelarating(true);
|
||||
m_containsPushBack = sorted.containsPushBack();
|
||||
|
||||
if (sorted.size() >= 3)
|
||||
{
|
||||
const CAircraftSituationList sortedWithout = sorted.withoutFrontSituation();
|
||||
m_wasNotOnGround = sortedWithout.isConstNotOnGround();
|
||||
m_wasOnGround = sortedWithout.isConstOnGround();
|
||||
}
|
||||
|
||||
if (calcStdDeviations)
|
||||
{
|
||||
this->calculateStdDeviations(situations);
|
||||
m_rotateUp = sorted.front().getPitch() > (m_pitchMean + m_pitchStdDev);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_rotateUp = sorted.isRotatingUp(true);
|
||||
}
|
||||
}
|
||||
|
||||
QString CAircraftSituationChange::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
static const QString null("null");
|
||||
if (this->isNull()) { return null; }
|
||||
return QStringLiteral("CS: '") % this->getCallsign().asString() %
|
||||
QStringLiteral(" ' ts: ") % this->getTimestampAndOffset(true) %
|
||||
QStringLiteral(" | situations:") % QString::number(m_situationsCount) %
|
||||
QStringLiteral(" | ts adj.: ") % QString::number(m_oldestAdjustedTimestampMSecsSinceEpoch) % QStringLiteral("-") % QString::number(m_latestAdjustedTimestampMSecsSinceEpoch) %
|
||||
QStringLiteral(" | just takeoff: ") % boolToYesNo(this->isJustTakingOff()) % QStringLiteral(" just touchdown: ") % boolToYesNo(this->isJustTouchingDown()) %
|
||||
QStringLiteral(" | all gnd: ") % boolToYesNo(this->isConstOnGround()) % QStringLiteral("/ ") % boolToYesNo(this->wasConstOnGround()) %
|
||||
QStringLiteral(" | all not gnd: ") % boolToYesNo(this->isConstNotOnGround()) % QStringLiteral("/ ") % boolToYesNo(this->wasConstNotOnGround()) %
|
||||
QStringLiteral(" | ascending: ") % boolToYesNo(this->isConstAscending()) % QStringLiteral(" descending: ") % boolToYesNo(this->isConstDescending()) %
|
||||
QStringLiteral(" | accelerating.: ") % boolToYesNo(this->isConstAccelerating()) % QStringLiteral(" decelarating: ") % boolToYesNo(this->isConstDecelarating()) %
|
||||
QStringLiteral(" | rotate up: ") % boolToYesNo(this->isRotatingUp()) %
|
||||
QStringLiteral(" | push back: ") % boolToYesNo(this->containsPushBack()) %
|
||||
QStringLiteral(" | alt.delta: ") % m_altAglMean.valueRoundedWithUnit(1) % QStringLiteral("/") % m_altAglStdDev.valueRoundedWithUnit(1) %
|
||||
QStringLiteral(" | std.dev: pitch ") % m_pitchMean.valueRoundedWithUnit(1) % QStringLiteral("/") % m_pitchStdDev.valueRoundedWithUnit(1) %
|
||||
QStringLiteral(" gs ") % m_gsMean.valueRoundedWithUnit(1) % QStringLiteral("/") % m_gsStdDev.valueRoundedWithUnit(1) %
|
||||
QStringLiteral(" alt. ") % m_altMean.valueRoundedWithUnit(1) % QStringLiteral("/") % m_altStdDev.valueRoundedWithUnit(1) %
|
||||
QStringLiteral(" elv. ") % m_elvMean.valueRoundedWithUnit(1) % QStringLiteral("/") % m_elvStdDev.valueRoundedWithUnit(1);
|
||||
}
|
||||
|
||||
CVariant CAircraftSituationChange::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (ITimestampWithOffsetBased::canHandleIndex(index)) { return ITimestampWithOffsetBased::propertyByIndex(index); }
|
||||
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCallsign: return m_correspondingCallsign.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexConstAscending: return CVariant::from(m_constAscending);
|
||||
case IndexConstDescending: return CVariant::from(m_constDescending);
|
||||
case IndexConstNotOnGround: return CVariant::from(m_constNotOnGround);
|
||||
case IndexConstOnGround: return CVariant::from(m_constOnGround);
|
||||
case IndexIsNull: return CVariant::from(this->isNull());
|
||||
case IndexJustTakingOff: return CVariant::from(m_justTakeoff);
|
||||
case IndexJustTouchingDown: return CVariant::from(m_justTouchdown);
|
||||
case IndexRotatingUp: return CVariant::from(m_rotateUp);
|
||||
case IndexContainsPushBack: return CVariant::from(m_containsPushBack);
|
||||
default: return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftSituationChange::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAircraftSituationChange>(); return; }
|
||||
if (ITimestampWithOffsetBased::canHandleIndex(index)) { ITimestampWithOffsetBased::setPropertyByIndex(index, variant); return; }
|
||||
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexCallsign: m_correspondingCallsign.setPropertyByIndex(index.copyFrontRemoved(), variant); break;
|
||||
case IndexConstAscending: m_constAscending = variant.toBool(); break;
|
||||
case IndexConstDescending: m_constDescending = variant.toBool(); break;
|
||||
case IndexConstNotOnGround: m_constNotOnGround = variant.toBool(); break;
|
||||
case IndexConstOnGround: m_constOnGround = variant.toBool(); break;
|
||||
case IndexJustTakingOff: m_justTakeoff = variant.toBool(); break;
|
||||
case IndexJustTouchingDown: m_justTouchdown = variant.toBool(); break;
|
||||
case IndexRotatingUp: m_rotateUp = variant.toBool(); break;
|
||||
case IndexContainsPushBack: m_containsPushBack = variant.toBool(); break;
|
||||
case IndexIsNull: break;
|
||||
default: CValueObject::setPropertyByIndex(index, variant); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CAircraftSituationChange::calculateStdDeviations(const CAircraftSituationList &situations)
|
||||
{
|
||||
if (situations.isEmpty()) { return false; }
|
||||
|
||||
const QList<double> altValues = situations.altitudeValues(CLengthUnit::ft());
|
||||
if (altValues.size() == situations.size())
|
||||
{
|
||||
const QPair<double, double> altFt = CMathUtils::standardDeviationAndMean(altValues);
|
||||
m_altStdDev = CAltitude(altFt.first, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
m_altMean = CAltitude(altFt.second, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
}
|
||||
|
||||
const QList<double> elvValues = situations.elevationValues(CLengthUnit::ft());
|
||||
if (elvValues.size() == situations.size())
|
||||
{
|
||||
const QPair<double, double> elvFt = CMathUtils::standardDeviationAndMean(elvValues);
|
||||
m_elvStdDev = CAltitude(elvFt.first, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
m_elvMean = CAltitude(elvFt.second, CAltitude::MeanSeaLevel, CLengthUnit::ft());
|
||||
|
||||
if (altValues.size() == situations.size())
|
||||
{
|
||||
QList<double> altElvDeltas;
|
||||
for (int i = 0; i < altValues.size(); i++)
|
||||
{
|
||||
const double delta = altValues[i] - elvValues[i];
|
||||
altElvDeltas.push_back(delta);
|
||||
}
|
||||
const QPair<double, double> deltaFt = CMathUtils::standardDeviationAndMean(altElvDeltas);
|
||||
m_altAglStdDev = CLength(deltaFt.first, CLengthUnit::ft());
|
||||
m_altAglMean = CLength(deltaFt.second, CLengthUnit::ft());
|
||||
}
|
||||
}
|
||||
|
||||
const QList<double> gsValues = situations.groundSpeedValues(CSpeedUnit::kts());
|
||||
if (gsValues.size() == situations.size())
|
||||
{
|
||||
const QPair<double, double> gsKts = CMathUtils::standardDeviationAndMean(gsValues);
|
||||
m_gsStdDev = CSpeed(gsKts.first, CSpeedUnit::kts());
|
||||
m_gsMean = CSpeed(gsKts.second, CSpeedUnit::kts());
|
||||
}
|
||||
|
||||
const QList<double> pitchValues = situations.pitchValues(CAngleUnit::deg());
|
||||
if (gsValues.size() == situations.size())
|
||||
{
|
||||
const QPair<double, double> pitchDeg = CMathUtils::standardDeviationAndMean(pitchValues);
|
||||
m_pitchStdDev = CAngle(pitchDeg.first, CAngleUnit::deg());
|
||||
m_pitchMean = CAngle(pitchDeg.second, CAngleUnit::deg());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const CAircraftSituationChange &CAircraftSituationChange::null()
|
||||
{
|
||||
static const CAircraftSituationChange null;
|
||||
return null;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user