mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 15:45:46 +08:00
refs #820, utility functions for score and groupBy
This commit is contained in:
@@ -584,6 +584,13 @@ namespace BlackMisc
|
||||
this->m_modelString.startsWith(modelString, sensitivity);
|
||||
}
|
||||
|
||||
int CAircraftModel::calculateScore(const CAircraftModel &compareModel) const
|
||||
{
|
||||
int score = this->getAircraftIcaoCode().calculateScore(compareModel.getAircraftIcaoCode());
|
||||
score += this->getLivery().calculateScore(compareModel.getLivery());
|
||||
return 0.5 * score;
|
||||
}
|
||||
|
||||
CStatusMessageList CAircraftModel::validate(bool withNestedObjects) const
|
||||
{
|
||||
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation() }));
|
||||
|
||||
@@ -338,6 +338,9 @@ namespace BlackMisc
|
||||
//! Matches model string?
|
||||
bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const;
|
||||
|
||||
//! Calculate score
|
||||
int calculateScore(const CAircraftModel &compareModel) const;
|
||||
|
||||
//! Validate
|
||||
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
||||
|
||||
@@ -368,7 +371,7 @@ namespace BlackMisc
|
||||
//! Model mode
|
||||
static ModelMode modelModeFromString(const QString &mode);
|
||||
|
||||
//! Model mode-
|
||||
//! Model mode
|
||||
static const QString &modelModeToString(ModelMode mode);
|
||||
|
||||
//! From swift DB JSON
|
||||
|
||||
@@ -528,6 +528,18 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
ScoredModels CAircraftModelList::scoreFull(const CAircraftModel &remoteModel, bool ignoreZeroScores) const
|
||||
{
|
||||
ScoredModels scoreMap;
|
||||
for (const CAircraftModel &model : *this)
|
||||
{
|
||||
const int score = model.calculateScore(remoteModel);
|
||||
if (ignoreZeroScores && score < 1) { continue; }
|
||||
scoreMap.insertMulti(score, model);
|
||||
}
|
||||
return scoreMap;
|
||||
}
|
||||
|
||||
QStringList CAircraftModelList::toCompleterStrings(bool sorted) const
|
||||
{
|
||||
QStringList c;
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace BlackMisc
|
||||
|
||||
namespace Simulation
|
||||
{
|
||||
//! Individual (matching) score for each model
|
||||
using ScoredModels = QMap<int, CAircraftModel>;
|
||||
|
||||
//! Value object encapsulating a list of aircraft models
|
||||
class BLACKMISC_EXPORT CAircraftModelList :
|
||||
public BlackMisc::CSequence<CAircraftModel>,
|
||||
@@ -204,6 +207,9 @@ namespace BlackMisc
|
||||
//! File name normalized for DB
|
||||
void normalizeFileNamesForDb();
|
||||
|
||||
//! Score by aircraft ICAO code
|
||||
ScoredModels scoreFull(const CAircraftModel &remoteModel, bool ignoreZeroScores = true) const;
|
||||
|
||||
//! Completer strings
|
||||
QStringList toCompleterStrings(bool sorted = true) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user