mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +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");
|
Q_ASSERT_X(sApp->getWebDataServices(), Q_FUNC_INFO, "No web services");
|
||||||
|
|
||||||
// already DB model?
|
// already DB model?
|
||||||
CAircraftModel model(modelToLookup);
|
CAircraftModel model(modelToLookup); // copy
|
||||||
if (modelToLookup.hasValidDbKey() && modelToLookup.getModelType() == CAircraftModel::TypeDatabaseEntry) { return modelToLookup; }
|
if (modelToLookup.isLoadedFromDb()) { return modelToLookup; }
|
||||||
|
|
||||||
// --- now I try to fill in as many DB data as possible ---
|
// --- now I try to fill in as many DB data as possible ---
|
||||||
// 1) This will unify data where possible
|
// 1) This will unify data where possible
|
||||||
// 2) I have full information of what the other pilot flies 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
|
// 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
|
// 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
|
// 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
|
// 2) not in the DB yet
|
||||||
|
|
||||||
const CCallsign callsign(model.getCallsign());
|
const CCallsign callsign(model.getCallsign());
|
||||||
@@ -210,7 +210,7 @@ namespace BlackCore
|
|||||||
if (modelFromDb.hasValidDbKey())
|
if (modelFromDb.hasValidDbKey())
|
||||||
{
|
{
|
||||||
model = modelFromDb;
|
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
|
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
|
// check if livery is already from DB
|
||||||
CAircraftIcaoCode aircraftIcaoUsedForLookup(model.getAircraftIcaoCode());
|
if (!model.getLivery().isLoadedFromDb())
|
||||||
CAirlineIcaoCode airlineIcaoUsedForLookup(model.getAirlineIcaoCode());
|
|
||||||
if (!aircraftIcaoUsedForLookup.hasValidDbKey())
|
|
||||||
{
|
{
|
||||||
aircraftIcaoUsedForLookup = CAircraftMatcher::reverseLookupAircraftIcao(aircraftIcaoUsedForLookup.getDesignator(), callsign, log);
|
CAirlineIcaoCode airlineIcaoCode(model.getAirlineIcaoCode());
|
||||||
}
|
if (!airlineIcaoCode.isLoadedFromDb())
|
||||||
|
|
||||||
if (!airlineIcaoUsedForLookup.hasValidDbKey())
|
|
||||||
{
|
{
|
||||||
airlineIcaoUsedForLookup = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcaoUsedForLookup.getDesignator(), callsign, log);
|
airlineIcaoCode = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcaoCode.getDesignator(), callsign, log);
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to match by livery
|
// try to match by livery
|
||||||
if (liveryCode.isEmpty() && airlineIcaoUsedForLookup.hasValidDesignator())
|
if (liveryCode.isEmpty() && airlineIcaoCode.hasValidDesignator())
|
||||||
{
|
{
|
||||||
// we create a standard livery code, then we try to find based on this
|
// we create a standard livery code, then we try to find based on this
|
||||||
liveryCode = CLivery::getStandardCode(model.getAirlineIcaoCode());
|
liveryCode = CLivery::getStandardCode(airlineIcaoCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CLivery::isValidCombinedCode(liveryCode))
|
if (CLivery::isValidCombinedCode(liveryCode))
|
||||||
{
|
{
|
||||||
// search DB model by livery
|
// search livery by combined code
|
||||||
const CAircraftModelList models(sApp->getWebDataServices()->getModelsForAircraftDesignatorAndLiveryCombinedCode(aircraftIcaoUsedForLookup.getDesignator(), liveryCode));
|
const CLivery reverseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(liveryCode));
|
||||||
if (models.isEmpty())
|
if (reverseLivery.hasValidDbKey())
|
||||||
{
|
|
||||||
// no models for that livery, search for livery only
|
|
||||||
const CLivery databaseLivery(sApp->getWebDataServices()->getLiveryForCombinedCode(liveryCode));
|
|
||||||
if (databaseLivery.hasValidDbKey())
|
|
||||||
{
|
{
|
||||||
// we have found a livery in the DB
|
// we have found a livery in the DB
|
||||||
model.setLivery(databaseLivery);
|
model.setLivery(reverseLivery);
|
||||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1'").arg(databaseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1'").arg(reverseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// model by livery data found
|
// no livery data found
|
||||||
model = models.front();
|
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup of livery '%1' yielded no result").arg(reverseLivery.getCombinedCodePlusInfo()), getLogCategories()); }
|
||||||
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()); }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} // livery lookup
|
||||||
|
|
||||||
// if no DB livery, create own dummy livery
|
// if no DB livery yet, create own livery
|
||||||
if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey())
|
if (!model.hasValidDbKey() && !model.getLivery().hasValidDbKey())
|
||||||
{
|
{
|
||||||
// create a pseudo livery, try to find airline first
|
// create a pseudo livery, try to find airline first
|
||||||
CAirlineIcaoCode reverseAirlineIcao(sApp->getWebDataServices()->smartAirlineIcaoSelector(CAirlineIcaoCode(airlineIcaoUsedForLookup.getDesignator())));
|
if (airlineIcaoCode.hasValidDesignator())
|
||||||
if (!reverseAirlineIcao.hasValidDbKey())
|
|
||||||
{
|
{
|
||||||
// no DB data, we update as much as possible
|
const CLivery liveryDummy(CLivery::getStandardCode(airlineIcaoCode), airlineIcaoCode, "Generated");
|
||||||
reverseAirlineIcao = model.getAirlineIcaoCode();
|
|
||||||
reverseAirlineIcao.updateMissingParts(CAirlineIcaoCode(airlineIcaoUsedForLookup));
|
|
||||||
}
|
|
||||||
if (airlineIcaoUsedForLookup.hasValidDesignator())
|
|
||||||
{
|
|
||||||
const CLivery liveryDummy(CLivery::getStandardCode(reverseAirlineIcao), reverseAirlineIcao, "Generated");
|
|
||||||
model.setLivery(liveryDummy);
|
model.setLivery(liveryDummy);
|
||||||
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, set dummy livery `%1`").arg(liveryDummy.getCombinedCodePlusInfo())); }
|
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())
|
if (!model.getAircraftIcaoCode().hasValidDbKey())
|
||||||
{
|
{
|
||||||
CAircraftIcaoCode reverseAircraftIcao(sApp->getWebDataServices()->getAircraftIcaoCodeForDesignator(aircraftIcaoUsedForLookup.getDesignator()));
|
CAircraftIcaoCode aircraftIcaoUsedForLookup(model.getAircraftIcaoCode());
|
||||||
if (!reverseAircraftIcao.hasValidDbKey())
|
if (!aircraftIcaoUsedForLookup.isLoadedFromDb())
|
||||||
|
{
|
||||||
|
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
|
// no DB data, we update as much as possible
|
||||||
reverseAircraftIcao = model.getAircraftIcaoCode();
|
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QString("Reverse lookup, ICAO '%1' not resolved from DB").arg(aircraftIcaoUsedForLookup.getDesignator())); }
|
||||||
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())); }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // model from DB
|
} // model from DB
|
||||||
|
|
||||||
model.setCallsign(callsign);
|
model.setCallsign(callsign);
|
||||||
|
model.setModelType(modelToLookup.getModelType());
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
{
|
{
|
||||||
CMatchingUtils::addLogDetailsToList(log, callsign, QString("Using model: ICAO '%1', livery '%2', model '%3', type '%4'").
|
CMatchingUtils::addLogDetailsToList(log, callsign, QString("Using model: ICAO '%1', livery '%2', model '%3', type '%4'").
|
||||||
arg(model.getAircraftIcaoCode().getCombinedIcaoStringWithKey()).
|
arg(model.getAircraftIcaoCode().getCombinedIcaoStringWithKey(),
|
||||||
arg(model.getLivery().getCombinedCodePlusInfo()).
|
model.getLivery().getCombinedCodePlusInfo(),
|
||||||
arg(model.getModelString()).
|
model.getModelString(), model.getModelTypeAsString())
|
||||||
arg(model.getModelTypeAsString())
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return model;
|
return model;
|
||||||
|
|||||||
Reference in New Issue
Block a user