Ref T182, adjust scoring in livery, ICAO codes

This commit is contained in:
Klaus Basan
2017-11-06 03:50:40 +01:00
parent 0f133f6505
commit 7db5e9aea3
3 changed files with 38 additions and 38 deletions

View File

@@ -132,8 +132,7 @@ namespace BlackMisc
int CAircraftIcaoCode::calculateScore(const CAircraftIcaoCode &otherCode) const int CAircraftIcaoCode::calculateScore(const CAircraftIcaoCode &otherCode) const
{ {
const bool bothFromDb = this->isLoadedFromDb() && otherCode.isLoadedFromDb(); if (this->isDbEqual(otherCode)) { return 100; }
if (bothFromDb && otherCode.getDbKey() == this->getDbKey()) { return 100; }
int score = 0; int score = 0;
if (this->hasValidDesignator() && this->getDesignator() == otherCode.getDesignator()) if (this->hasValidDesignator() && this->getDesignator() == otherCode.getDesignator())
@@ -163,19 +162,22 @@ namespace BlackMisc
} }
} }
// score needs to higher than ranking // 0..65 so far
if (this->hasManufacturer() && otherCode.hasManufacturer()) if (this->hasManufacturer() && otherCode.hasManufacturer())
{ {
if (this->matchesManufacturer(otherCode.getManufacturer())) if (this->matchesManufacturer(otherCode.getManufacturer()))
{ {
score += 20; score += 10;
} }
else if (this->getManufacturer().contains(otherCode.getManufacturer(), Qt::CaseInsensitive)) else if (this->getManufacturer().contains(otherCode.getManufacturer(), Qt::CaseInsensitive))
{ {
score += 15; score += 5;
} }
} }
// 0..75 so far
if (this->isMilitary() == otherCode.isMilitary()) { score += 10; }
// 0..85 // 0..85
return score; return score;
} }

View File

@@ -362,21 +362,21 @@ namespace BlackMisc
int CAirlineIcaoCode::calculateScore(const CAirlineIcaoCode &otherCode) const int CAirlineIcaoCode::calculateScore(const CAirlineIcaoCode &otherCode) const
{ {
const bool bothFromDb = otherCode.isLoadedFromDb() && this->isLoadedFromDb(); if (this->isDbEqual(otherCode)) { return 100; }
if (bothFromDb && this->getDbKey() == otherCode.getDbKey()) const bool bothFromDb = this->isLoadedFromDb() && otherCode.isLoadedFromDb();
{
return 100;
}
int score = 0; int score = 0;
if (otherCode.hasValidDesignator() && this->getDesignator() == otherCode.getDesignator()) if (otherCode.hasValidDesignator() && this->getDesignator() == otherCode.getDesignator())
{ {
score += 60; score += 60;
} }
// only for DB values we check VA
if (bothFromDb && this->isVirtualAirline() == otherCode.isVirtualAirline()) if (bothFromDb && this->isVirtualAirline() == otherCode.isVirtualAirline())
{ {
score += 20; score += 20;
} }
// consider the various names
if (this->hasName() && this->getName() == otherCode.getName()) if (this->hasName() && this->getName() == otherCode.getName())
{ {
score += 20; score += 20;

View File

@@ -374,40 +374,38 @@ namespace BlackMisc
int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const int CLivery::calculateScore(const CLivery &otherLivery, bool preferColorLiveries) const
{ {
if (this->isDbEqual(otherLivery)) { return 100; }
// get a level
static const int sameAirlineIcaoLevel = CAirlineIcaoCode("DLH").calculateScore(CAirlineIcaoCode("DLH"));
Q_ASSERT_X(sameAirlineIcaoLevel == 60, Q_FUNC_INFO, "airline scoring changed");
int score = 0; int score = 0;
if (this->isLoadedFromDb() && otherLivery.isLoadedFromDb() && (this->getCombinedCode() == otherLivery.getCombinedCode())) const double colorMultiplier = 1.0 - this->getColorDistance(otherLivery);
if (this->isColorLivery() && otherLivery.isColorLivery())
{ {
return 100; // exact // 2 color liveries 25..85
score = 25;
score += 60 * colorMultiplier;
} }
else else if (this->isAirlineLivery() && otherLivery.isAirlineLivery())
{ {
const double multiplier = preferColorLiveries ? 0.10 : 0.35; // 2 airline liveries 0..85
score += multiplier * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode()); // 0..50 based on ICAO
// 0..25 based on color distance
// 0..10 based on mil.flag
// same ICAO at least means 30, max 50
score = 0.5 * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode());
score += 25 * colorMultiplier;
if (this->isMilitary() == otherLivery.isMilitary()) { score += 10; }
} }
else if ((this->isColorLivery() && otherLivery.isAirlineLivery()) || (otherLivery.isColorLivery() && this->isAirlineLivery()))
// max. 0..35 so far
if (score == 0) { return 0; }
// overrate non airline liveries / color liveries
if (this->isAirlineStandardLivery() && !preferColorLiveries) { score += 10; }
if (preferColorLiveries)
{ {
if (this->isColorLivery() || !this->hasValidAirlineDesignator()) // 1 airline, 1 color livery
{ // 0 .. 50
score += 20; // 25 is weaker as same ICAO code / 2 from above
} score = preferColorLiveries ? 25 : 0;
} score += 25 * colorMultiplier; // needs to be the same as in 2 airlines
// 0..45 so far
if (!this->hasValidColors()) { return score; }
const double cd = this->getColorDistance(otherLivery); // 0..1
if (cd == 0)
{
score += 40;
}
else
{
score += (1.0 - cd) * 25; // 0..25
} }
return score; return score;
} }