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,12 +746,16 @@ namespace BlackCore
const bool hasAnyId = ids.hasAnyId(); const bool hasAnyId = ids.hasAnyId();
if (hasAnyId) { this->markAsSwiftClient(callsign); } if (hasAnyId) { this->markAsSwiftClient(callsign); }
CAircraftModel lookupModel; // result
const CAircraftMatcherSetup setup = m_matchingSettings.get();
do
{
// directly check model string // directly check model string
if (!modelString.isEmpty()) if (!modelString.isEmpty())
{ {
CAircraftModel model = CAircraftMatcher::reverseLookupModelString(modelString, 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 string
} }
CLivery livery; CLivery livery;
@@ -762,9 +766,8 @@ namespace BlackCore
{ {
if (ids.model >= 0) if (ids.model >= 0)
{ {
CAircraftModel model = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log); lookupModel = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log);
model.setCallsign(callsign); if (lookupModel.hasValidDbKey()) { break; } // found by model id from livery string
if (model.hasValidDbKey()) { return model; } // found by model id from livery string
}; };
CAircraftMatcher::reverseLookupByIds(ids, aircraftIcao, livery, callsign, log); CAircraftMatcher::reverseLookupByIds(ids, aircraftIcao, livery, callsign, log);
@@ -775,9 +778,8 @@ namespace BlackCore
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Using DB livery %1 and aircraft ICAO %2 to create model").arg(livery.getDbKeyAsString(), aircraftIcao.getDbKeyAsString()), CAirspaceMonitor::getLogCategories()); 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 // we have a valid livery from DB + valid aircraft ICAO from DB
CAircraftModel model(modelString, type, "By DB livery and aircraft ICAO", aircraftIcao, livery); lookupModel = CAircraftModel(modelString, type, "By DB livery and aircraft ICAO", aircraftIcao, livery);
model.setCallsign(callsign); break;
return model;
} }
} }
@@ -837,7 +839,25 @@ namespace BlackCore
CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used aircraft ICAO: '%1'").arg(aircraftIcao.toQString(true)), CAirspaceMonitor::getLogCategories()); 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()); CMatchingUtils::addLogDetailsToList(log, callsign, QStringLiteral("Used airline ICAO: '%1'").arg(airlineIcao.toQString(true)), CAirspaceMonitor::getLogCategories());
return CAircraftMatcher::reverseLookupModel(callsign, aircraftIcao, airlineIcao, liveryString, modelString, m_matchingSettings.get(), type, log); 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"));
}
// done
return lookupModel;
} }
bool CAirspaceMonitor::addNewAircraftInRange(const CSimulatedAircraft &aircraft) bool CAirspaceMonitor::addNewAircraftInRange(const CSimulatedAircraft &aircraft)