refs #533, fixed matcher as temporary solution until we have DB data

* the whole concept here will change, see comments CAircraftMatcher::getClosestMatch
* currently returns exact match or default model
* added ASSERT in monitor to detect missing callsign for model at an early stage
This commit is contained in:
Klaus Basan
2015-12-08 06:53:43 +01:00
parent bc65cde182
commit 27bbb3d58c
3 changed files with 60 additions and 37 deletions

View File

@@ -18,6 +18,7 @@
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/propertyindexallclasses.h" #include "blackmisc/propertyindexallclasses.h"
#include "blackmisc/threadutils.h" #include "blackmisc/threadutils.h"
#include "blackmisc/verify.h"
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Audio; using namespace BlackMisc::Audio;
@@ -606,7 +607,8 @@ namespace BlackCore
if (!inRange) if (!inRange)
{ {
// here we assume user has logged out, incomplete data because of traffic sim, etc. // here we assume user has logged out, incomplete data because of traffic sim, etc.
CLogMessage(this).debug() << "Aircraft not in range anymore " << callsign.toQString(); // aircraft is no longer in range, or ws never added to range (no position updates)
CLogMessage(this).debug() << "Aircraft not in range anymore or never added to range " << callsign.toQString();
return; return;
} }
@@ -618,6 +620,7 @@ namespace BlackCore
return; // maybe we like to continue here, hard so say return; // maybe we like to continue here, hard so say
} }
Q_ASSERT_X(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName(), Q_FUNC_INFO, "invalid model data"); Q_ASSERT_X(!m_serverSupportsNameQuery || remoteAircraft.hasValidRealName(), Q_FUNC_INFO, "invalid model data");
Q_ASSERT_X(remoteAircraft.getCallsign() == remoteAircraft.getModel().getCallsign(), Q_FUNC_INFO, "wrong model callsign");
emit this->readyForModelMatching(remoteAircraft); emit this->readyForModelMatching(remoteAircraft);
} }

View File

