mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-16 18:35:35 +08:00
Ref T704, split matching utils for logging in aviation context
This commit is contained in:
committed by
Mat Sutcliffe
parent
07712c27e8
commit
4237839bbd
@@ -6,7 +6,7 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/matchingutils.h"
|
||||
#include "blackmisc/aviation/logutils.h"
|
||||
#include "blackmisc/aviation/aircraftsituationchange.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
@@ -131,7 +131,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->isDbEqual(otherCode))
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QString("Equal DB code: 100"));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QString("Equal DB code: 100"));
|
||||
return 100;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace BlackMisc
|
||||
score += 50; // same designator
|
||||
if (log)
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Same designator: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Same designator: %1").arg(score));
|
||||
}
|
||||
|
||||
int scoreOld = score;
|
||||
@@ -151,7 +151,7 @@ namespace BlackMisc
|
||||
else if (this->getRank() < 10) { score += (10 - this->getRank()); }
|
||||
if (score > scoreOld)
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Added rank: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Added rank: %1").arg(score));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -159,12 +159,12 @@ namespace BlackMisc
|
||||
if (this->hasFamily() && this->getFamily() == otherCode.getFamily())
|
||||
{
|
||||
score += 40;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Added family: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Added family: %1").arg(score));
|
||||
}
|
||||
else if (this->hasValidCombinedType() && otherCode.getCombinedType() == this->getCombinedType())
|
||||
{
|
||||
score += 30;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Added combined code: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Added combined code: %1").arg(score));
|
||||
}
|
||||
else if (this->hasValidCombinedType())
|
||||
{
|
||||
@@ -207,7 +207,7 @@ namespace BlackMisc
|
||||
{
|
||||
score += 4;
|
||||
}
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Added combined code parts: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Added combined code parts: %1").arg(score));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,11 +217,11 @@ namespace BlackMisc
|
||||
if (this->matchesManufacturer(otherCode.getManufacturer()))
|
||||
{
|
||||
score += 10;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Matches manufacturer '%1': %2").arg(this->getManufacturer()).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Matches manufacturer '%1': %2").arg(this->getManufacturer()).arg(score));
|
||||
}
|
||||
else if (this->getManufacturer().contains(otherCode.getManufacturer(), Qt::CaseInsensitive))
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Contains manufacturer '%1': %2").arg(this->getManufacturer()).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Contains manufacturer '%1': %2").arg(this->getManufacturer()).arg(score));
|
||||
score += 5;
|
||||
}
|
||||
}
|
||||
@@ -230,12 +230,12 @@ namespace BlackMisc
|
||||
if (this->hasCategory() && otherCode.hasCategory() && this->getCategory() == otherCode.getCategory())
|
||||
{
|
||||
score += 8;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Matches military flag '%1': %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Matches military flag '%1': %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
}
|
||||
else if (this->isMilitary() == otherCode.isMilitary())
|
||||
{
|
||||
score += 8;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Matches military flag '%1': %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Matches military flag '%1': %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
}
|
||||
// 0..85
|
||||
return score;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "airlineicaocode.h"
|
||||
#include "callsign.h"
|
||||
#include "blackmisc/simulation/matchingutils.h"
|
||||
#include "logutils.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/icons.h"
|
||||
@@ -392,7 +392,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->isDbEqual(otherCode))
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("DB equal score: 100"));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("DB equal score: 100"));
|
||||
return 100;
|
||||
}
|
||||
const bool bothFromDb = this->isLoadedFromDb() && otherCode.isLoadedFromDb();
|
||||
@@ -400,31 +400,31 @@ namespace BlackMisc
|
||||
if (otherCode.hasValidDesignator() && this->getDesignator() == otherCode.getDesignator())
|
||||
{
|
||||
score += 60;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Same designator: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Same designator: %1").arg(score));
|
||||
}
|
||||
|
||||
// only for DB values we check VA
|
||||
if (bothFromDb && this->isVirtualAirline() == otherCode.isVirtualAirline())
|
||||
{
|
||||
score += 20;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("VA equality: %1").arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("VA equality: %1").arg(score));
|
||||
}
|
||||
|
||||
// consider the various names
|
||||
if (this->hasName() && this->getName() == otherCode.getName())
|
||||
{
|
||||
score += 20;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Same name '%1': %2").arg(this->getName()).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Same name '%1': %2").arg(this->getName()).arg(score));
|
||||
}
|
||||
else if (this->hasTelephonyDesignator() && this->getTelephonyDesignator() == otherCode.getTelephonyDesignator())
|
||||
{
|
||||
score += 15;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Same telephony '%1': %2").arg(this->getTelephonyDesignator()).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Same telephony '%1': %2").arg(this->getTelephonyDesignator()).arg(score));
|
||||
}
|
||||
else if (this->hasSimplifiedName() && this->getSimplifiedName() == otherCode.getSimplifiedName())
|
||||
{
|
||||
score += 10;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Same simplified name '%1': %2").arg(this->getSimplifiedName()).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Same simplified name '%1': %2").arg(this->getSimplifiedName()).arg(score));
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
@@ -7,16 +7,25 @@
|
||||
*/
|
||||
|
||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||
#include "blackmisc/aviation/logutils.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
#include "blackmisc/country.h"
|
||||
#include "blackmisc/range.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
#include <QStringBuilder>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
const CLogCategoryList &CAirlineIcaoCodeList::getLogCategories()
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategory::aviation());
|
||||
return cats;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList::CAirlineIcaoCodeList()
|
||||
{ }
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "blackmisc/simulation/matchingutils.h"
|
||||
#include "blackmisc/db/datastoreutility.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/aviation/logutils.h"
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/comparefunctions.h"
|
||||
#include "blackmisc/logcategory.h"
|
||||
@@ -438,7 +438,7 @@ namespace BlackMisc
|
||||
{
|
||||
if (this->isDbEqual(otherLivery))
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Equal DB code: 100"));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Equal DB code: 100"));
|
||||
return 100;
|
||||
}
|
||||
|
||||
@@ -454,7 +454,7 @@ namespace BlackMisc
|
||||
// 2 color liveries 25..85
|
||||
score = 25;
|
||||
score += 60 * colorMultiplier;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("2 color liveries, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("2 color liveries, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
}
|
||||
else if (this->isAirlineLivery() && otherLivery.isAirlineLivery())
|
||||
{
|
||||
@@ -465,10 +465,10 @@ namespace BlackMisc
|
||||
// same ICAO at least means 30, max 50
|
||||
score = qRound(0.5 * this->getAirlineIcaoCode().calculateScore(otherLivery.getAirlineIcaoCode(), log));
|
||||
score += 25 * colorMultiplier;
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("2 airline liveries, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("2 airline liveries, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
if (this->isMilitary() == otherLivery.isMilitary())
|
||||
{
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Mil.flag '%1' matches: %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Mil.flag '%1' matches: %2").arg(boolToYesNo(this->isMilitary())).arg(score));
|
||||
score += 10;
|
||||
}
|
||||
}
|
||||
@@ -479,7 +479,7 @@ namespace BlackMisc
|
||||
// 25 is weaker as same ICAO code / 2 from above
|
||||
score = preferColorLiveries ? 25 : 0;
|
||||
score += 25 * colorMultiplier; // needs to be the same as in 2 airlines
|
||||
CMatchingUtils::addLogDetailsToList(log, *this, QStringLiteral("Color/airline mixed, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
CLogUtilities::addLogDetailsToList(log, *this, QStringLiteral("Color/airline mixed, color multiplier %1: %2").arg(colorMultiplier).arg(score));
|
||||
}
|
||||
return score;
|
||||
}
|
||||
|
||||
81
src/blackmisc/aviation/logutils.cpp
Normal file
81
src/blackmisc/aviation/logutils.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "logutils.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
void CLogUtilities::addLogDetailsToList(CStatusMessageList *log, const CCallsign &callsign, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
if (!log) { return; }
|
||||
if (message.isEmpty()) { return; }
|
||||
log->push_back(CLogUtilities::logMessage(callsign, message, extraCategories, s));
|
||||
}
|
||||
|
||||
void CLogUtilities::addLogDetailsToList(CStatusMessageList *log, const CAircraftIcaoCode &icao, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
if (!log) { return; }
|
||||
if (message.isEmpty()) { return; }
|
||||
log->push_back(CLogUtilities::logMessage(icao, message, extraCategories, s));
|
||||
}
|
||||
|
||||
void CLogUtilities::addLogDetailsToList(CStatusMessageList *log, const CAirlineIcaoCode &icao, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
if (!log) { return; }
|
||||
if (message.isEmpty()) { return; }
|
||||
log->push_back(CLogUtilities::logMessage(icao, message, extraCategories, s));
|
||||
}
|
||||
|
||||
void CLogUtilities::addLogDetailsToList(CStatusMessageList *log, const CLivery &livery, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
if (!log) { return; }
|
||||
if (message.isEmpty()) { return; }
|
||||
log->push_back(CLogUtilities::logMessage(livery, message, extraCategories, s));
|
||||
}
|
||||
|
||||
CStatusMessage CLogUtilities::logMessage(const CCallsign &callsign, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
const CStatusMessage m(categories(extraCategories), s, callsign.isEmpty() ? message.trimmed() : callsign.toQString() + ": " + message.trimmed());
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage CLogUtilities::logMessage(const CAircraftIcaoCode &icaoCode, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
const CStatusMessage m(categories(extraCategories), s, icaoCode.hasDesignator() ? icaoCode.getDesignatorDbKey() + ": " + message.trimmed() : message.trimmed());
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage CLogUtilities::logMessage(const CAirlineIcaoCode &icaoCode, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
const CStatusMessage m(categories(extraCategories), s, icaoCode.hasValidDesignator() ? icaoCode.getVDesignatorDbKey() + ": " + message.trimmed() : message.trimmed());
|
||||
return m;
|
||||
}
|
||||
|
||||
CStatusMessage CLogUtilities::logMessage(const CLivery &livery, const QString &message, const CLogCategoryList &extraCategories, CStatusMessage::StatusSeverity s)
|
||||
{
|
||||
const CStatusMessage m(categories(extraCategories), s, livery.hasCombinedCode() ? livery.getCombinedCodePlusInfoAndId() + ": " + message.trimmed() : message.trimmed());
|
||||
return m;
|
||||
}
|
||||
|
||||
const CLogCategoryList &CLogUtilities::defaultCategories()
|
||||
{
|
||||
static const CLogCategoryList cats({ CLogCategory::aviation() });
|
||||
return cats;
|
||||
}
|
||||
|
||||
CLogCategoryList CLogUtilities::categories(const CLogCategoryList &extraCategories)
|
||||
{
|
||||
if (extraCategories.isEmpty()) { return defaultCategories(); }
|
||||
CLogCategoryList cats(defaultCategories());
|
||||
cats.push_back(extraCategories);
|
||||
return cats;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
95
src/blackmisc/aviation/logutils.h
Normal file
95
src/blackmisc/aviation/logutils.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/* Copyright (C) 2019
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution. No part of swift project, including this file, may be copied, modified, propagated,
|
||||
* or distributed except according to the terms contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AVIATION_MATCHINGUTILS_H
|
||||
#define BLACKMISC_AVIATION_MATCHINGUTILS_H
|
||||
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
/*!
|
||||
* Log.utilities
|
||||
*/
|
||||
class BLACKMISC_EXPORT CLogUtilities
|
||||
{
|
||||
public:
|
||||
//! Specialized log for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static void addLogDetailsToList(CStatusMessageList *log, const CCallsign &callsign,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static void addLogDetailsToList(CStatusMessageList *log, const CAircraftIcaoCode &icao,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static void addLogDetailsToList(CStatusMessageList *log, const CAirlineIcaoCode &icao,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static void addLogDetailsToList(CStatusMessageList *log, const CLivery &livery,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log message for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static CStatusMessage logMessage(
|
||||
const CCallsign &callsign,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log message for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static CStatusMessage logMessage(
|
||||
const CAircraftIcaoCode &icaoCode,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log message for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static CStatusMessage logMessage(
|
||||
const CAirlineIcaoCode &icaoCode,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
//! Specialized log message for matching / reverse lookup
|
||||
//! \threadsafe
|
||||
static CStatusMessage logMessage(
|
||||
const CLivery &livery,
|
||||
const QString &message, const CLogCategoryList &extraCategories = {},
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityInfo);
|
||||
|
||||
private:
|
||||
//! Default categories
|
||||
static const CLogCategoryList &defaultCategories();
|
||||
|
||||
//! Categories
|
||||
static CLogCategoryList categories(const CLogCategoryList &extraCategories);
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
Reference in New Issue
Block a user