-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
source/plugins/correlation/importannotationskeydetection.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* Copyright © 2013-2023 Graphia Technologies Ltd. | ||
* | ||
* This file is part of Graphia. | ||
* | ||
* Graphia is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graphia is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graphia. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "importannotationskeydetection.h" | ||
|
||
#include "correlationplugin.h" | ||
|
||
#include <QFuture> | ||
#include <QtConcurrentRun> | ||
#include <QQmlEngine> | ||
|
||
using namespace Qt::Literals::StringLiterals; | ||
|
||
ImportAnnotationsKeyDetection::ImportAnnotationsKeyDetection() // NOLINT modernize-use-equals-default | ||
{ | ||
connect(&_watcher, &QFutureWatcher<void>::started, this, &ImportAnnotationsKeyDetection::busyChanged); | ||
connect(&_watcher, &QFutureWatcher<void>::finished, this, &ImportAnnotationsKeyDetection::busyChanged); | ||
} | ||
|
||
ImportAnnotationsKeyDetection::~ImportAnnotationsKeyDetection() // NOLINT modernize-use-equals-default | ||
{ | ||
_watcher.waitForFinished(); | ||
} | ||
|
||
void ImportAnnotationsKeyDetection::start() | ||
{ | ||
uncancel(); | ||
|
||
const QFuture<void> future = QtConcurrent::run([this] | ||
{ | ||
size_t bestRowIndex = 0; | ||
int bestPercent = 0; | ||
|
||
QStringList columnNames; | ||
columnNames.reserve(static_cast<int>(_plugin->numColumns())); | ||
|
||
for(size_t i = 0; i < _plugin->numColumns(); i++) | ||
columnNames.append(_plugin->columnName(i)); | ||
|
||
auto typeIdentities = _tabularData->rowTypeIdentities(); | ||
|
||
for(size_t rowIndex = 0; rowIndex < _tabularData->numRows(); rowIndex++) | ||
{ | ||
auto type = typeIdentities.at(rowIndex).type(); | ||
if(type != TypeIdentity::Type::String && type != TypeIdentity::Type::Int) | ||
continue; | ||
|
||
auto percent = _tabularData->rowMatchPercentage(rowIndex, columnNames); | ||
|
||
// If we already have an equivalent match, prefer the earlier column | ||
if(percent == bestPercent && rowIndex > bestRowIndex) | ||
continue; | ||
|
||
if(percent >= bestPercent) | ||
{ | ||
bestRowIndex = rowIndex; | ||
bestPercent = percent; | ||
} | ||
|
||
// Can't improve on 100%! | ||
if(bestPercent >= 100 || cancelled()) | ||
break; | ||
} | ||
|
||
_result.clear(); | ||
|
||
if(!cancelled()) | ||
{ | ||
_result.insert(u"row"_s, static_cast<int>(bestRowIndex)); | ||
_result.insert(u"percent"_s, bestPercent); | ||
} | ||
|
||
emit resultChanged(); | ||
}); | ||
|
||
_watcher.setFuture(future); | ||
} | ||
|
||
void ImportAnnotationsKeyDetection::reset() | ||
{ | ||
_result = {}; | ||
emit resultChanged(); | ||
} |
61 changes: 61 additions & 0 deletions
61
source/plugins/correlation/importannotationskeydetection.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* Copyright © 2013-2023 Graphia Technologies Ltd. | ||
* | ||
* This file is part of Graphia. | ||
* | ||
* Graphia is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Graphia is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Graphia. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef IMPORTANNOTATIONSKEYDETECTION_H | ||
#define IMPORTANNOTATIONSKEYDETECTION_H | ||
|
||
#include "shared/loading/tabulardata.h" | ||
#include "shared/utils/cancellable.h" | ||
|
||
#include <QObject> | ||
#include <QFutureWatcher> | ||
#include <QVariantMap> | ||
|
||
class CorrelationPluginInstance; | ||
|
||
class ImportAnnotationsKeyDetection : public QObject, public Cancellable | ||
{ | ||
Q_OBJECT | ||
|
||
Q_PROPERTY(CorrelationPluginInstance* plugin MEMBER _plugin) | ||
Q_PROPERTY(std::shared_ptr<TabularData> tabularData MEMBER _tabularData) | ||
Q_PROPERTY(bool busy READ busy NOTIFY busyChanged) | ||
Q_PROPERTY(QVariantMap result MEMBER _result NOTIFY resultChanged) | ||
|
||
private: | ||
CorrelationPluginInstance* _plugin = nullptr; | ||
std::shared_ptr<TabularData> _tabularData = nullptr; | ||
QFutureWatcher<void> _watcher; | ||
QVariantMap _result; | ||
|
||
public: | ||
ImportAnnotationsKeyDetection(); | ||
~ImportAnnotationsKeyDetection() override; | ||
|
||
Q_INVOKABLE void start(); | ||
Q_INVOKABLE void reset(); | ||
Q_INVOKABLE void cancel() override { Cancellable::cancel(); } | ||
|
||
bool busy() const { return _watcher.isRunning(); } | ||
|
||
signals: | ||
void busyChanged(); | ||
void resultChanged(); | ||
}; | ||
|
||
#endif // IMPORTANNOTATIONSKEYDETECTION_H |