Ref T658, matching script

This commit is contained in:
Klaus Basan
2019-05-12 00:08:36 +02:00
parent 839e340702
commit 0b4427e39d
9 changed files with 113 additions and 21 deletions

View File

@@ -10,11 +10,13 @@
#include "blackcore/application.h" #include "blackcore/application.h"
#include "blackcore/webdataservices.h" #include "blackcore/webdataservices.h"
#include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/simulation/matchingscript.h"
#include "blackmisc/simulation/matchingutils.h" #include "blackmisc/simulation/matchingutils.h"
#include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/aircrafticaocode.h"
#include "blackmisc/aviation/airlineicaocode.h" #include "blackmisc/aviation/airlineicaocode.h"
#include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/callsign.h"
#include "blackmisc/aviation/livery.h" #include "blackmisc/aviation/livery.h"
#include "blackmisc/fileutils.h"
#include "blackmisc/logcategory.h" #include "blackmisc/logcategory.h"
#include "blackmisc/logcategorylist.h" #include "blackmisc/logcategorylist.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
@@ -26,6 +28,7 @@
#include <QtGlobal> #include <QtGlobal>
#include <QPair> #include <QPair>
#include <QStringBuilder> #include <QStringBuilder>
#include <QJSEngine>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
@@ -270,14 +273,69 @@ namespace BlackCore
return matchedModel; return matchedModel;
} }
CAircraftModel CAircraftMatcher::reverseLookupModel(const CCallsign &callsign, const CAircraftIcaoCode &networkAircraftIcao, const CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, 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)
{ {
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);
// matching script
while (setup.doRunMsNetworkEntryScript())
{
const QString js = CFileUtils::readFileToString(setup.getMsNetworkEntryFile());
if (js.isEmpty()) { break; }
static const QString logFile = CFileUtils::appendFilePaths(CDirectoryUtils::logDirectory(), "logMatchingSriptEntry.log");
QJSEngine engine;
// engine.installExtensions(QJSEngine::ConsoleExtension);
QJSValue jsMetaObject = engine.newQMetaObject(&MSSwiftValues::staticMetaObject);
engine.globalObject().setProperty("SwiftValues", jsMetaObject);
MSSwiftValues networkObject(
callsign.asString(),
networkAircraftIcao.getDesignator(), networkAircraftIcao.getDbKey(),
networkAirlineIcao.getDesignator(), networkAirlineIcao.getDbKey(),
networkLiveryInfo, -1
);
MSSwiftValues reverseModel(
model.getCallsign().asString(),
model.getAircraftIcaoCode().getDesignator(), model.getAircraftIcaoCode().getDbKey(),
model.getAirlineIcaoCode().getDesignator(), model.getAirlineIcaoCode().getDbKey(),
model.getLivery().getCombinedCode(), model.getLivery().getDbKey()
);
MSSwiftValues returnObject;
QJSValue jsNetworkObject = engine.newQObject(&networkObject);
engine.globalObject().setProperty("networkObject", jsNetworkObject);
QJSValue jsReverseObject = engine.newQObject(&networkObject);
engine.globalObject().setProperty("reverseObject", jsNetworkObject);
QJSValue jsReturnObject = engine.newQObject(&returnObject);
engine.globalObject().setProperty("returnObject", jsNetworkObject);
QJSValue ms = engine.evaluate(js, logFile);
ms = ms.call();
if (ms.isError())
{
CLogMessage(getLogCategories()).warning(u"Matching script error: %1 '%2'") << ms.property("lineNumber").toInt() << ms.toString();
}
else
{
if (ms.isString())
{
const QString r = ms.toString();
if (!r.isEmpty())
{
CLogMessage(getLogCategories()).info(u"Matching script: '%1'") << ms.property("lineNumber").toInt() << ms.toString();
}
}
}
// end this
break;
}
return model; return model;
} }

View File

