mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
Ref T704, moved "ifPossibleReduceNameTelephonyCountry" into airline code list, unified functions
This commit is contained in:
committed by
Mat Sutcliffe
parent
1b4aa1162a
commit
9b5ffdf924
@@ -1801,48 +1801,6 @@ namespace BlackCore
|
||||
**/
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAircraftMatcher::ifPossibleReduceIcaoByAirlineNameTelephonyDesignator(const CCallsign &cs, const QString &airlineName, const QString &telephony, const CAirlineIcaoCodeList &inList, const QString &info, bool &reduced, CStatusMessageList *log)
|
||||
{
|
||||
reduced = false;
|
||||
if (inList.isEmpty())
|
||||
{
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % u" Empty input list, cannot reduce", getLogCategories()); }
|
||||
return inList;
|
||||
}
|
||||
|
||||
if (telephony.isEmpty() && airlineName.isEmpty())
|
||||
{
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % u" No name/telephony, cannot reduce " % QString::number(inList.size()) % u" entries", getLogCategories()); }
|
||||
return inList;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList step1Data = inList.findByNamesOrTelephonyDesignator(airlineName);
|
||||
if (step1Data.size() < 1 || step1Data.size() == inList.size())
|
||||
{
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % QStringLiteral(" cannot reduce by '%1'").arg(airlineName), getLogCategories()); }
|
||||
step1Data = inList;
|
||||
}
|
||||
else
|
||||
{
|
||||
reduced = true;
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % QStringLiteral(" reduced by '%1'").arg(airlineName), getLogCategories()); }
|
||||
}
|
||||
if (step1Data.size() == 1) { return step1Data; }
|
||||
|
||||
CAirlineIcaoCodeList step2Data = inList.findByNamesOrTelephonyDesignator(telephony);
|
||||
if (step2Data.size() < 1 || step2Data.size() == inList.size())
|
||||
{
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % QStringLiteral(" cannot reduce by '%1'").arg(telephony), getLogCategories()); }
|
||||
step2Data = step1Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
reduced = true;
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, cs, info % QStringLiteral(" reduced by '%1'").arg(telephony), getLogCategories()); }
|
||||
}
|
||||
return step2Data;
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftMatcher::ifPossibleReduceByCombinedType(const CSimulatedAircraft &remoteAircraft, const CAircraftModelList &inList, const CAircraftMatcherSetup &setup, bool &reduced, CStatusMessageList *log)
|
||||
{
|
||||
reduced = false;
|
||||
|
||||
@@ -360,10 +360,6 @@ namespace BlackCore
|
||||
//! \threadsafe
|
||||
static BlackMisc::Simulation::CAircraftModelList ifPossibleReduceModelsByAirlineNameTelephonyDesignator(const BlackMisc::Aviation::CCallsign &cs, const QString &airlineName, const QString &telephony, const BlackMisc::Simulation::CAircraftModelList &inList, const QString &info, bool &reduced, BlackMisc::CStatusMessageList *log);
|
||||
|
||||
//! Reduce by airline name/telephone designator
|
||||
//! \threadsafe
|
||||
static BlackMisc::Aviation::CAirlineIcaoCodeList ifPossibleReduceIcaoByAirlineNameTelephonyDesignator(const BlackMisc::Aviation::CCallsign &cs, const QString &airlineName, const QString &telephony, const BlackMisc::Aviation::CAirlineIcaoCodeList &inList, const QString &info, bool &reduced, BlackMisc::CStatusMessageList *log);
|
||||
|
||||
//! Installed models by combined code (ie L2J, L1P, ...)
|
||||
//! \threadsafe
|
||||
static BlackMisc::Simulation::CAircraftModelList ifPossibleReduceByCombinedType(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, const BlackMisc::Simulation::CAircraftModelList &inList, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, bool &reduced, BlackMisc::CStatusMessageList *log);
|
||||
|
||||
@@ -115,20 +115,20 @@ namespace BlackMisc
|
||||
|
||||
bool CAirlineIcaoCode::matchesDesignator(const QString &designator) const
|
||||
{
|
||||
if (designator.isEmpty()) { return false; }
|
||||
return designator.trimmed().toUpper() == m_designator;
|
||||
if (designator.isEmpty() || m_designator.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(m_designator, designator.trimmed());
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesVDesignator(const QString &designator) const
|
||||
{
|
||||
if (designator.isEmpty()) { return false; }
|
||||
return designator.trimmed().toUpper() == this->getVDesignator();
|
||||
if (designator.isEmpty() || m_designator.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(this->getVDesignator(), designator.trimmed());
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesIataCode(const QString &iata) const
|
||||
{
|
||||
if (iata.isEmpty()) { return false; }
|
||||
return iata.trimmed().toUpper() == m_iataCode;
|
||||
if (iata.isEmpty() || m_iataCode.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(m_iataCode, iata.trimmed());
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesDesignatorOrIataCode(const QString &candidate) const
|
||||
@@ -143,6 +143,12 @@ namespace BlackMisc
|
||||
return this->matchesVDesignator(candidate) || this->matchesIataCode(candidate);
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesTelephonyDesignator(const QString &candidate) const
|
||||
{
|
||||
if (candidate.isEmpty() || m_telephonyDesignator.isEmpty()) { return false; }
|
||||
return caseInsensitiveStringCompare(m_telephonyDesignator, candidate.trimmed());
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesNamesOrTelephonyDesignator(const QString &candidate) const
|
||||
{
|
||||
const QString cand(candidate.toUpper().trimmed());
|
||||
|
||||
@@ -181,6 +181,9 @@ namespace BlackMisc
|
||||
//! Matches IATA code or v-designator?
|
||||
bool matchesVDesignatorOrIataCode(const QString &candidate) const;
|
||||
|
||||
//! Matches telephony designator (aka callsign, not to be confused with CCallsign)
|
||||
bool matchesTelephonyDesignator(const QString &candidate) const;
|
||||
|
||||
//! Relaxed check by name or telephony designator (aka callsign, not to be confused with CCallsign)
|
||||
bool matchesNamesOrTelephonyDesignator(const QString &candidate) const;
|
||||
|
||||
|
||||
@@ -113,6 +113,15 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByTelephonyDesignator(const QString &candidate) const
|
||||
{
|
||||
if (candidate.isEmpty()) { return CAirlineIcaoCodeList(); }
|
||||
return this->findBy([&](const CAirlineIcaoCode & code)
|
||||
{
|
||||
return code.matchesTelephonyDesignator(candidate);
|
||||
});
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByNamesOrTelephonyDesignator(const QString &candidate) const
|
||||
{
|
||||
if (candidate.isEmpty()) { return CAirlineIcaoCodeList(); }
|
||||
@@ -174,28 +183,92 @@ namespace BlackMisc
|
||||
if (codesFound.size() == 1) { return codesFound.front(); }
|
||||
if (codesFound.isEmpty())
|
||||
{
|
||||
// nothing found so far
|
||||
codesFound = this->findByNamesOrTelephonyDesignator(patternUsed.getName());
|
||||
codesFound = this->ifPossibleReduceByTelephonyDesignator(patternUsed.getTelephonyDesignator());
|
||||
codesFound = codesFound.ifPossibleReduceByCountry(patternUsed.getCountryIso());
|
||||
}
|
||||
else
|
||||
{
|
||||
// further reduce
|
||||
if (patternUsed.hasName())
|
||||
{
|
||||
const CAirlineIcaoCodeList backup(codesFound);
|
||||
codesFound = this->findByNamesOrTelephonyDesignator(patternUsed.getName());
|
||||
if (codesFound.isEmpty()) { codesFound = backup; }
|
||||
}
|
||||
bool reduced = false;
|
||||
codesFound = codesFound.ifPossibleReduceNameTelephonyCountry(callsign, patternUsed.getName(), patternUsed.getTelephonyDesignator(), patternUsed.getCountryIso(), reduced, QString(), nullptr);
|
||||
}
|
||||
|
||||
// further reduce
|
||||
if (patternUsed.hasValidCountry())
|
||||
return codesFound.frontOrDefault();
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::ifPossibleReduceNameTelephonyCountry(const CCallsign &cs, const QString &airlineName, const QString &telephony, const QString &countryIso, bool &reduced, const QString &loginfo, CStatusMessageList *log) const
|
||||
{
|
||||
reduced = false;
|
||||
if (this->isEmpty())
|
||||
{
|
||||
CAirlineIcaoCodeList countryCodes = codesFound.findByCountryIsoCode(patternUsed.getCountry().getIsoCode());
|
||||
if (!countryCodes.isEmpty()) { return countryCodes.front(); }
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % u" Empty input list, cannot reduce", getLogCategories()); }
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (!codesFound.isEmpty()) { return codesFound.front(); }
|
||||
return patternUsed;
|
||||
if (telephony.isEmpty() && airlineName.isEmpty() && countryIso.isEmpty())
|
||||
{
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % u" No name/telephony/country, cannot reduce " % QString::number(this->size()) % u" entries", getLogCategories()); }
|
||||
return *this;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList step1Data = airlineName.isEmpty() ? *this : this->findByNamesOrTelephonyDesignator(airlineName);
|
||||
if (step1Data.size() < 1 || step1Data.size() == this->size())
|
||||
{
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" cannot reduce by '%1'").arg(airlineName), getLogCategories()); }
|
||||
step1Data = *this;
|
||||
}
|
||||
else
|
||||
{
|
||||
reduced = true;
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" reduced by '%1'").arg(airlineName), getLogCategories()); }
|
||||
}
|
||||
if (step1Data.size() == 1) { return step1Data; }
|
||||
|
||||
CAirlineIcaoCodeList step2Data = telephony.isEmpty() ? step1Data : step1Data.findByNamesOrTelephonyDesignator(telephony);
|
||||
if (step2Data.size() < 1 || step2Data.size() == this->size())
|
||||
{
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" cannot reduce by name '%1'").arg(telephony), getLogCategories()); }
|
||||
step2Data = step1Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
reduced = true;
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" reduced by telephony '%1'").arg(telephony), getLogCategories()); }
|
||||
}
|
||||
if (step2Data.size() == 1) { return step2Data; }
|
||||
|
||||
CAirlineIcaoCodeList step3Data = countryIso.isEmpty() ? step2Data : step2Data.findByCountryIsoCode(countryIso);
|
||||
if (step3Data.size() < 1 || step3Data.size() == this->size())
|
||||
{
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" cannot reduce by country '%1'").arg(countryIso), getLogCategories()); }
|
||||
step3Data = step2Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
reduced = true;
|
||||
if (log) { CLogUtilities::addLogDetailsToList(log, cs, loginfo % QStringLiteral(" reduced by '%1'").arg(countryIso), getLogCategories()); }
|
||||
}
|
||||
return step3Data;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::ifPossibleReduceByCountry(const QString &countryIso) const
|
||||
{
|
||||
if (countryIso.isEmpty()) { return *this; }
|
||||
if (this->isEmpty()) { return *this; }
|
||||
const CAirlineIcaoCodeList found = this->findByCountryIsoCode(countryIso);
|
||||
if (found.size() == this->size() || found.isEmpty()) { return *this; }
|
||||
return found;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::ifPossibleReduceByTelephonyDesignator(const QString &telephonyDesignator) const
|
||||
{
|
||||
if (telephonyDesignator.isEmpty()) { return *this; }
|
||||
if (this->isEmpty()) { return *this; }
|
||||
const CAirlineIcaoCodeList found = this->findByTelephonyDesignator(telephonyDesignator);
|
||||
if (found.size() == this->size() || found.isEmpty()) { return *this; }
|
||||
return found;
|
||||
}
|
||||
|
||||
CAirlineIcaoCode CAirlineIcaoCodeList::findBestMatchByCallsign(const CCallsign &callsign) const
|
||||
|
||||
@@ -39,6 +39,9 @@ namespace BlackMisc
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CAirlineIcaoCodeList)
|
||||
using CSequence::CSequence;
|
||||
|
||||
//! Categories
|
||||
static const CLogCategoryList &getLogCategories();
|
||||
|
||||
//! Default constructor.
|
||||
CAirlineIcaoCodeList();
|
||||
|
||||
@@ -74,6 +77,9 @@ namespace BlackMisc
|
||||
//! Find if simplified name contains search string
|
||||
CAirlineIcaoCodeList findBySimplifiedNameContaining(const QString &containedString) const;
|
||||
|
||||
//! Find by names or telephony designator (aka callsign, not to be confused with CCallsign)
|
||||
CAirlineIcaoCodeList findByTelephonyDesignator(const QString &candidate) const;
|
||||
|
||||
//! Find by names or telephony designator (aka callsign, not to be confused with CCallsign)
|
||||
CAirlineIcaoCodeList findByNamesOrTelephonyDesignator(const QString &candidate) const;
|
||||
|
||||
@@ -86,11 +92,20 @@ namespace BlackMisc
|
||||
//! The ones with an invalid designator
|
||||
CAirlineIcaoCodeList findByInvalidDesignator() const;
|
||||
|
||||
//! Use callsign to conclude airline
|
||||
CAirlineIcaoCode findBestMatchByCallsign(const CCallsign &callsign) const;
|
||||
|
||||
//! Best selection by given pattern
|
||||
CAirlineIcaoCode smartAirlineIcaoSelector(const CAirlineIcaoCode &icaoPattern, const CCallsign &callsign) const;
|
||||
|
||||
//! Use callsign to conclude airline
|
||||
CAirlineIcaoCode findBestMatchByCallsign(const CCallsign &callsign) const;
|
||||
//! Reduce by airline name/telephone designator, ISO country
|
||||
CAirlineIcaoCodeList ifPossibleReduceNameTelephonyCountry(const BlackMisc::Aviation::CCallsign &cs, const QString &airlineName, const QString &telephony, const QString &countryIso, bool &reduced, const QString &logInfo, CStatusMessageList *log) const;
|
||||
|
||||
//! Reduce by ISO country
|
||||
CAirlineIcaoCodeList ifPossibleReduceByCountry(const QString &countryIso) const;
|
||||
|
||||
//! Reduce by telephony designator
|
||||
CAirlineIcaoCodeList ifPossibleReduceByTelephonyDesignator(const QString &telephonyDesignator) const;
|
||||
|
||||
//! String list for completion by ICAO designator
|
||||
QStringList toIcaoDesignatorCompleterStrings(bool combinedString = true, bool sort = true) const;
|
||||
|
||||
Reference in New Issue
Block a user