@@ -57,7 +57,10 @@ namespace BlackMisc
void CAircraftMatcher::setMatchingModes(MatchingMode matchingModes) void CAircraftMatcher::setMatchingModes(MatchingMode matchingModes)
{ {
m_matchingMode = matchingModes; m_matchingMode = matchingModes;
if (m_matchingMode.testFlag(ModelMapping) && m_modelsDatastore.isEmpty()) initMappings(); if (m_matchingMode.testFlag(ModelMapping) && m_modelsFromDatastoreInstalled.isEmpty())
{
initMappings();
}
} }
CAircraftModel CAircraftMatcher::getClosestMatch(const CSimulatedAircraft &remoteAircraft) CAircraftModel CAircraftMatcher::getClosestMatch(const CSimulatedAircraft &remoteAircraft)
@@ -83,25 +86,42 @@ namespace BlackMisc
return aircraftModel; return aircraftModel;
} }
if (remoteAircraft.getModel().hasModelString()) do
{ {
//! \todo this code here is partially nuts and needs to be adjusted
//! as soon as we have real DB data
//! things to change:
//! 1) instead of keeping two lists (DB data + own models) just
//! update / enhance the list of installed models with the DB metadata
//! then there is only one search required
//! 2) Keep a cache of installed models enriched by the DB metadata (that will eliminate all
//! sync processes and can be done offline
//! 3) drivers which can assign reliable ICAO codes should do this as much as possible
//! the sync process with DB will improve those information (by livery details, but in case
//! of now metadata from DB we have the best matching data we can get
//! Also such data can be used in the mapping tool as default values (Less values to type in)
// try to find in installed models by model string
aircraftModel = matchByExactModelName(remoteAircraft); aircraftModel = matchByExactModelName(remoteAircraft);
} if (aircraftModel.hasModelString()) { break; }
if (!aircraftModel.hasModelString()) // ------------ start parts depending on swift DB data -------------------
{
aircraftModel = matchByMapping(remoteAircraft); // by DB ICAO data
} aircraftModel = matchInstalledModelsByIcaoData(remoteAircraft);
if (aircraftModel.hasModelString()) { break; }
// ------------ end parts depending on swift DB data -------------------
if (!aircraftModel.hasModelString())
{
aircraftModel = matchByAlgorithm(remoteAircraft); aircraftModel = matchByAlgorithm(remoteAircraft);
} if (aircraftModel.hasModelString()) { break; }
if (!aircraftModel.hasModelString())
{
aircraftModel = getDefaultModel(); aircraftModel = getDefaultModel();
} }
while (false);
// copy over callsign
aircraftModel.setCallsign(remoteAircraft.getCallsign());
Q_ASSERT_X(!aircraftModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign"); Q_ASSERT_X(!aircraftModel.getCallsign().isEmpty(), Q_FUNC_INFO, "Missing callsign");
Q_ASSERT_X(aircraftModel.hasModelString(), Q_FUNC_INFO, "Missing model string"); Q_ASSERT_X(aircraftModel.hasModelString(), Q_FUNC_INFO, "Missing model string");
@@ -129,11 +149,12 @@ namespace BlackMisc
void CAircraftMatcher::setDefaultModel(const BlackMisc::Simulation::CAircraftModel &defaultModel) void CAircraftMatcher::setDefaultModel(const BlackMisc::Simulation::CAircraftModel &defaultModel)
{ {
m_defaultModel = defaultModel; m_defaultModel = defaultModel;
m_defaultModel.setModelType(CAircraftModel::TypeModelMatchingDefaultModel);
} }
void CAircraftMatcher::ps_setDatastoreModels(const CAircraftModelList &mappings) void CAircraftMatcher::ps_setDatastoreModels(const CAircraftModelList &mappings)
{ {
m_modelsDatastore = mappings; m_modelsFromDatastoreInstalled = mappings;
} }
void CAircraftMatcher::initImpl() void CAircraftMatcher::initImpl()
@@ -144,10 +165,10 @@ namespace BlackMisc
// sync // sync
this->synchronize(); this->synchronize();
CLogMessage(this).debug() << "Mapping definitions after sync" << m_modelsDatastore.size(); CLogMessage(this).debug() << "Mapping definitions after sync" << m_modelsFromDatastoreInstalled.size();
// finish // finish
CLogMessage(this).info("Mapping system: %1 definitions for %2 installed models") << m_modelsDatastore.size() CLogMessage(this).info("Mapping system: %1 definitions for %2 installed models") << m_modelsFromDatastoreInstalled.size()
<< m_installedModels.size(); << m_installedModels.size();
m_initState = InitFinished; m_initState = InitFinished;
emit initializationFinished(); emit initializationFinished();
@@ -160,8 +181,8 @@ namespace BlackMisc
if (mappingsSize < 1) if (mappingsSize < 1)
{ {
m_mappingsProvider->read(); m_mappingsProvider->read();
m_modelsDatastore = m_mappingsProvider->getDatastoreModels(); m_modelsFromDatastoreInstalled = m_mappingsProvider->getDatastoreModels();
mappingsSize = m_modelsDatastore.size(); mappingsSize = m_modelsFromDatastoreInstalled.size();
if (mappingsSize < 1) if (mappingsSize < 1)
{ {
CLogMessage(this).error("Reading mapping rules failed or empty!"); CLogMessage(this).error("Reading mapping rules failed or empty!");
@@ -170,7 +191,7 @@ namespace BlackMisc
return; return;
} }
} }
m_modelsDatastore = m_mappingsProvider->getDatastoreModels(); m_modelsFromDatastoreInstalled = m_mappingsProvider->getDatastoreModels();
CLogMessage(this).debug() << "Mapping definitions" << mappingsSize; CLogMessage(this).debug() << "Mapping definitions" << mappingsSize;
} }
@@ -179,17 +200,14 @@ namespace BlackMisc
return this->m_installedModels.findFirstByModelString(remoteAircraft.getModelString()); return this->m_installedModels.findFirstByModelString(remoteAircraft.getModelString());
} }
CAircraftModel CAircraftMatcher::matchByMapping(const CSimulatedAircraft &remoteAircraft) CAircraftModel CAircraftMatcher::matchInstalledModelsByIcaoData(const CSimulatedAircraft &remoteAircraft)
{ {
CAircraftModel aircraftModel; CAircraftModel aircraftModel;
BlackMisc::Simulation::CAircraftModelList datastoreModels = m_modelsDatastore.findByIcaoDesignators(remoteAircraft.getAircraftIcaoCode(), remoteAircraft.getAirlineIcaoCode()); if (m_modelsFromDatastoreInstalled.isEmpty()) { return aircraftModel; }
BlackMisc::Simulation::CAircraftModelList datastoreModels(m_modelsFromDatastoreInstalled.findByIcaoDesignators(remoteAircraft.getAircraftIcaoCode(), remoteAircraft.getAirlineIcaoCode()));
if (!datastoreModels.isEmpty()) if (!datastoreModels.isEmpty())
{ {
CAircraftModel modelFromMappings = datastoreModels.front(); CAircraftModel aircraftModel(datastoreModels.front());
// now turn the model from the mapping rules into a model from the simulator which has more metadata
aircraftModel = m_installedModels.findFirstByModelString(modelFromMappings.getModelString());
Q_ASSERT(aircraftModel.getModelString() == modelFromMappings.getModelString());
aircraftModel.updateMissingParts(modelFromMappings); // update ICAO
aircraftModel.setModelType(CAircraftModel::TypeModelMatching); aircraftModel.setModelType(CAircraftModel::TypeModelMatching);
} }
return aircraftModel; return aircraftModel;
@@ -203,9 +221,9 @@ namespace BlackMisc
int CAircraftMatcher::synchronizeWithExistingModels(const QStringList &modelNames, Qt::CaseSensitivity cs) int CAircraftMatcher::synchronizeWithExistingModels(const QStringList &modelNames, Qt::CaseSensitivity cs)
{ {
if (modelNames.isEmpty() || m_modelsDatastore.isEmpty()) { return 0; } if (modelNames.isEmpty() || m_modelsFromDatastoreInstalled.isEmpty()) { return 0; }
CAircraftModelList newList; CAircraftModelList newList;
for (const CAircraftModel &modelDatastore : m_modelsDatastore) for (const CAircraftModel &modelDatastore : m_modelsFromDatastoreInstalled)
{ {
if (this->m_initState != InitInProgress) { return 0; } // canceled if (this->m_initState != InitInProgress) { return 0; } // canceled
QString modelString(modelDatastore.getModelString()); QString modelString(modelDatastore.getModelString());
@@ -215,8 +233,8 @@ namespace BlackMisc
newList.push_back(modelDatastore); newList.push_back(modelDatastore);
} }
} }
this->m_modelsDatastore = newList; this->m_modelsFromDatastoreInstalled = newList;
return this->m_modelsDatastore.size(); return this->m_modelsFromDatastoreInstalled.size();
} }
} }
} // namespace } // namespace