@@ -89,10 +89,10 @@ namespace BlackCore
//! 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
static BlackMisc::Simulation::CAircraftModel reverseLookupModel( static BlackMisc::Simulation::CAircraftModel reverseLookupModel(const BlackMisc::Aviation::CCallsign &callsign,
const BlackMisc::Aviation::CCallsign &callsign,
const BlackMisc::Aviation::CAircraftIcaoCode &networkAircraftIcao, const BlackMisc::Aviation::CAircraftIcaoCode &networkAircraftIcao,
const BlackMisc::Aviation::CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString, const BlackMisc::Aviation::CAirlineIcaoCode &networkAirlineIcao, const QString &networkLiveryInfo, const QString &networkModelString,
const BlackMisc::Simulation::CAircraftMatcherSetup &setup,
BlackMisc::Simulation::CAircraftModel::ModelType type, BlackMisc::Simulation::CAircraftModel::ModelType type,
BlackMisc::CStatusMessageList *log = nullptr); BlackMisc::CStatusMessageList *log = nullptr);

View File

@@ -2,7 +2,7 @@ load(common_pre)
# GUI is required for the matrix classes # GUI is required for the matrix classes
# Network for host info etc. # Network for host info etc.
QT += network dbus xml multimedia QT += network dbus xml multimedia qml
TARGET = blackcore TARGET = blackcore
TEMPLATE = lib TEMPLATE = lib

View File

