mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +08:00
refs #720, improved distributor and airline/livery detection
* mark data read from DB (req. for string key where existing key value is not reliable indicator for DB data) * detect distributors by part of model string * use a simplified name (no spaces, no special characters) to find a match * allow to obtain model strings (=keys) as set and list
This commit is contained in:
committed by
Mathew Sutcliffe
parent
39dae7ed45
commit
f9922353c4
@@ -9,8 +9,8 @@
|
||||
|
||||
#include "airlineicaocode.h"
|
||||
#include "callsign.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/icons.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/logcategorylist.h"
|
||||
@@ -75,6 +75,11 @@ namespace BlackMisc
|
||||
return s.trimmed();
|
||||
}
|
||||
|
||||
QString CAirlineIcaoCode::getSimplifiedName() const
|
||||
{
|
||||
return BlackMisc::simplifyNameForSearch(this->getName());
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasValidCountry() const
|
||||
{
|
||||
return this->m_country.isValid();
|
||||
@@ -120,6 +125,14 @@ namespace BlackMisc
|
||||
return this->matchesVDesignator(candidate) || this->matchesIataCode(candidate);
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::isContainedInSimplifiedName(const QString &candidate) const
|
||||
{
|
||||
if (candidate.isEmpty() || !this->hasName()) { return false; }
|
||||
// try unaltered name first (should be faster)
|
||||
if (this->getName().contains(candidate, Qt::CaseInsensitive)) { return true; }
|
||||
return this->getSimplifiedName().contains(candidate, Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasCompleteData() const
|
||||
{
|
||||
return this->hasValidDesignator() && this->hasValidCountry() && this->hasName();
|
||||
@@ -361,15 +374,15 @@ namespace BlackMisc
|
||||
return CAirlineIcaoCode();
|
||||
}
|
||||
|
||||
QString designator(json.value(prefix + "designator").toString());
|
||||
QString iata(json.value(prefix + "iata").toString());
|
||||
QString telephony(json.value(prefix + "callsign").toString());
|
||||
QString name(json.value(prefix + "name").toString());
|
||||
QString countryIso(json.value(prefix + "country").toString());
|
||||
QString countryName(json.value(prefix + "countryname").toString());
|
||||
bool va = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "va").toString());
|
||||
bool operating = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "operating").toString());
|
||||
bool military = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "military").toString());
|
||||
const QString designator(json.value(prefix + "designator").toString());
|
||||
const QString iata(json.value(prefix + "iata").toString());
|
||||
const QString telephony(json.value(prefix + "callsign").toString());
|
||||
const QString name(json.value(prefix + "name").toString());
|
||||
const QString countryIso(json.value(prefix + "country").toString());
|
||||
const QString countryName(json.value(prefix + "countryname").toString());
|
||||
const bool va = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "va").toString());
|
||||
const bool operating = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "operating").toString());
|
||||
const bool military = CDatastoreUtility::dbBoolStringToBool(json.value(prefix + "military").toString());
|
||||
|
||||
CAirlineIcaoCode code(
|
||||
designator, name,
|
||||
|
||||
@@ -92,6 +92,9 @@ namespace BlackMisc
|
||||
//! Get name, e.g. "Lufthansa"
|
||||
const QString &getName() const { return this->m_name; }
|
||||
|
||||
//! \copydoc BlackMisc::simplifyNameForSearch
|
||||
QString getSimplifiedName() const;
|
||||
|
||||
//! Name plus key, e.g. "Lufthansa (3421)"
|
||||
QString getNameWithKey() const;
|
||||
|
||||
@@ -146,6 +149,9 @@ namespace BlackMisc
|
||||
//! Matches IATA code or v-designator?
|
||||
bool matchesVDesignatorOrIataCode(const QString &candidate) const;
|
||||
|
||||
//! Does simplified name contain the candidate
|
||||
bool isContainedInSimplifiedName(const QString &candidate) const;
|
||||
|
||||
//! Telephony designator?
|
||||
bool hasTelephonyDesignator() const { return !this->m_telephonyDesignator.isEmpty(); }
|
||||
|
||||
@@ -158,7 +164,7 @@ namespace BlackMisc
|
||||
//! Comined string with key
|
||||
QString getCombinedStringWithKey() const;
|
||||
|
||||
//! What is better, the callsign airline code or this code
|
||||
//! What is better, the callsign airline code or this code. Return the better one.
|
||||
CAirlineIcaoCode thisOrCallsignCode(const CCallsign &callsign) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Icon::toIcon
|
||||
|
||||
@@ -80,6 +80,15 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::findBySimplifiedNameContaining(const QString &containedString) const
|
||||
{
|
||||
if (containedString.isEmpty()) { return CAirlineIcaoCodeList(); }
|
||||
return this->findBy([&](const CAirlineIcaoCode & code)
|
||||
{
|
||||
return code.isContainedInSimplifiedName(containedString);
|
||||
});
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByMilitary(bool military) const
|
||||
{
|
||||
return this->findBy([&](const CAirlineIcaoCode & code)
|
||||
|
||||
@@ -66,6 +66,9 @@ namespace BlackMisc
|
||||
//! Find by country code
|
||||
CAirlineIcaoCodeList findByCountryIsoCode(const QString &isoCode) const;
|
||||
|
||||
//! Find if simplified name contains search string
|
||||
CAirlineIcaoCodeList findBySimplifiedNameContaining(const QString &containedString) const;
|
||||
|
||||
//! Find by military flag
|
||||
CAirlineIcaoCodeList findByMilitary(bool military) const;
|
||||
|
||||
@@ -87,7 +90,6 @@ namespace BlackMisc
|
||||
//! From our DB JSON
|
||||
static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true);
|
||||
};
|
||||
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace BlackMisc
|
||||
return s;
|
||||
}
|
||||
|
||||
bool CLivery::isContainedInSimplifiedAirlineName(const QString &candidate) const
|
||||
{
|
||||
return this->getAirlineIcaoCode().isContainedInSimplifiedName(candidate);
|
||||
}
|
||||
|
||||
bool CLivery::setAirlineIcaoCode(const CAirlineIcaoCode &airlineIcao)
|
||||
{
|
||||
if (m_airline == airlineIcao) { return false; }
|
||||
|
||||
@@ -80,6 +80,12 @@ namespace BlackMisc
|
||||
//! Get description.
|
||||
const QString &getDescription() const { return m_description; }
|
||||
|
||||
//! Get corresponding airline name
|
||||
const QString &getAirlineName() const { return this->getAirlineIcaoCode().getName(); }
|
||||
|
||||
//! Does simplified airline name contain the candidate
|
||||
bool isContainedInSimplifiedAirlineName(const QString &candidate) const;
|
||||
|
||||
//! Get fuselage color.
|
||||
const BlackMisc::CRgbColor &getColorFuselage() const { return m_colorFuselage; }
|
||||
|
||||
|
||||
@@ -37,21 +37,31 @@ namespace BlackMisc
|
||||
return this->findBy(&CLivery::getAirlineIcaoCodeDesignator, i);
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoDesignator(const QString &icao) const
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const QString &icao) const
|
||||
{
|
||||
QString i(icao.trimmed().toUpper());
|
||||
if (i.isEmpty()) { return CLivery(); }
|
||||
return this->findFirstByOrDefault([&](const CLivery & livery)
|
||||
{
|
||||
return livery.getAirlineIcaoCodeDesignator() == icao &&
|
||||
livery.isAirlineStandardLivery();
|
||||
|
||||
if (!livery.isAirlineStandardLivery()) { return false; }
|
||||
return livery.getAirlineIcaoCode().matchesVDesignator(i);
|
||||
});
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoDesignator(const CAirlineIcaoCode &icao) const
|
||||
CLiveryList CLiveryList::findStdLiveriesBySimplifiedAirlineName(const QString &containedString) const
|
||||
{
|
||||
return this->findStdLiveryByAirlineIcaoDesignator(icao.getDesignator());
|
||||
if (containedString.isEmpty()) { return CLiveryList(); }
|
||||
return this->findBy([&](const CLivery & livery)
|
||||
{
|
||||
// keep isAirlineStandardLivery first (faster)
|
||||
return livery.isAirlineStandardLivery() &&
|
||||
livery.isContainedInSimplifiedAirlineName(containedString);
|
||||
});
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
||||
{
|
||||
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findByCombinedCode(const QString &combinedCode) const
|
||||
@@ -81,6 +91,9 @@ namespace BlackMisc
|
||||
|
||||
CLivery CLiveryList::smartLiverySelector(const CLivery &liveryPattern) const
|
||||
{
|
||||
// multiple searches are slow, maybe we can performance optimize this
|
||||
// in the futuew
|
||||
|
||||
// first try on id, that would be perfect
|
||||
if (liveryPattern.hasValidDbKey())
|
||||
{
|
||||
@@ -97,14 +110,25 @@ namespace BlackMisc
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
// by airline
|
||||
if (liveryPattern.hasValidAirlineDesignator())
|
||||
{
|
||||
const QString icao(liveryPattern.getAirlineIcaoCodeDesignator());
|
||||
const CLivery l(this->findStdLiveryByAirlineIcaoDesignator(icao));
|
||||
const CLivery l(this->findStdLiveryByAirlineIcaoVDesignator(icao));
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
// lenient search by name contained (slow)
|
||||
if (liveryPattern.getAirlineIcaoCode().hasName())
|
||||
{
|
||||
const QString search(liveryPattern.getAirlineIcaoCode().getSimplifiedName());
|
||||
const CLiveryList liveries(this->findStdLiveriesBySimplifiedAirlineName(search));
|
||||
if (!liveries.isEmpty())
|
||||
{
|
||||
return liveries.front();
|
||||
}
|
||||
}
|
||||
return CLivery();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -47,10 +47,13 @@ namespace BlackMisc
|
||||
CLiveryList findByAirlineIcaoDesignator(const QString &icao) const;
|
||||
|
||||
//! Find livery by airline
|
||||
CLivery findStdLiveryByAirlineIcaoDesignator(const QString &icao) const;
|
||||
CLivery findStdLiveryByAirlineIcaoVDesignator(const QString &icao) const;
|
||||
|
||||
//! Find livery by airline
|
||||
CLivery findStdLiveryByAirlineIcaoDesignator(const CAirlineIcaoCode &icao) const;
|
||||
CLivery findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const;
|
||||
|
||||
//! By simplified name
|
||||
CLiveryList findStdLiveriesBySimplifiedAirlineName(const QString &containedString) const;
|
||||
|
||||
//! Find livery by combined code
|
||||
CLivery findByCombinedCode(const QString &combinedCode) const;
|
||||
@@ -63,7 +66,6 @@ namespace BlackMisc
|
||||
|
||||
//! Find
|
||||
CLivery smartLiverySelector(const CLivery &liveryPattern) const;
|
||||
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user