9#include "QStringBuilder"
24using namespace swift::misc::physical_quantities;
25using namespace swift::misc::math;
26using namespace swift::config;
30namespace swift::misc::aviation
35 qRegisterMetaType<CAircraftSituationChange::GuessedSceneryDeviation>();
40 bool alreadySortedLatestFirst,
bool calcStdDeviations)
42 if (situations.
size() < 2)
52 "Wrong sort order or NULL position");
59 m_situationsCount = situations.
size();
60 m_correspondingCallsign = cs;
76 if (sorted.
size() >= 3)
83 if (calcStdDeviations)
86 m_rotateUp = sorted.
front().
getPitch() > (m_pitchMean + m_pitchStdDev);
106 const bool vtol = model.
isVtol();
114 *details = QStringLiteral(
"No VTOL, push back");
124 *details = QStringLiteral(
"No VTOL, not moving => on ground");
137 if (!guessedRotateSpeed.
isNull())
141 SWIFT_VERIFY_X(validGuessedSpeed, Q_FUNC_INFO,
"Wrong guessed value for lift off");
142 if (!validGuessedSpeed)
146 sureRotateSpeed = guessedRotateSpeed * 1.25;
154 *details = QStringLiteral(
"max.pitch");
162 *details = QStringLiteral(
"max.bank");
186 *details = QStringLiteral(
"elevation on ground");
202 *details = QStringLiteral(
"rotating up detected");
211 *details = QStringLiteral(
"waiting for rotating up");
221 *details = QStringLiteral(
"const ascending");
236 if (!guessedRotateSpeed.
isNull())
244 *details = QStringLiteral(
"Guessing, max.guessed gs.") +
254 *details = QStringLiteral(
"Fall through");
263 if (m_elvStdDev.isNull())
272 if (m_altStdDev.isNull())
288 u
" | situations:" %
QString::number(m_situationsCount) % u
" | ts adj.: " %
290 QString::number(m_latestAdjustedTimestampMSecsSinceEpoch) % u
" | just takeoff: " %
300 u
"] | AGL delta: " % m_gndDistMean.valueRoundedWithUnit(1) % u
'/' %
301 m_gndDistStdDev.valueRoundedWithUnit(1) % u
" | std.dev/mean: pitch " %
302 m_pitchMean.valueRoundedWithUnit(1) % u
'/' % m_pitchStdDev.valueRoundedWithUnit(1) % u
" gs " %
303 m_gsMean.valueRoundedWithUnit(1) % u
'/' % m_gsStdDev.valueRoundedWithUnit(1) % u
" alt. " %
304 m_altMean.valueRoundedWithUnit(1) % u
'/' % m_altStdDev.valueRoundedWithUnit(1) % u
" elv. " %
305 m_elvMean.valueRoundedWithUnit(1) % u
'/' % m_elvStdDev.valueRoundedWithUnit(1);
322 case IndexCallsign:
return m_correspondingCallsign.propertyByIndex(index.
copyFrontRemoved());
357 case IndexCallsign: m_correspondingCallsign.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
358 case IndexSituationsCount: m_situationsCount = variant.
toInt();
break;
359 case IndexConstAscending: m_constAscending = variant.
toBool();
break;
360 case IndexConstDescending: m_constDescending = variant.
toBool();
break;
361 case IndexConstNotOnGround: m_constNotOnGround = variant.
toBool();
break;
362 case IndexConstOnGround: m_constOnGround = variant.
toBool();
break;
363 case IndexJustTakingOff: m_justTakeoff = variant.
toBool();
break;
364 case IndexJustTouchingDown: m_justTouchdown = variant.
toBool();
break;
365 case IndexRotatingUp: m_rotateUp = variant.
toBool();
break;
366 case IndexContainsPushBack: m_containsPushBack = variant.
toBool();
break;
368 case IndexAltitudeMean:
369 case IndexAltitudeStdDev:
370 case IndexElevationMean:
371 case IndexElevationStdDev:
break;
393 case IndexSituationsCount:
397 case IndexConstNotOnGround:
401 case IndexJustTouchingDown:
406 case IndexAltitudeMean:
407 return m_altMean.comparePropertyByIndex(index.
copyFrontRemoved(), compareValue.m_altMean);
408 case IndexAltitudeStdDev:
409 return m_altStdDev.comparePropertyByIndex(index.
copyFrontRemoved(), compareValue.m_altStdDev);
410 case IndexElevationMean:
411 return m_elvMean.comparePropertyByIndex(index.
copyFrontRemoved(), compareValue.m_elvMean);
412 case IndexElevationStdDev:
413 return m_elvStdDev.comparePropertyByIndex(index.
copyFrontRemoved(), compareValue.m_elvStdDev);
416 Q_ASSERT_X(
false, Q_FUNC_INFO,
"No comparison");
428 m_gsStdDev = gsStdDevMean.first;
429 m_gsMean = gsStdDevMean.second;
432 m_pitchStdDev = pitchStdDevMean.first;
433 m_pitchMean = pitchStdDevMean.second;
436 if (altValues.
size() == situations.
size())
444 if (elvValues.
size() == situations.
size())
450 if (altValues.
size() == situations.
size())
453 for (
int i = 0; i < altValues.
size(); i++)
455 const double delta = altValues[i] - elvValues[i];
462 const auto gndDistMinMax = std::minmax_element(gndDistance.
constBegin(), gndDistance.
constEnd());
463 const double gndDistMin = *gndDistMinMax.first;
464 const double gndDistMax = *gndDistMinMax.second;
467 this->guessSceneryDeviation(cg);
481 static const QString noInfo(
"no info");
482 static const QString completeOg(
"complete og");
483 static const QString wasOg(
"was og");
484 static const QString smallAGLDev(
"small AGL dev. near gnd.");
491 case NoDeviationInfo:
497 void CAircraftSituationChange::setSceneryDeviation(
const CLength &deviation,
const CLength &cg,
500 m_guessedSceneryDeviation = deviation;
502 this->setSceneryDeviationHint(hint);
505 void CAircraftSituationChange::guessSceneryDeviation(
const CLength &cg)
508 this->setSceneryDeviationHint(NoDeviationInfo);
509 if (m_gndDistStdDev.
isNull())
513 if (m_gndDistMean.
isNull())
522 if (m_gndDistStdDev <= maxDeviation)
528 this->setSceneryDeviation(m_gndDistMean, cg,
AllOnGround);
533 this->setSceneryDeviation(m_gndDistMean, cg,
WasOnGround);
536 if (!m_altStdDev.isNull() && m_altStdDev <= maxDeviation)
539 if (!m_maxGroundDistance.isNull() && m_maxGroundDistance < cg)
static CAngleUnit deg()
Degrees.
static bool isLocalDeveloperDebugBuild()
Local build for developers.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
size_type size() const
Returns number of elements in the sequence.
reference front()
Access the first element.
reference back()
Access the last element.
bool isEmpty() const
Synonym for empty.
qint64 getMSecsSinceEpoch() const
Timestamp as ms value.
qint64 m_timestampMSecsSinceEpoch
timestamp value
qint64 getAdjustedMSecsSinceEpoch() const
Timestamp with offset added for interpolation.
static bool canHandleIndex(CPropertyIndexRef index)
Can given index be handled.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
qint64 getTimeOffsetMs() const
Milliseconds to add to timestamp for interpolation.
int comparePropertyByIndex(CPropertyIndexRef index, const ITimestampWithOffsetBased &compareValue) const
Compare for index.
qint64 m_timeOffsetMs
offset time in ms
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getTimestampAndOffset(bool formatted) const
Timestamp and offset.
CONTAINER getSortedAdjustedLatestFirst() const
As sorted copy.
void guessModelParameters(physical_quantities::CLength &guessedCGOut, physical_quantities::CSpeed &guessedVRotateOut) const
Guess aircraft model parameters.
QString convertToQString(bool i18n=false) const
Cast as QString.
ColumnIndex
Properties by index.
bool hasSceneryDeviation() const
Scenery deviation available?
int getSituationsCount() const
Basend on n situations.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool containsPushBack() const
Contains any push back?
static const QString & guessedSceneryDeviationToString(GuessedSceneryDeviation hint)
The enum as string.
bool isConstDescending() const
Constantly descending?
bool isConstAscending() const
Constantly ascending?
bool hasAltitudeDevWithinAllowedRange() const
Altitude within CAircraftSituation::allowedAltitudeDeviation range.
bool wasConstNotOnGround() const
Was not on ground (without latest situation)?
bool hasElevationDevWithinAllowedRange() const
Elevation within CAircraftSituation::allowedAltitudeDeviation range.
bool isConstAccelerating() const
Constantly accelerating?
const CCallsign & getCallsign() const
Get callsign.
static void registerMetadata()
Register metadata.
bool isJustTakingOff() const
Is just taking off?
CAircraftSituationChange()=default
Default constructor.
GuessedSceneryDeviation
Hint about the guessed scenery deviation.
@ AllOnGround
based on all situations on ground
@ WasOnGround
was on ground except last situation
@ SmallAGLDeviationNearGround
"Almost const AGL" near Ground
bool isConstDecelarating() const
Constantly decelarating?
bool isRotatingUp() const
Is rotating up?
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
bool isJustTouchingDown() const
Is just touching down?
int comparePropertyByIndex(CPropertyIndexRef index, const CAircraftSituationChange &compareValue) const
Compare for index.
const QString & getSceneryDeviationHintAsString() const
Scenery deviation hint hint as string.
bool isConstOnGround() const
Are all situations on ground?
bool isConstNotOnGround() const
Are all situations not on ground?
static const CAircraftSituationChange & null()
NULL object.
bool guessOnGround(CAircraftSituation &situation, const simulation::CAircraftModel &model) const
Guess on ground flag.
bool wasConstOnGround() const
Was on ground (without latest situation)?
bool calculateStdDeviations(const CAircraftSituationList &situations, const physical_quantities::CLength &cg)
Calculate the standard deviiations.
Value object encapsulating information of an aircraft's situation.
const physical_quantities::CLength & getCG() const
Get CG if any.
bool shouldGuessOnGround() const
Should we guess on ground?
const physical_quantities::CAngle & getBank() const
Get bank (angle).
bool hasCG() const
Has CG set?
physical_quantities::CLength getGroundDistance(const physical_quantities::CLength ¢erOfGravity) const
Distance to ground, null if impossible to calculate.
void setOnGroundInfo(const aviation::COnGroundInfo &info)
Set the on ground info.
const physical_quantities::CAngle & getPitch() const
Get pitch.
const physical_quantities::CSpeed & getGroundSpeed() const
Get ground speed.
bool isMoving() const
Is moving? Means ground speed > epsilon.
const CCallsign & getCallsign() const
Corresponding callsign.
static const physical_quantities::CLength & allowedAltitudeDeviation()
Within this range deviation is so small we consider values "almost constant".
List of aircraft situations.
bool isJustTouchingDown(bool alreadySortedLatestFirst=false) const
Is just touching down?
CAircraftSituationList withoutFrontSituation() const
Remove the first situation.
bool isConstAccelerating(bool alreadySortedLatestFirst=false) const
Constantly accelerating?
bool isConstNotOnGround() const
Are all situations not on ground?
physical_quantities::CAnglePair pitchStandardDeviationAndMean() const
Pitch angles standard deviation and mean.
QList< double > elevationValues(const physical_quantities::CLengthUnit &unit) const
All elevation values.
bool isConstDecelarating(bool alreadySortedLatestFirst=false) const
Constantly decelarating?
bool isConstDescending(bool alreadySortedLatestFirst=false) const
Constantly descending?
bool isConstOnGround() const
Are all situations on ground?
bool isRotatingUp(bool alreadySortedLatestFirst=false) const
Is rotating up?
bool isJustTakingOff(bool alreadySortedLatestFirst=false) const
Is just taking off?
QList< double > altitudeValues(const physical_quantities::CLengthUnit &unit) const
All altitude values.
bool isSortedAdjustedLatestFirstWithoutNullPositions() const
Latest first and no null positions?
bool isConstAscending(bool alreadySortedLatestFirst=false) const
Constantly ascending?
bool containsPushBack() const
Contains any push back?
physical_quantities::CSpeedPair groundSpeedStandardDeviationAndMean() const
Ground speed standard deviation and mean.
Altitude as used in aviation, can be AGL or MSL altitude.
static physical_quantities::CLengthUnit defaultUnit()
Default unit for calculations.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized).
Information about the ground status.
@ OnGroundByGuessing
weakest
@ NotSetGroundDetails
not set or unknown if correct (e.g.
void setOnGroundDetails(OnGroundDetails details)
When source of knowledge changes.
IsOnGround getOnGround() const
Is on ground?
static QPair< double, double > standardDeviationAndMean(const QList< double > &values)
Standard deviation (first) and mean (second).
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
Physical unit length (length).
static CLengthUnit ft()
Foot ft.
bool isNegativeWithEpsilonConsidered() const
Value <= 0 epsilon considered.
bool isNull() const
Is quantity null?
double value(MU unit) const
Value in given unit.
static const CSpeed & null()
QString valueRoundedWithUnit(const MU &unit, int digits=-1, bool withGroupSeparator=false, bool i18n=false) const
Value to QString with the given unit, e.g. "5.00m".
static CSpeedUnit km_h()
Kilometer/hour km/h.
static CSpeedUnit kts()
Knots.
Aircraft model (used by another pilot, my models on disk).
bool isVtol() const
VTOL aircraft?
const physical_quantities::CLength & getCG() const
Get center of gravity.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
int compare(T a, T b)
Compare arithmetic values.
SWIFT_MISC_EXPORT const QString & boolToYesNo(bool v)
Bool to yes/no.
QList< T >::const_iterator constBegin() const const
QList< T >::const_iterator constEnd() const const
void push_back(QList< T >::parameter_type value)
qsizetype size() const const
QString number(double n, char format, int precision)
QVariant fromValue(T &&value)
bool toBool() const const
int toInt(bool *ok) const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.