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)
{
Q_UNUSED(setup);
CLivery livery;
livery.setAirlineIcaoCode(networkAirlineIcao);
CAircraftModel model(networkModelString, type, {}, networkAircraftIcao, livery);
model.setCallsign(callsign);
model = CAircraftMatcher::reverseLookupModel(model, networkLiveryInfo, log);
model.setModelType(CAircraftModel::TypeReverseLookup);
return model;
}
CAircraftModel CAircraftMatcher::networkEntryScript(const CAircraftModel &inModel, const CAircraftMatcherSetup &setup, CStatusMessageList *log)
{
if (!setup.doRunMsNetworkEntryScript()) { return inModel; }
// 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())
{
const QString js = CFileUtils::readFileToString(setup.getMsNetworkEntryFile());
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");
QJSEngine engine;
// engine.installExtensions(QJSEngine::ConsoleExtension);
@@ -295,15 +311,15 @@ namespace BlackCore
engine.globalObject().setProperty("SwiftValues", jsMetaObject);
MSSwiftValues networkObject(
callsign.asString(),
networkAircraftIcao.getDesignator(), networkAircraftIcao.getDbKey(),
networkAirlineIcao.getDesignator(), networkAirlineIcao.getDbKey(),
networkLiveryInfo, -1
inAircraftIcao.getDesignator(), inAircraftIcao.getDbKey(),
inAirlineIcao.getDesignator(), inAirlineIcao.getDbKey(),
inLivery.getCombinedCode(), inLivery.getDbKey()
);
MSSwiftValues reverseModel(
model.getCallsign().asString(),
model.getAircraftIcaoCode().getDesignator(), model.getAircraftIcaoCode().getDbKey(),
model.getAirlineIcaoCode().getDesignator(), model.getAirlineIcaoCode().getDbKey(),
model.getLivery().getCombinedCode(), model.getLivery().getDbKey()
inModel.getCallsign().asString(),
inModel.getAircraftIcaoCode().getDesignator(), inModel.getAircraftIcaoCode().getDbKey(),
inModel.getAirlineIcaoCode().getDesignator(), inModel.getAirlineIcaoCode().getDbKey(),
inModel.getLivery().getCombinedCode(), inModel.getLivery().getDbKey()
);
MSSwiftValues returnObject;
@@ -318,7 +334,9 @@ namespace BlackCore
ms = ms.call();
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
{
@@ -327,7 +345,7 @@ namespace BlackCore
const QString r = ms.toString();
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;
}
return model;
// not yet using the script model
return inModel;
}
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,
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
//! \threadsafe
//! \ingroup reverselookup

View File

@@ -746,98 +746,118 @@ namespace BlackCore
const bool hasAnyId = ids.hasAnyId();
if (hasAnyId) { this->markAsSwiftClient(callsign); }
// directly check model string
if (!modelString.isEmpty())
CAircraftModel lookupModel; // result
const CAircraftMatcherSetup setup = m_matchingSettings.get();
do
{
CAircraftModel model = CAircraftMatcher::reverseLookupModelString(modelString, callsign, log);
model.setCallsign(callsign);
if (model.hasValidDbKey()) { return model; } // found by model string
}
CLivery livery;
CAirlineIcaoCode airlineIcao;
CAircraftIcaoCode aircraftIcao;
if (hasAnyId)
{
if (ids.model >= 0)
// directly check model string
if (!modelString.isEmpty())
{
CAircraftModel model = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log);
model.setCallsign(callsign);
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)));
lookupModel = CAircraftMatcher::reverseLookupModelString(modelString, callsign, log);
if (lookupModel.hasValidDbKey()) { break; } // found by model string
}
airlineIcao = CAircraftMatcher::failoverValidAirlineIcaoDesignator(callsign, airlineIcaoString, fpRemarks.getAirlineIcao().getDesignator(), true, true, log);
if (!airlineIcao.isLoadedFromDb() && fpRemarks.hasParsedAirlineRemarks())
CLivery livery;
CAirlineIcaoCode airlineIcao;
CAircraftIcaoCode aircraftIcao;
if (hasAnyId)
{
const QString airlineName = CAircraftMatcher::reverseLookupAirlineName(fpRemarks.getFlightOperator(), callsign, log);
if (!airlineName.isEmpty())
if (ids.model >= 0)
{
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());
}
lookupModel = CAircraftMatcher::reverseLookupModelId(ids.model, callsign, log);
if (lookupModel.hasValidDbKey()) { break; } // found by model id from livery string
};
const QString telephony = CAircraftMatcher::reverseLookupTelephonyDesignator(fpRemarks.getRadioTelephony(), callsign, log);
if (!telephony.isEmpty())
CAircraftMatcher::reverseLookupByIds(ids, aircraftIcao, livery, callsign, log);
if (livery.hasValidDbKey()) { airlineIcao = livery.getAirlineIcaoCode(); }
if (aircraftIcao.hasValidDbKey() && livery.hasValidDbKey())
{
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());
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
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
airlineIcao = CAircraftMatcher::reverseLookupAirlineIcao(airlineIcao, callsign, log);
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);
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());
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);
// done
return lookupModel;
}
bool CAirspaceMonitor::addNewAircraftInRange(const CSimulatedAircraft &aircraft)