mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #792, do not reverse lookup a model if it is not 100% identifiable
Instead only use livery, airline, aircraft ICAO
This commit is contained in:
@@ -186,16 +186,16 @@ namespace BlackCore
|
||||
Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "No web services");
|
||||
|
||||
// already DB model?
|
||||
CAircraftModel model(modelToLookup);
|
||||
if (modelToLookup.hasValidDbKey() && modelToLookup.getModelType() == CAircraftModel::TypeDatabaseEntry) { return modelToLookup; }
|
||||
CAircraftModel model(modelToLookup); // copy
|
||||
if (modelToLookup.isLoadedFromDb()) { return modelToLookup; }
|
||||
|
||||
// --- now I try to fill in as many DB data as possible ---
|
||||
// 1) This will unify data where possible
|
||||
// 2) I have full information of what the other pilot flies where possible
|
||||
// 3) This is not model matching here (!), it is a process of getting the most accurate data from that fuzzy information I get via FSD
|
||||
//
|
||||
// reverse lookup, use DB data wherever possible
|
||||
// 1) If I cannot resolce the ICAO codes here, they are either wrong (most likely in most cases) or
|
||||
// Reverse lookup, use DB data wherever possible
|
||||
// 1) If I cannot resolve the ICAO codes here, they are either wrong (most likely in most cases) or
|
||||
// 2) not in the DB yet
|
||||
|
||||
const CCallsign callsign(model.getCallsign());
|
||||
@@ -210,7 +210,7 @@ namespace BlackCore
|
||||
if (modelFromDb.hasValidDbKey())
|
||||
{
|
||||
model = modelFromDb;
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup found DB model '%1' for '%2'").arg(modelFromDb.getModelStringAndDbKey()).arg(callsign.toQString()), getLogCategories()); }
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup found DB model '%1' for '%2'").arg(modelFromDb.getModelStringAndDbKey(), callsign.toQString()), getLogCategories()); }
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -218,96 +218,84 @@ namespace BlackCore
|
||||
}
|
||||
}
|
||||
|
||||
if (!model.hasValidDbKey())
|
||||
// lookup if model is not yet from DB
|
||||
if (!model.isLoadedFromDb())
|
||||
{
|
||||
// only if not yet matched with DB
|
||||
CAircraftIcaoCode aircraftIcaoUsedForLookup(model.getAircraftIcaoCode());
|
||||
CAirlineIcaoCode airlineIcaoUsedForLookup(model.getAirlineIcaoCode());
|
||||
if (!aircraftIcaoUsedForLookup.hasValidDbKey())
|
||||
// check if livery is already from DB
|
||||
if (!model.getLivery().isLoadedFromDb())
|
||||
{
|
||||
aircraftIcaoUsedForLookup = CAircraftMatcher::reverseLookupAircraftIcao(aircraftIcaoUsedForLookup.getDesignator(), callsign, log);
|
||||
}
|
||||
|
||||
if (!airlineIcaoUsedForLookup.hasValidDbKey())
|
||||
{
|
||||
airlineIcaoUsedForLookup = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcaoUsedForLookup.getDesignator(), callsign, log);
|
||||
}
|
||||
|
||||
// try to match by livery
|
||||
if (liveryCode.isEmpty() && airlineIcaoUsedForLookup.hasValidDesignator())
|
||||
{
|
||||
// we create a standard livery code, then we try to find based on this
|
||||
liveryCode = CLivery::getStandardCode(model.getAirlineIcaoCode());
|
||||
}
|
||||
|
||||
if (CLivery::isValidCombinedCode(liveryCode))
|
||||
{
|
||||
// search DB model by livery
|
||||
const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoUsedForLookup.getDesignator(), liveryCode));
|
||||
if (models.isEmpty())
|
||||
CAirlineIcaoCode airlineIcaoCode(model.getAirlineIcaoCode());
|
||||
if (!airlineIcaoCode.isLoadedFromDb())
|
||||
{
|
||||
// no models for that livery, search for livery only
|
||||
const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(liveryCode));
|
||||
if (databaseLivery.hasValidDbKey())
|
||||
airlineIcaoCode = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcaoCode.getDesignator(), callsign, log);
|
||||
}
|
||||
|
||||
// try to match by livery
|
||||
if (liveryCode.isEmpty() && airlineIcaoCode.hasValidDesignator())
|
||||
{
|
||||
// we create a standard livery code, then we try to find based on this
|
||||
liveryCode = CLivery::getStandardCode(airlineIcaoCode);
|
||||
}
|
||||
|
||||
if (CLivery::isValidCombinedCode(liveryCode))
|
||||
{
|
||||
// search livery by combined code
|
||||
const CLivery reverseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(liveryCode));
|
||||
if (reverseLivery.hasValidDbKey())
|
||||
{
|
||||
// we have found a livery in the DB
|
||||
model.setLivery(databaseLivery);
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1'").arg(databaseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
||||
model.setLivery(reverseLivery);
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1'").arg(reverseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// model by livery data found
|
||||
model = models.front();
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of DB model '%1' for '%2'/'%3'', found '%4'").arg(model.getDbKey()).arg(aircraftIcaoUsedForLookup.getDesignator()).arg(liveryCode).arg(models.size()), getLogCategories()); }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no livery data found
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1' yielded no result").arg(reverseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
||||
}
|
||||
} // livery lookup
|
||||
|
||||
// if no DB livery, create own dummy livery
|
||||
if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey())
|
||||
{
|
||||
// create a pseudo livery, try to find airline first
|
||||
CAirlineIcaoCode reverseAirlineIcao(sApp->getWebDataServices()->smartAirlineIcaoSelector(CAirlineIcaoCode(airlineIcaoUsedForLookup.getDesignator())));
|
||||
if (!reverseAirlineIcao.hasValidDbKey())
|
||||
// if no DB livery yet, create own livery
|
||||
if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey())
|
||||
{
|
||||
// no DB data, we update as much as possible
|
||||
reverseAirlineIcao = model.getAirlineIcaoCode();
|
||||
reverseAirlineIcao.updateMissingParts(CAirlineIcaoCode(airlineIcaoUsedForLookup));
|
||||
}
|
||||
if (airlineIcaoUsedForLookup.hasValidDesignator())
|
||||
{
|
||||
const CLivery liveryDummy(CLivery::getStandardCode(reverseAirlineIcao), reverseAirlineIcao, "Generated");
|
||||
model.setLivery(liveryDummy);
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, set dummy livery `%1`").arg(liveryDummy.getCombinedCodePlusInfo())); }
|
||||
}
|
||||
}
|
||||
// create a pseudo livery, try to find airline first
|
||||
if (airlineIcaoCode.hasValidDesignator())
|
||||
{
|
||||
const CLivery liveryDummy(CLivery::getStandardCode(airlineIcaoCode), airlineIcaoCode, "Generated");
|
||||
model.setLivery(liveryDummy);
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Generated livery, set livery `%1`").arg(liveryDummy.getCombinedCodePlusInfo())); }
|
||||
}
|
||||
} // pseudo livery
|
||||
} // livery from DB
|
||||
|
||||
// aircraft ICAO if not from DB yet
|
||||
if (!model.getAircraftIcaoCode().hasValidDbKey())
|
||||
{
|
||||
CAircraftIcaoCode reverseAircraftIcao(sApp->getWebDataServices()->getAircraftIcaoCodeForDesignator(aircraftIcaoUsedForLookup.getDesignator()));
|
||||
if (!reverseAircraftIcao.hasValidDbKey())
|
||||
CAircraftIcaoCode aircraftIcaoUsedForLookup(model.getAircraftIcaoCode());
|
||||
if (!aircraftIcaoUsedForLookup.isLoadedFromDb())
|
||||
{
|
||||
// no DB data, we update as much as possible
|
||||
reverseAircraftIcao = model.getAircraftIcaoCode();
|
||||
reverseAircraftIcao.updateMissingParts(CAircraftIcaoCode(aircraftIcaoUsedForLookup));
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, aircraft '%1' not found in DB").arg(reverseAircraftIcao.getDesignator())); }
|
||||
}
|
||||
if (reverseAircraftIcao.hasDesignator())
|
||||
{
|
||||
model.setAircraftIcaoCode(reverseAircraftIcao);
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, set aircraft ICAO to '%1'").arg(reverseAircraftIcao.getCombinedIcaoStringWithKey())); }
|
||||
aircraftIcaoUsedForLookup = CAircraftMatcher::reverseLookupAircraftIcao(aircraftIcaoUsedForLookup.getDesignator(), callsign, log);
|
||||
if (aircraftIcaoUsedForLookup.isLoadedFromDb())
|
||||
{
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Set aircraft ICAO to '%1' from DB").arg(aircraftIcaoUsedForLookup.getCombinedIcaoStringWithKey())); }
|
||||
}
|
||||
else
|
||||
{
|
||||
// no DB data, we update as much as possible
|
||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, ICAO '%1' not resolved from DB").arg(aircraftIcaoUsedForLookup.getDesignator())); }
|
||||
}
|
||||
}
|
||||
}
|
||||
} // model from DB
|
||||
|
||||
model.setCallsign(callsign);
|
||||
model.setModelType(modelToLookup.getModelType());
|
||||
|
||||
if (log)
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, callsign, QString("Using model: ICAO '%1', livery '%2', model '%3', type '%4'").
|
||||
arg(model.getAircraftIcaoCode().getCombinedIcaoStringWithKey()).
|
||||
arg(model.getLivery().getCombinedCodePlusInfo()).
|
||||
arg(model.getModelString()).
|
||||
arg(model.getModelTypeAsString())
|
||||
arg(model.getAircraftIcaoCode().getCombinedIcaoStringWithKey(),
|
||||
model.getLivery().getCombinedCodePlusInfo(),
|
||||
model.getModelString(), model.getModelTypeAsString())
|
||||
);
|
||||
}
|
||||
return model;
|
||||
|
||||
Reference in New Issue
Block a user