Ref T658, moved entry script in own function and adjusted airspace monitor

This commit is contained in:
Klaus Basan
2019-05-19 18:34:15 +02:00
parent ef4e11025d
commit 475d23c3da
3 changed files with 131 additions and 87 deletions

View File

@@ -275,19 +275,35 @@ namespace BlackCore
CAircraftModel CAircraftMatcher::reverseLookupModel(const CCallsign &callsign, const CAircraftIcaoCode &networkAircraftIcao, const CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, const CAircraftMatcherSetup &setup, CAircraftModel::ModelType type, CStatusMessageList *log) CAircraftModel CAircraftMatcher::reverseLookupModel(const CCallsign &callsign, const CAircraftIcaoCode &networkAircraftIcao, const CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, const CAircraftMatcherSetup &setup, CAircraftModel::ModelType type, CStatusMessageList *log)
{ {
Q_UNUSED(setup);
CLivery livery; CLivery livery;
livery.setAirlineIcaoCode(networkAirlineIcao); livery.setAirlineIcaoCode(networkAirlineIcao);
CAircraftModel model(networkModelString, type, {}, networkAircraftIcao, livery); CAircraftModel model(networkModelString, type, {}, networkAircraftIcao, livery);
model.setCallsign(callsign); model.setCallsign(callsign);
model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, log); model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, log);
model.setModelType(CAircraftModel::TypeReverseLookup); model.setModelType(CAircraftModel::TypeReverseLookup);
return model;
}
CAircraftModel CAircraftMatcher::networkEntryScript(const CAircraftModel &inModel, const CAircraftMatcherSetup &setup, CStatusMessageList *log)
{
if (!setup.doRunMsNetworkEntryScript()) { return inModel; }
// matching script // matching script
const CCallsign callsign = inModel.getCallsign();
const CAircraftIcaoCode inAircraftIcao = inModel.getAircraftIcaoCode();
const CAirlineIcaoCode inAirlineIcao = inModel.getAirlineIcaoCode();
const CLivery inLivery = inModel.getLivery();
while (setup.doRunMsNetworkEntryScript()) while (setup.doRunMsNetworkEntryScript())
{ {
const QString js = CFileUtils::readFileToString(setup.getMsNetworkEntryFile()); const QString js = CFileUtils::readFileToString(setup.getMsNetworkEntryFile());
if (js.isEmpty()) { break; } if (js.isEmpty()) { break; }
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Matching script (rev.lookup): '%1'").arg(setup.getMsNetworkEntryFile())); }
static const QString logFile = CFileUtils::appendFilePaths(CDirectoryUtils::logDirectory(), "logMatchingSriptEntry.log"); static const QString logFile = CFileUtils::appendFilePaths(CDirectoryUtils::logDirectory(), "logMatchingSriptEntry.log");
QJSEngine engine; QJSEngine engine;
// engine.installExtensions(QJSEngine::ConsoleExtension); // engine.installExtensions(QJSEngine::ConsoleExtension);
@@ -295,15 +311,15 @@ namespace BlackCore
engine.globalObject().setProperty("SwiftValues", jsMetaObject); engine.globalObject().setProperty("SwiftValues", jsMetaObject);
MSSwiftValues networkObject( MSSwiftValues networkObject(
callsign.asString(), callsign.asString(),
networkAircraftIcao.getDesignator(), networkAircraftIcao.getDbKey(), inAircraftIcao.getDesignator(), inAircraftIcao.getDbKey(),
networkAirlineIcao.getDesignator(), networkAirlineIcao.getDbKey(), inAirlineIcao.getDesignator(), inAirlineIcao.getDbKey(),
networkLiveryInfo, -1 inLivery.getCombinedCode(), inLivery.getDbKey()
); );
MSSwiftValues reverseModel( MSSwiftValues reverseModel(
model.getCallsign().asString(), inModel.getCallsign().asString(),
model.getAircraftIcaoCode().getDesignator(), model.getAircraftIcaoCode().getDbKey(), inModel.getAircraftIcaoCode().getDesignator(), inModel.getAircraftIcaoCode().getDbKey(),
model.getAirlineIcaoCode().getDesignator(), model.getAirlineIcaoCode().getDbKey(), inModel.getAirlineIcaoCode().getDesignator(), inModel.getAirlineIcaoCode().getDbKey(),
model.getLivery().getCombinedCode(), model.getLivery().getDbKey() inModel.getLivery().getCombinedCode(), inModel.getLivery().getDbKey()
); );
MSSwiftValues returnObject; MSSwiftValues returnObject;
@@ -318,7 +334,9 @@ namespace BlackCore
ms = ms.call(); ms = ms.call();
if (ms.isError()) if (ms.isError())
{ {
CLogMessage(getLogCategories()).warning(u"Matching script error: %1 '%2'") << ms.property("lineNumber").toInt() << ms.toString(); const QString msg = QStringLiteral("Matching script error: %1 '%2'").arg(ms.property("lineNumber").toInt()).arg(ms.toString());
CLogMessage(getLogCategories()).warning(msg);
if (log) { CMatchingUtils::addLogDetailsToList(log, callsign, msg); }
} }
else else
{ {
@@ -327,7 +345,7 @@ namespace BlackCore
const QString r = ms.toString(); const QString r = ms.toString();
if (!r.isEmpty()) if (!r.isEmpty())
{ {
CLogMessage(getLogCategories()).info(u"Matching script: '%1'") << ms.property("lineNumber").toInt() << ms.toString(); CLogMessage(getLogCategories()).info(u"Matching script: '%1'") << r;
} }
} }
} }
@@ -336,7 +354,8 @@ namespace BlackCore
break; break;
} }
return model; // not yet using the script model
return inModel;
} }
CAircraftModel CAircraftMatcher::reverseLookupModel(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, CStatusMessageList *log) CAircraftModel CAircraftMatcher::reverseLookupModel(const CAircraftModel &modelToLookup, const QString &networkLiveryInfo, CStatusMessageList *log)

