diff --git a/src/blackmisc/aviation/aircrafticaocode.cpp b/src/blackmisc/aviation/aircrafticaocode.cpp index 20f71812a..5ca9f7461 100644 --- a/src/blackmisc/aviation/aircrafticaocode.cpp +++ b/src/blackmisc/aviation/aircrafticaocode.cpp @@ -132,8 +132,7 @@ namespace BlackMisc int CAircraftIcaoCode::calculateScore(const CAircraftIcaoCode &otherCode) const { - const bool bothFromDb = this->isLoadedFromDb() && otherCode.isLoadedFromDb(); - if (bothFromDb && otherCode.getDbKey() == this->getDbKey()) { return 100; } + if (this->isDbEqual(otherCode)) { return 100; } int score = 0; 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->matchesManufacturer(otherCode.getManufacturer())) { - score += 20; + score += 10; } 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 return score; } diff --git a/src/blackmisc/aviation/airlineicaocode.cpp b/src/blackmisc/aviation/airlineicaocode.cpp index 12029e629..63f2c6e06 100644 --- a/src/blackmisc/aviation/airlineicaocode.cpp +++ b/src/blackmisc/aviation/airlineicaocode.cpp @@ -362,21 +362,21 @@ namespace BlackMisc int CAirlineIcaoCode::calculateScore(const CAirlineIcaoCode &otherCode) const { - const bool bothFromDb = otherCode.isLoadedFromDb() && this->isLoadedFromDb(); - if (bothFromDb && this->getDbKey() == otherCode.getDbKey()) - { - return 100; - } + if (this->isDbEqual(otherCode)) { return 100; } + const bool bothFromDb = this->isLoadedFromDb() && otherCode.isLoadedFromDb(); int score = 0; if (otherCode.hasValidDesignator() && this->getDesignator() == otherCode.getDesignator()) { score += 60; } + // only for DB values we check VA if (bothFromDb && this->isVirtualAirline() == otherCode.isVirtualAirline()) { score += 20; } + + // consider the various names if (this->hasName() && this->getName() == otherCode.getName()) { score += 20; diff --git a/src/blackmisc/aviation/livery.cpp b/src/blackmisc/aviation/livery.cpp index 6eb9a808e..e2bc73054 100644 --- a/src/blackmisc/aviation/livery.cpp +++ b/src/blackmisc/aviation/livery.cpp @@ -374,40 +374,38 @@ namespace BlackMisc 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; - 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; - score += multiplier * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode()); + // 2 airline liveries 0..85 + // 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; } } - - // max. 0..35 so far - if (score == 0) { return 0; } - - // overrate non airline liveries / color liveries - if (this->isAirlineStandardLivery() && !preferColorLiveries) { score += 10; } - if (preferColorLiveries) + else if ((this->isColorLivery() && otherLivery.isAirlineLivery()) || (otherLivery.isColorLivery() && this->isAirlineLivery())) { - if (this->isColorLivery() || !this->hasValidAirlineDesignator()) - { - score += 20; - } - } - - // 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 + // 1 airline, 1 color livery + // 0 .. 50 + // 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 } return score; }