mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-28 20:25:34 +08:00
refs #825, utility functions
* allow to prefer color liveries (idea: when no airline is found, a neutral livery looks better) * pick randomly among equal scores
This commit is contained in:
@@ -393,7 +393,7 @@ namespace BlackMisc
|
|||||||
return this->getCombinedCodePlusInfo();
|
return this->getCombinedCodePlusInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CLivery::calculateScore(const CLivery &otherLivery) const
|
int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const
|
||||||
{
|
{
|
||||||
int score = 0;
|
int score = 0;
|
||||||
if (this->isLoadedFromDb() && otherLivery.isLoadedFromDb() && (this->getCombinedCode() == otherLivery.getCombinedCode()))
|
if (this->isLoadedFromDb() && otherLivery.isLoadedFromDb() && (this->getCombinedCode() == otherLivery.getCombinedCode()))
|
||||||
@@ -402,14 +402,24 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
score += 0.35 * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode());
|
const double multiplier = preferColorLiveries ? 0.10 : 0.35;
|
||||||
|
score += multiplier * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0..50 so far
|
// max. 0..35 so far
|
||||||
if (score == 0) { return 0; }
|
if (score == 0) { return 0; }
|
||||||
if (this->isAirlineStandardLivery()) { score += 10; }
|
if (this->isAirlineStandardLivery() && !preferColorLiveries) { score += 10; }
|
||||||
|
|
||||||
// 0..60 so far
|
// overrate non airline liveries
|
||||||
|
if (preferColorLiveries)
|
||||||
|
{
|
||||||
|
if (this->isColorLivery() || !this->hasValidAirlineDesignator())
|
||||||
|
{
|
||||||
|
score += 20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0..45 so far
|
||||||
if (!this->hasValidColors()) { return score; }
|
if (!this->hasValidColors()) { return score; }
|
||||||
const double cd = this->getColorDistance(otherLivery); // 0..1
|
const double cd = this->getColorDistance(otherLivery); // 0..1
|
||||||
if (cd == 0)
|
if (cd == 0)
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Score by comparison to another livery 0..100
|
//! Score by comparison to another livery 0..100
|
||||||
//! \remark normally used with liveries preselect by airline ICAO code
|
//! \remark normally used with liveries preselect by airline ICAO code
|
||||||
int calculateScore(const CLivery &otherLivery) const;
|
int calculateScore(const CLivery &otherLivery, bool preferColorLiveries = false) const;
|
||||||
|
|
||||||
//! Object from JSON
|
//! Object from JSON
|
||||||
static CLivery fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString("liv_"));
|
static CLivery fromDatabaseJson(const QJsonObject &json, const QString &prefix = QString("liv_"));
|
||||||
|
|||||||
@@ -629,10 +629,10 @@ namespace BlackMisc
|
|||||||
this->m_modelString.startsWith(modelString, sensitivity);
|
this->m_modelString.startsWith(modelString, sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CAircraftModel::calculateScore(const CAircraftModel &compareModel) const
|
int CAircraftModel::calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries) const
|
||||||
{
|
{
|
||||||
int score = this->getAircraftIcaoCode().calculateScore(compareModel.getAircraftIcaoCode());
|
int score = this->getAircraftIcaoCode().calculateScore(compareModel.getAircraftIcaoCode());
|
||||||
score += this->getLivery().calculateScore(compareModel.getLivery());
|
score += this->getLivery().calculateScore(compareModel.getLivery(), preferColorLiveries);
|
||||||
return 0.5 * score;
|
return 0.5 * score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -356,7 +356,7 @@ namespace BlackMisc
|
|||||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||||
|
|
||||||
//! Calculate score
|
//! Calculate score
|
||||||
int calculateScore(const CAircraftModel &compareModel) const;
|
int calculateScore(const CAircraftModel &compareModel, bool preferColorLiveries) const;
|
||||||
|
|
||||||
//! Validate
|
//! Validate
|
||||||
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
||||||
|
|||||||
@@ -58,6 +58,16 @@ namespace BlackMisc
|
|||||||
return this->contains(&CAircraftModel::getCallsign, callsign);
|
return this->contains(&CAircraftModel::getCallsign, callsign);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAircraftModelList::containsCombinedType(const QString &combinedType) const
|
||||||
|
{
|
||||||
|
if (combinedType.isEmpty()) { return false; }
|
||||||
|
const QString ct(combinedType.toUpper().trimmed());
|
||||||
|
return this->containsBy([ & ](const CAircraftModel & model)
|
||||||
|
{
|
||||||
|
return model.getAircraftIcaoCode().getCombinedType() == ct;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool CAircraftModelList::containsModelsWithAircraftAndAirlineDesignator(const QString &aircraftDesignator, const QString &airlineDesignator) const
|
bool CAircraftModelList::containsModelsWithAircraftAndAirlineDesignator(const QString &aircraftDesignator, const QString &airlineDesignator) const
|
||||||
{
|
{
|
||||||
return this->contains(&CAircraftModel::getAircraftIcaoCodeDesignator, aircraftDesignator, &CAircraftModel::getAirlineIcaoCodeDesignator, airlineDesignator);
|
return this->contains(&CAircraftModel::getAircraftIcaoCodeDesignator, aircraftDesignator, &CAircraftModel::getAirlineIcaoCodeDesignator, airlineDesignator);
|
||||||
@@ -531,9 +541,12 @@ namespace BlackMisc
|
|||||||
ScoredModels CAircraftModelList::scoreFull(const CAircraftModel &remoteModel, bool ignoreZeroScores) const
|
ScoredModels CAircraftModelList::scoreFull(const CAircraftModel &remoteModel, bool ignoreZeroScores) const
|
||||||
{
|
{
|
||||||
ScoredModels scoreMap;
|
ScoredModels scoreMap;
|
||||||
|
// prefer colors if there is no airline
|
||||||
|
const bool hasAirlineDesignator = remoteModel.hasAirlineDesignator() && this->contains(&CAircraftModel::getAirlineIcaoCodeDesignator, remoteModel.getAirlineIcaoCodeDesignator());
|
||||||
|
const bool preferColorLiveries = !hasAirlineDesignator;
|
||||||
for (const CAircraftModel &model : *this)
|
for (const CAircraftModel &model : *this)
|
||||||
{
|
{
|
||||||
const int score = model.calculateScore(remoteModel);
|
const int score = model.calculateScore(remoteModel, preferColorLiveries);
|
||||||
if (ignoreZeroScores && score < 1) { continue; }
|
if (ignoreZeroScores && score < 1) { continue; }
|
||||||
scoreMap.insertMulti(score, model);
|
scoreMap.insertMulti(score, model);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,9 @@ namespace BlackMisc
|
|||||||
//! Contains model for callsign
|
//! Contains model for callsign
|
||||||
bool containsCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
|
bool containsCallsign(const BlackMisc::Aviation::CCallsign &callsign) const;
|
||||||
|
|
||||||
|
//! Contains given combined type
|
||||||
|
bool containsCombinedType(const QString &combinedType) const;
|
||||||
|
|
||||||
//! Contains any model with aircraft and airline designator
|
//! Contains any model with aircraft and airline designator
|
||||||
bool containsModelsWithAircraftAndAirlineDesignator(const QString &aircraftDesignator, const QString &airlineDesignator) const;
|
bool containsModelsWithAircraftAndAirlineDesignator(const QString &aircraftDesignator, const QString &airlineDesignator) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user