View File

@@ -86,6 +86,11 @@ namespace BlackCore
const QString &primaryIcao, const QString &secondaryIcao, const QString &primaryIcao, const QString &secondaryIcao,
bool airlineFromCallsign, bool useWebServices, BlackMisc::CStatusMessageList *log = nullptr); bool airlineFromCallsign, bool useWebServices, BlackMisc::CStatusMessageList *log = nullptr);
//! Run the network entry script
//! \threadsafe
//! \ingroup reverselookup
static BlackMisc::Simulation::CAircraftModel networkEntryScript(const BlackMisc::Simulation::CAircraftModel &inModel, const BlackMisc::Simulation::CAircraftMatcherSetup &setup, BlackMisc::CStatusMessageList *log);
//! Try to find the corresponding data in DB and get best information for given data //! Try to find the corresponding data in DB and get best information for given data
//! \threadsafe //! \threadsafe
//! \ingroup reverselookup //! \ingroup reverselookup

View File

@@ -746,98 +746,118 @@ namespace BlackCore
const bool hasAnyId = ids.hasAnyId(); const bool hasAnyId = ids.hasAnyId();
if (hasAnyId) { this->markAsSwiftClient(callsign); } if (hasAnyId) { this->markAsSwiftClient(callsign); }
// directly check model string CAircraftModel lookupModel; // result
if (!modelString.isEmpty()) const CAircraftMatcherSetup setup = m_matchingSettings.get();
do
{ {
CAircraftModel model = CAircraftMatcher::reverseLookupModelString(modelString, callsign, log); // directly check model string
model.setCallsign(callsign); if (!modelString.isEmpty())
if (model.hasValidDbKey()) { return model; } // found by model string
}
CLivery livery;
CAirlineIcaoCode airlineIcao;
CAircraftIcaoCode aircraftIcao;
if (hasAnyId)
{
if (ids.model >= 0)
{ {
CAircraftModel model = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log); lookupModel = CAircraftMatcher::reverseLookupModelString(modelString, callsign, log);
model.setCallsign(callsign); if (lookupModel.hasValidDbKey()) { break; } // found by model string
if (model.hasValidDbKey()) { return model; } // found by model id from livery string
};
CAircraftMatcher::reverseLookupByIds(ids, aircraftIcao, livery, callsign, log);
if (livery.hasValidDbKey()) { airlineIcao = livery.getAirlineIcaoCode(); }
if (aircraftIcao.hasValidDbKey() && livery.hasValidDbKey())
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Using DB livery %1 and aircraft ICAO %2 to create model").arg(livery.getDbKeyAsString(), aircraftIcao.getDbKeyAsString()), CAirspaceMonitor::getLogCategories());
// we have a valid livery from DB + valid aircraft ICAO from DB
CAircraftModel model(modelString, type, "By DB livery and aircraft ICAO", aircraftIcao, livery);
model.setCallsign(callsign);
return model;
}
}
// now fuzzy search on aircraft
if (!aircraftIcao.hasValidDbKey())
{
aircraftIcao = CAircraftIcaoCode(aircraftIcaoString);
const bool knownAircraftIcao = CAircraftMatcher::isKnowAircraftDesignator(aircraftIcaoString, callsign, log);
if (airlineIcao.isLoadedFromDb() && !knownAircraftIcao)
{
// we have no valid aircraft ICAO, so we do a fuzzy search among those
const CAircraftIcaoCode foundIcao = CAircraftMatcher::searchAmongAirlineAircraft(aircraftIcaoString, airlineIcao, callsign, log);
if (foundIcao.isLoadedFromDb()) { aircraftIcao = foundIcao; }
}
}
// if we have a livery, we already know the airline, or the livery is a color livery
if (!airlineIcao.hasValidDbKey() && !livery.hasValidDbKey())
{
const CFlightPlanRemarks fpRemarks = this->tryToGetFlightPlanRemarks(callsign);
if (fpRemarks.isEmpty())
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("No flight plan remarks"));
}
else
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("FP remarks: '%1'").arg(fpRemarks.getRemarks()));
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("FP rem.parsed: '%1'").arg(fpRemarks.toQString(true)));
} }
airlineIcao = CAircraftMatcher::failoverValidAirlineIcaoDesignator(callsign, airlineIcaoString, fpRemarks.getAirlineIcao().getDesignator(), true, true, log); CLivery livery;
if (!airlineIcao.isLoadedFromDb() && fpRemarks.hasParsedAirlineRemarks()) CAirlineIcaoCode airlineIcao;
CAircraftIcaoCode aircraftIcao;
if (hasAnyId)
{ {
const QString airlineName = CAircraftMatcher::reverseLookupAirlineName(fpRemarks.getFlightOperator(), callsign, log); if (ids.model >= 0)
if (!airlineName.isEmpty())
{ {
const QString resolvedAirlineName = CAircraftMatcher::reverseLookupAirlineName(airlineName); lookupModel = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log);
airlineIcao.setName(resolvedAirlineName); if (lookupModel.hasValidDbKey()) { break; } // found by model id from livery string
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Setting resolved airline name '%1' from '%2'").arg(resolvedAirlineName, airlineName), CAirspaceMonitor::getLogCategories()); };
}
const QString telephony = CAircraftMatcher::reverseLookupTelephonyDesignator(fpRemarks.getRadioTelephony(), callsign, log); CAircraftMatcher::reverseLookupByIds(ids, aircraftIcao, livery, callsign, log);
if (!telephony.isEmpty()) if (livery.hasValidDbKey()) { airlineIcao = livery.getAirlineIcaoCode(); }
if (aircraftIcao.hasValidDbKey() && livery.hasValidDbKey())
{ {
const QString resolvedTelephony = CAircraftMatcher::reverseLookupTelephonyDesignator(telephony); CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Using DB livery %1 and aircraft ICAO %2 to create model").arg(livery.getDbKeyAsString(), aircraftIcao.getDbKeyAsString()), CAirspaceMonitor::getLogCategories());
airlineIcao.setTelephonyDesignator(resolvedTelephony);
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Setting resolved telephony designator '%1' from '%2'").arg(resolvedTelephony, telephony), CAirspaceMonitor::getLogCategories()); // we have a valid livery from DB + valid aircraft ICAO from DB
lookupModel = CAircraftModel(modelString, type, "By DB livery and aircraft ICAO", aircraftIcao, livery);
break;
} }
} }
if (!airlineIcao.isLoadedFromDb()) // now fuzzy search on aircraft
if (!aircraftIcao.hasValidDbKey())
{ {
// already try to resolve at this stage by a smart lookup with all the filled data from above aircraftIcao = CAircraftIcaoCode(aircraftIcaoString);
airlineIcao = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcao, callsign, log); const bool knownAircraftIcao = CAircraftMatcher::isKnowAircraftDesignator(aircraftIcaoString, callsign, log);
if (airlineIcao.isLoadedFromDb() && !knownAircraftIcao)
{
// we have no valid aircraft ICAO, so we do a fuzzy search among those
const CAircraftIcaoCode foundIcao = CAircraftMatcher::searchAmongAirlineAircraft(aircraftIcaoString, airlineIcao, callsign, log);
if (foundIcao.isLoadedFromDb()) { aircraftIcao = foundIcao; }
}
} }
// if we have a livery, we already know the airline, or the livery is a color livery
if (!airlineIcao.hasValidDbKey() && !livery.hasValidDbKey())
{
const CFlightPlanRemarks fpRemarks = this->tryToGetFlightPlanRemarks(callsign);
if (fpRemarks.isEmpty())
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("No flight plan remarks"));
}
else
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("FP remarks: '%1'").arg(fpRemarks.getRemarks()));
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("FP rem.parsed: '%1'").arg(fpRemarks.toQString(true)));
}
airlineIcao = CAircraftMatcher::failoverValidAirlineIcaoDesignator(callsign, airlineIcaoString, fpRemarks.getAirlineIcao().getDesignator(), true, true, log);
if (!airlineIcao.isLoadedFromDb() && fpRemarks.hasParsedAirlineRemarks())
{
const QString airlineName = CAircraftMatcher::reverseLookupAirlineName(fpRemarks.getFlightOperator(), callsign, log);
if (!airlineName.isEmpty())
{
const QString resolvedAirlineName = CAircraftMatcher::reverseLookupAirlineName(airlineName);
airlineIcao.setName(resolvedAirlineName);
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Setting resolved airline name '%1' from '%2'").arg(resolvedAirlineName, airlineName), CAirspaceMonitor::getLogCategories());
}
const QString telephony = CAircraftMatcher::reverseLookupTelephonyDesignator(fpRemarks.getRadioTelephony(), callsign, log);
if (!telephony.isEmpty())
{
const QString resolvedTelephony = CAircraftMatcher::reverseLookupTelephonyDesignator(telephony);
airlineIcao.setTelephonyDesignator(resolvedTelephony);
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Setting resolved telephony designator '%1' from '%2'").arg(resolvedTelephony, telephony), CAirspaceMonitor::getLogCategories());
}
}
if (!airlineIcao.isLoadedFromDb())
{
// already try to resolve at this stage by a smart lookup with all the filled data from above
airlineIcao = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcao, callsign, log);
}
}
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used aircraft ICAO: '%1'").arg(aircraftIcao.toQString(true)), CAirspaceMonitor::getLogCategories());
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used airline ICAO: '%1'").arg(airlineIcao.toQString(true)), CAirspaceMonitor::getLogCategories());
lookupModel = CAircraftMatcher::reverseLookupModel(callsign, aircraftIcao, airlineIcao, liveryString, modelString, setup, type, log);
}
while (false);
// model found
lookupModel.setCallsign(callsign);
// Script
if (setup.doRunMsNetworkEntryScript())
{
lookupModel = CAircraftMatcher::networkEntryScript(lookupModel, setup, log);
}
else
{
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("No entry script used"));
} }
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used aircraft ICAO: '%1'").arg(aircraftIcao.toQString(true)), CAirspaceMonitor::getLogCategories()); // done
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used airline ICAO: '%1'").arg(airlineIcao.toQString(true)), CAirspaceMonitor::getLogCategories()); return lookupModel;
return CAircraftMatcher::reverseLookupModel(callsign, aircraftIcao, airlineIcao, liveryString, modelString, m_matchingSettings.get(), type, log);
} }
bool CAirspaceMonitor::addNewAircraftInRange(const CSimulatedAircraft &aircraft) bool CAirspaceMonitor::addNewAircraftInRange(const CSimulatedAircraft &aircraft)