@@ -35,7 +35,6 @@ namespace BlackGui
{ {
/** /**
* Handle validation result * Handle validation result
* \sa BlackMisc::Views::
*/ */
class BLACKGUI_EXPORT CAircraftModelValidationComponent : public COverlayMessagesFrame class BLACKGUI_EXPORT CAircraftModelValidationComponent : public COverlayMessagesFrame
{ {

View File

@@ -32,6 +32,14 @@
<bool>true</bool> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="qw_MatchingForm"> <widget class="QWidget" name="qw_MatchingForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>296</width>
<height>600</height>
</rect>
</property>
<layout class="QVBoxLayout" name="vl_ScrollAreaContent"> <layout class="QVBoxLayout" name="vl_ScrollAreaContent">
<property name="leftMargin"> <property name="leftMargin">
<number>0</number> <number>0</number>
@@ -50,7 +58,7 @@
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
<height>550</height> <height>600</height>
</size> </size>
</property> </property>
</widget> </widget>

View File

@@ -44,6 +44,16 @@ namespace BlackMisc
return true; return true;
} }
bool CAircraftMatcherSetup::doRunMsNetworkEntryScript() const
{
return m_msNetworkEnabled && !m_msNetworkEntryFile.isEmpty();
}
bool CAircraftMatcherSetup::doRunMsMatchingStageScript() const
{
return m_msMatchingEnabled && !m_msMatchingStageFile.isEmpty();
}
void CAircraftMatcherSetup::setVerificationAtStartup(bool verify) void CAircraftMatcherSetup::setVerificationAtStartup(bool verify)
{ {
MatchingMode m = this->getMatchingMode(); MatchingMode m = this->getMatchingMode();

View File

@@ -137,6 +137,11 @@ namespace BlackMisc
bool isMsMatchingStageEnabled() const { return m_msMatchingEnabled; } bool isMsMatchingStageEnabled() const { return m_msMatchingEnabled; }
//! @} //! @}
//! Run the scripts @{
bool doRunMsNetworkEntryScript() const;
bool doRunMsMatchingStageScript() const;
//! @}
//! Is matching script enabled @{ //! Is matching script enabled @{
void setMsNetworkEntryEnabled(bool enabled) { m_msNetworkEnabled = enabled; } void setMsNetworkEntryEnabled(bool enabled) { m_msNetworkEnabled = enabled; }
void setMsMatchingStageEnabled(bool enabled) { m_msMatchingEnabled = enabled; } void setMsMatchingStageEnabled(bool enabled) { m_msMatchingEnabled = enabled; }

View File

@@ -12,49 +12,49 @@ namespace BlackMisc
{ {
namespace Simulation namespace Simulation
{ {
void MSNetworkValues::setCallsign(const QString &callsign) void MSSwiftValues::setCallsign(const QString &callsign)
{ {
if (m_callsign == callsign) { return; } if (m_callsign == callsign) { return; }
m_callsign = callsign; m_callsign = callsign;
emit this->callsignChanged(); emit this->callsignChanged();
} }
void MSNetworkValues::setDbAircraftIcaoId(int id) void MSSwiftValues::setDbAircraftIcaoId(int id)
{ {
if (id == m_dbAircraftIcaoId) { return; } if (id == m_dbAircraftIcaoId) { return; }
m_dbAircraftIcaoId = id; m_dbAircraftIcaoId = id;
emit this->dbAircraftIcaoIdChanged(); emit this->dbAircraftIcaoIdChanged();
} }
void MSNetworkValues::setDbAirlineIcaoId(int id) void MSSwiftValues::setDbAirlineIcaoId(int id)
{ {
if (id == m_dbAirlineIcaoId) { return; } if (id == m_dbAirlineIcaoId) { return; }
m_dbAirlineIcaoId = id; m_dbAirlineIcaoId = id;
emit this->dbAirlineIcaoIdChanged(); emit this->dbAirlineIcaoIdChanged();
} }
void MSNetworkValues::setDbLiveryId(int id) void MSSwiftValues::setDbLiveryId(int id)
{ {
if (id == m_dbLiveryId) { return; } if (id == m_dbLiveryId) { return; }
m_dbLiveryId = id; m_dbLiveryId = id;
emit this->dbLiveryIdChanged(); emit this->dbLiveryIdChanged();
} }
void MSNetworkValues::setAircraftIcao(const QString &aircraftIcao) void MSSwiftValues::setAircraftIcao(const QString &aircraftIcao)
{ {
if (aircraftIcao == m_aircraftIcao) { return; } if (aircraftIcao == m_aircraftIcao) { return; }
m_aircraftIcao = aircraftIcao; m_aircraftIcao = aircraftIcao;
emit this->aircraftIcaoChanged(); emit this->aircraftIcaoChanged();
} }
void MSNetworkValues::setAirlineIcao(const QString &airlineIcao) void MSSwiftValues::setAirlineIcao(const QString &airlineIcao)
{ {
if (airlineIcao == m_airlineIcao) { return; } if (airlineIcao == m_airlineIcao) { return; }
m_airlineIcao = airlineIcao; m_airlineIcao = airlineIcao;
emit this->airlineIcaoChanged(); emit this->airlineIcaoChanged();
} }
void MSNetworkValues::setLivery(const QString &livery) void MSSwiftValues::setLivery(const QString &livery)
{ {
if (livery == m_livery) { return; } if (livery == m_livery) { return; }
m_livery = livery; m_livery = livery;

View File

@@ -21,7 +21,7 @@ namespace BlackMisc
namespace Simulation namespace Simulation
{ {
//! The network values //! The network values
class BLACKMISC_EXPORT MSNetworkValues : public QObject class BLACKMISC_EXPORT MSSwiftValues : public QObject
{ {
Q_OBJECT Q_OBJECT
@@ -37,7 +37,19 @@ namespace BlackMisc
public: public:
//! Ctor //! Ctor
Q_INVOKABLE MSNetworkValues() {} Q_INVOKABLE MSSwiftValues() {}
//! Ctor
Q_INVOKABLE MSSwiftValues(const QString &cs,
const QString &aircraftIcao, int idAircraftIcao,
const QString &airlineIcao, int idAirlineIcao,
const QString &livery, int liveryId) :
m_callsign(cs.trimmed().toUpper()),
m_aircraftIcao(aircraftIcao.trimmed().toUpper()),
m_airlineIcao(airlineIcao.trimmed().toUpper()),
m_livery(livery.trimmed().toUpper()),
m_dbAircraftIcaoId(idAircraftIcao), m_dbAirlineIcaoId(idAirlineIcao), m_dbLiveryId(liveryId)
{}
//! Get callsign //! Get callsign
const QString &getCallsign() const { return m_callsign; } const QString &getCallsign() const { return m_callsign; }