View File

@@ -27,7 +27,6 @@ namespace BlackMisc
{ {
namespace Simulation namespace Simulation
{ {
/*! Matcher for all models /*! Matcher for all models
* \details Reads all the mapping rules and all the available flight simulator models. * \details Reads all the mapping rules and all the available flight simulator models.
* Then all rules for models not existing are eliminated ( \sa synchronize ). * Then all rules for models not existing are eliminated ( \sa synchronize ).
@@ -88,7 +87,7 @@ namespace BlackMisc
const BlackMisc::Simulation::CAircraftModelList &getDatastoreModels() const { return m_mappingsProvider->getDatastoreModels(); } const BlackMisc::Simulation::CAircraftModelList &getDatastoreModels() const { return m_mappingsProvider->getDatastoreModels(); }
//! Number of mapping definitions //! Number of mapping definitions
int countMappingRules() const { return m_modelsDatastore.size(); } int countMappingRules() const { return m_modelsFromDatastoreInstalled.size(); }
//! Synchronize models and mappings //! Synchronize models and mappings
//! \remarks after this step, we only have mappings for which we have models //! \remarks after this step, we only have mappings for which we have models
@@ -119,8 +118,12 @@ namespace BlackMisc
void initImpl(); void initImpl();
void initMappings(); void initMappings();
//! Search in installed models by key (aka model string)
CAircraftModel matchByExactModelName(const CSimulatedAircraft &remoteAircraft); CAircraftModel matchByExactModelName(const CSimulatedAircraft &remoteAircraft);
CAircraftModel matchByMapping(const CSimulatedAircraft &remoteAircraft);
//! Installed models by database ICAO data (requires DB entries)
CAircraftModel matchInstalledModelsByIcaoData(const CSimulatedAircraft &remoteAircraft);
CAircraftModel matchByAlgorithm(const CSimulatedAircraft &remoteAircraft); CAircraftModel matchByAlgorithm(const CSimulatedAircraft &remoteAircraft);
//! Synchronize with existing model names, remove unneeded models //! Synchronize with existing model names, remove unneeded models
@@ -130,11 +133,10 @@ namespace BlackMisc
std::atomic<InitState> m_initState { NotInitialized }; std::atomic<InitState> m_initState { NotInitialized };
QPointer<BlackMisc::CWorker> m_initWorker; QPointer<BlackMisc::CWorker> m_initWorker;
MatchingMode m_matchingMode = ModelMatching; MatchingMode m_matchingMode = ModelMatching;
CAircraftModelList m_installedModels; CAircraftModelList m_installedModels; //!< my simulator`s installed models
CAircraftModelList m_modelsDatastore; CAircraftModelList m_modelsFromDatastoreInstalled; //!< models from datastore I do actually have installed
BlackMisc::Simulation::CAircraftModel m_defaultModel; BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< model to be used as default model
}; };
} }
} // namespace } // namespace