diff --git a/core b/core index c08d1b8..a05b0ab 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c08d1b8ad2976824def52cf0fca26a72b1069356 +Subproject commit a05b0ab234936e28b6ba79535ccaee297d83a1e8 diff --git a/gui/include/Visualization/VisualizationGraphWidget.h b/gui/include/Visualization/VisualizationGraphWidget.h index aa21ae9..749d8e0 100644 --- a/gui/include/Visualization/VisualizationGraphWidget.h +++ b/gui/include/Visualization/VisualizationGraphWidget.h @@ -111,8 +111,7 @@ public: signals: void synchronize(const DateTimeRange &range, const DateTimeRange &oldRange); - void requestDataLoading(QVector > variable, const DateTimeRange &range, - bool synchronise); + void changeRange(const std::shared_ptr& variable, const DateTimeRange &range); /// Signal emitted when the variable is about to be removed from the graph void variableAboutToBeRemoved(std::shared_ptr var); diff --git a/gui/src/SqpApplication.cpp b/gui/src/SqpApplication.cpp index 856a6dd..66363a7 100644 --- a/gui/src/SqpApplication.cpp +++ b/gui/src/SqpApplication.cpp @@ -35,9 +35,6 @@ public: sqpApp->variableController().createVariable(variableName,variableMetadata,variableProvider,sqpApp->timeController().dateTime()); }); -// connect(m_VariableController->variableModel(), &VariableModel::requestVariable, -// m_DataSourceController.get(), &DataSourceController::requestVariable); - // VariableController <-> VisualizationController // connect(m_VariableController.get(), // SIGNAL(variableAboutToBeDeleted(std::shared_ptr)), diff --git a/gui/src/TimeWidget/TimeWidget.cpp b/gui/src/TimeWidget/TimeWidget.cpp index 1a88867..abf961e 100644 --- a/gui/src/TimeWidget/TimeWidget.cpp +++ b/gui/src/TimeWidget/TimeWidget.cpp @@ -80,6 +80,7 @@ void TimeWidget::onTimeUpdateRequested() { auto dateTime = timeRange(); emit timeUpdated(std::move(dateTime)); + sqpApp->timeController().setDateTimeRange(dateTime); } void TimeWidget::dragEnterEvent(QDragEnterEvent *event) diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index a73b784..061bd5d 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -297,35 +297,6 @@ void VisualizationGraphWidget::setFlags(GraphFlags flags) void VisualizationGraphWidget::addVariable(std::shared_ptr variable, DateTimeRange range) { - /// Lambda used to set graph's units and range according to the variable passed in parameter - auto loadRange = [this](std::shared_ptr variable, const DateTimeRange &range) { - impl->m_RenderingDelegate->setAxesUnits(*variable); - - this->setFlags(GraphFlag::DisableAll); - setGraphRange(range); - this->setFlags(GraphFlag::EnableAll); - emit requestDataLoading({variable}, range, false); - }; - - connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); - - // Calls update of graph's range and units when the data of the variable have been initialized. - // Note: we use QueuedConnection here as the update event must be called in the UI thread - connect(variable.get(), &Variable::dataInitialized, this, - [ varW = std::weak_ptr{variable}, range, loadRange, this ]() { - if (auto var = varW.lock()) { - // If the variable is the first added in the graph, we load its range - auto firstVariableInGraph = range == INVALID_RANGE; - auto loadedRange = graphRange(); - if (impl->m_VariableAutoRangeOnInit) { - loadedRange = firstVariableInGraph ? var->range() : range; - } - loadRange(var, loadedRange); - setYRange(var); - } - }, - Qt::QueuedConnection); - // Uses delegate to create the qcpplot components according to the variable auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); @@ -336,9 +307,17 @@ void VisualizationGraphWidget::addVariable(std::shared_ptr variable, D // If the variable already has its data loaded, load its units and its range in the graph if (variable->dataSeries() != nullptr) { - loadRange(variable, range); + impl->m_RenderingDelegate->setAxesUnits(*variable); + this->setFlags(GraphFlag::DisableAll); + setGraphRange(range); + this->setFlags(GraphFlag::EnableAll); } - + connect(variable.get(),&Variable::updated, + [variable=variable,this]() + { + QMetaObject::invokeMethod(this,[variable=variable,this](){this->onUpdateVarDisplaying(variable,this->graphRange());}); + }); + this->onUpdateVarDisplaying(variable,range);//My bullshit emit variableAdded(variable); } @@ -395,8 +374,6 @@ DateTimeRange VisualizationGraphWidget::graphRange() const noexcept void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool calibration) { - qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange START"); - if (calibration) { impl->m_IsCalibration = true; } @@ -407,8 +384,6 @@ void VisualizationGraphWidget::setGraphRange(const DateTimeRange &range, bool ca if (calibration) { impl->m_IsCalibration = false; } - - qCDebug(LOG_VisualizationGraphWidget()) << tr("VisualizationGraphWidget::setGraphRange END"); } void VisualizationGraphWidget::setAutoRangeOnVariableInitialization(bool value) @@ -768,29 +743,19 @@ void VisualizationGraphWidget::onGraphMenuRequested(const QPoint &pos) noexcept void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange &t2) { - qCDebug(LOG_VisualizationGraphWidget()) << tr("TORM: VisualizationGraphWidget::onRangeChanged") - << QThread::currentThread()->objectName() << "DoAcqui" - << impl->m_Flags.testFlag(GraphFlag::EnableAcquisition); - auto graphRange = DateTimeRange{t1.lower, t1.upper}; auto oldGraphRange = DateTimeRange{t2.lower, t2.upper}; if (impl->m_Flags.testFlag(GraphFlag::EnableAcquisition)) { - QVector > variableUnderGraphVector; - for (auto it = impl->m_VariableToPlotMultiMap.begin(), end = impl->m_VariableToPlotMultiMap.end(); it != end; it = impl->m_VariableToPlotMultiMap.upper_bound(it->first)) { - variableUnderGraphVector.push_back(it->first); + sqpApp->variableController().asyncChangeRange(it->first, graphRange); } - emit requestDataLoading(std::move(variableUnderGraphVector), graphRange, - !impl->m_IsCalibration); } - if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) { - qCDebug(LOG_VisualizationGraphWidget()) - << tr("TORM: VisualizationGraphWidget::Synchronize notify !!") - << QThread::currentThread()->objectName() << graphRange << oldGraphRange; + if (impl->m_Flags.testFlag(GraphFlag::EnableSynchronization) && !impl->m_IsCalibration) + { emit synchronize(graphRange, oldGraphRange); } @@ -804,9 +769,6 @@ void VisualizationGraphWidget::onRangeChanged(const QCPRange &t1, const QCPRange parentZone->notifyMouseLeaveGraph(this); } } - else { - qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; - } // Quits calibration impl->m_IsCalibration = false; @@ -841,9 +803,6 @@ void VisualizationGraphWidget::onMouseMove(QMouseEvent *event) noexcept parentZone->notifyMouseLeaveGraph(this); } } - else { - qCWarning(LOG_VisualizationGraphWidget()) << "onMouseMove: No parent zone widget"; - } // Search for the selection zone under the mouse auto selectionZoneItemUnderCursor = impl->selectionZoneAt(event->pos(), plot()); @@ -909,7 +868,7 @@ void VisualizationGraphWidget::onMouseWheel(QWheelEvent *event) noexcept plot().setNotAntialiasedElements(QCP::aeAll); } - plot().replot(QCustomPlot::rpQueuedReplot); + //plot().replot(QCustomPlot::rpQueuedReplot); } } } diff --git a/plugins/amda/include/AmdaProvider.h b/plugins/amda/include/AmdaProvider.h index da848e1..65534cb 100644 --- a/plugins/amda/include/AmdaProvider.h +++ b/plugins/amda/include/AmdaProvider.h @@ -23,22 +23,8 @@ public: explicit AmdaProvider(); std::shared_ptr clone() const override; - void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override; + virtual IDataSeries *getData(const DataProviderParameters ¶meters)override; - void requestDataAborting(QUuid acqIdentifier) override; - -private: - void retrieveData(QUuid token, const DateTimeRange &dateTime, const QVariantHash &data); - - void updateRequestProgress(QUuid acqIdentifier, std::shared_ptr request, - double progress); - - std::map, double> > - m_AcqIdToRequestProgressMap; - -private slots: - void onReplyDownloadProgress(QUuid acqIdentifier, - std::shared_ptr networkRequest, double progress); }; #endif // SCIQLOP_AMDAPROVIDER_H diff --git a/plugins/amda/include/AmdaResultParser.h b/plugins/amda/include/AmdaResultParser.h index 3601406..19c8c24 100644 --- a/plugins/amda/include/AmdaResultParser.h +++ b/plugins/amda/include/AmdaResultParser.h @@ -16,6 +16,8 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaResultParser) struct SCIQLOP_AMDA_EXPORT AmdaResultParser { static std::shared_ptr readTxt(const QString &filePath, DataSeriesType valueType) noexcept; + static IDataSeries* readTxt(QTextStream stream, + DataSeriesType type)noexcept; }; #endif // SCIQLOP_AMDARESULTPARSER_H diff --git a/plugins/amda/include/AmdaResultParserHelper.h b/plugins/amda/include/AmdaResultParserHelper.h index dbe6cbd..852fcd0 100644 --- a/plugins/amda/include/AmdaResultParserHelper.h +++ b/plugins/amda/include/AmdaResultParserHelper.h @@ -33,7 +33,7 @@ struct IAmdaResultParserHelper { /// @warning as the data are moved in the data series, the helper shouldn't be used after /// calling this method /// @return the data series created - virtual std::shared_ptr createSeries() = 0; + virtual IDataSeries* createSeries() = 0; /// Reads a line from the AMDA file to extract a property that will be used to generate the data /// series @@ -51,7 +51,7 @@ struct IAmdaResultParserHelper { class ScalarParserHelper : public IAmdaResultParserHelper { public: bool checkProperties() override; - std::shared_ptr createSeries() override; + IDataSeries* createSeries() override; void readPropertyLine(const QString &line) override; void readResultLine(const QString &line) override; @@ -70,7 +70,7 @@ private: class SpectrogramParserHelper : public IAmdaResultParserHelper { public: bool checkProperties() override; - std::shared_ptr createSeries() override; + IDataSeries* createSeries() override; void readPropertyLine(const QString &line) override; void readResultLine(const QString &line) override; @@ -91,7 +91,7 @@ private: class VectorParserHelper : public IAmdaResultParserHelper { public: bool checkProperties() override; - std::shared_ptr createSeries() override; + IDataSeries* createSeries() override; void readPropertyLine(const QString &line) override; void readResultLine(const QString &line) override; diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index 0c23e76..ab38dc0 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") @@ -29,6 +31,16 @@ const auto AMDA_URL_FORMAT = QStringLiteral( "getParameter.php?startTime=%2&stopTime=%3¶meterID=%4&outputFormat=ASCII&" "timeFormat=ISO8601&gzip=0"); +const auto AMDA_URL_FORMAT_WITH_TOKEN = QStringLiteral( + "http://%1/php/rest/" + "getParameter.php?startTime=%2&stopTime=%3¶meterID=%4&outputFormat=ASCII&" + "timeFormat=ISO8601&gzip=0&" + "token=%5"); + +const auto AMDA_TOKEN_URL_FORMAT = QStringLiteral( + "http://%1/php/rest/" + "auth.php"); + /// Dates format passed in the URL (e.g 2013-09-23T09:00) const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:mm:ss"); @@ -44,21 +56,7 @@ QString dateFormat(double sqpRange) noexcept AmdaProvider::AmdaProvider() { - qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::AmdaProvider") << QThread::currentThread(); - if (auto app = sqpApp) { - auto &networkController = app->networkController(); - connect(this, SIGNAL(requestConstructed(std::shared_ptr, QUuid, - std::function)), - &networkController, - SLOT(onProcessRequested(std::shared_ptr, QUuid, - std::function))); - - connect(&sqpApp->networkController(), - SIGNAL(replyDownloadProgress(QUuid, std::shared_ptr, double)), - this, - SLOT(onReplyDownloadProgress(QUuid, std::shared_ptr, double))); - } } std::shared_ptr AmdaProvider::clone() const @@ -67,208 +65,24 @@ std::shared_ptr AmdaProvider::clone() const return std::make_shared(); } -void AmdaProvider::requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) -{ - // NOTE: Try to use multithread if possible - const auto times = parameters.m_Times; - const auto data = parameters.m_Data; - for (const auto &dateTime : qAsConst(times)) { - qCDebug(LOG_AmdaProvider()) << tr("TORM AmdaProvider::requestDataLoading ") << acqIdentifier - << dateTime; - this->retrieveData(acqIdentifier, dateTime, data); - - - // TORM when AMDA will support quick asynchrone request - QThread::msleep(1000); - } -} - -void AmdaProvider::requestDataAborting(QUuid acqIdentifier) -{ - if (auto app = sqpApp) { - auto &networkController = app->networkController(); - networkController.onReplyCanceled(acqIdentifier); - } -} - -void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, - std::shared_ptr networkRequest, - double progress) -{ - qCDebug(LOG_AmdaProvider()) << tr("onReplyDownloadProgress") << acqIdentifier - << networkRequest.get() << progress; - auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); - if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { - - // Update the progression for the current request - auto requestPtr = networkRequest; - auto findRequest = [requestPtr](const auto &entry) { return requestPtr == entry.first; }; - - auto &requestProgressMap = acqIdToRequestProgressMapIt->second; - auto requestProgressMapEnd = requestProgressMap.end(); - auto requestProgressMapIt - = std::find_if(requestProgressMap.begin(), requestProgressMapEnd, findRequest); - - if (requestProgressMapIt != requestProgressMapEnd) { - requestProgressMapIt->second = progress; - } - else { - // This case can happened when a progression is send after the request has been - // finished. - // Generaly the case when aborting a request - qCDebug(LOG_AmdaProvider()) << tr("Can't retrieve Request in progress") << acqIdentifier - << networkRequest.get() << progress; - } - - // Compute the current final progress and notify it - double finalProgress = 0.0; - - auto fraq = requestProgressMap.size(); - - for (auto requestProgress : requestProgressMap) { - finalProgress += requestProgress.second; - qCDebug(LOG_AmdaProvider()) << tr("Current final progress without fraq:") - << finalProgress << requestProgress.second; - } - - if (fraq > 0) { - finalProgress = finalProgress / fraq; - } - - qCDebug(LOG_AmdaProvider()) << tr("Current final progress: ") << fraq << finalProgress; - emit dataProvidedProgress(acqIdentifier, finalProgress); - } - else { - // This case can happened when a progression is send after the request has been finished. - // Generaly the case when aborting a request - emit dataProvidedProgress(acqIdentifier, 100.0); - } -} - -void AmdaProvider::retrieveData(QUuid token, const DateTimeRange &dateTime, const QVariantHash &data) +IDataSeries* AmdaProvider::getData(const DataProviderParameters ¶meters) { - // Retrieves product ID from data: if the value is invalid, no request is made - auto productId = data.value(AMDA_XML_ID_KEY).toString(); - if (productId.isNull()) { - qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id"); - return; - } - - // Retrieves the data type that determines whether the expected format for the result file is - // scalar, vector... + auto range = parameters.m_Times.front(); + auto metaData = parameters.m_Data; + auto productId = metaData.value(AMDA_XML_ID_KEY).toString(); auto productValueType - = DataSeriesTypeUtils::fromString(data.value(AMDA_DATA_TYPE_KEY).toString()); - - // /////////// // - // Creates URL // - // /////////// // - - auto startDate = dateFormat(dateTime.m_TStart); - auto endDate = dateFormat(dateTime.m_TEnd); - - QVariantHash urlProperties{{AMDA_SERVER_KEY, data.value(AMDA_SERVER_KEY)}}; - auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties), - startDate, endDate, productId)}; - qCInfo(LOG_AmdaProvider()) << tr("TORM AmdaProvider::retrieveData url:") << url; - auto tempFile = std::make_shared(); - - // LAMBDA - auto httpDownloadFinished = [this, dateTime, tempFile, - productValueType](QNetworkReply *reply, QUuid dataId) noexcept { - - // Don't do anything if the reply was abort - if (reply->error() == QNetworkReply::NoError) { - - if (tempFile) { - auto replyReadAll = reply->readAll(); - if (!replyReadAll.isEmpty()) { - tempFile->write(replyReadAll); - } - tempFile->close(); - - // Parse results file - if (auto dataSeries - = AmdaResultParser::readTxt(tempFile->fileName(), productValueType)) { - emit dataProvided(dataId, dataSeries, dateTime); - } - else { - /// @todo ALX : debug - emit dataProvidedFailed(dataId); - } - } - m_AcqIdToRequestProgressMap.erase(dataId); - } - else { - qCCritical(LOG_AmdaProvider()) << tr("httpDownloadFinished ERROR"); - emit dataProvidedFailed(dataId); - } - - }; - auto httpFinishedLambda - = [this, httpDownloadFinished, tempFile](QNetworkReply *reply, QUuid dataId) noexcept { - - // Don't do anything if the reply was abort - if (reply->error() == QNetworkReply::NoError) { - auto downloadFileUrl = QUrl{QString{reply->readAll()}.trimmed()}; - - qCInfo(LOG_AmdaProvider()) - << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; - // Executes request for downloading file // - - // Creates destination file - if (tempFile->open()) { - // Executes request and store the request for progression - auto request = std::make_shared(downloadFileUrl); - updateRequestProgress(dataId, request, 0.0); - emit requestConstructed(request, dataId, httpDownloadFinished); - } - else { - emit dataProvidedFailed(dataId); - } - } - else { - qCCritical(LOG_AmdaProvider()) << tr("httpFinishedLambda ERROR"); - m_AcqIdToRequestProgressMap.erase(dataId); - emit dataProvidedFailed(dataId); - } - }; - - // //////////////// // - // Executes request // - // //////////////// // - - auto request = std::make_shared(url); - qCDebug(LOG_AmdaProvider()) << tr("First Request creation") << request.get(); - updateRequestProgress(token, request, 0.0); - - emit requestConstructed(request, token, httpFinishedLambda); + = DataSeriesTypeUtils::fromString(metaData.value(AMDA_DATA_TYPE_KEY).toString()); + auto startDate = dateFormat(range.m_TStart); + auto endDate = dateFormat(range.m_TEnd); + QVariantHash urlProperties{{AMDA_SERVER_KEY, metaData.value(AMDA_SERVER_KEY)}}; + auto token_url = QString{AMDA_TOKEN_URL_FORMAT}.arg(AmdaServer::instance().url(urlProperties)); + auto response = Downloader::get(token_url); + auto url = QString{AMDA_URL_FORMAT_WITH_TOKEN}.arg(AmdaServer::instance().url(urlProperties), + startDate, endDate, productId, QString(response.data())); + response = Downloader::get(url); + auto test = QJsonDocument::fromJson(response.data()); + url = test["dataFileURLs"].toString(); + response = Downloader::get(url); + return AmdaResultParser::readTxt(QTextStream{response.data()},productValueType); } -void AmdaProvider::updateRequestProgress(QUuid acqIdentifier, - std::shared_ptr request, double progress) -{ - qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress request") << request.get(); - auto acqIdToRequestProgressMapIt = m_AcqIdToRequestProgressMap.find(acqIdentifier); - if (acqIdToRequestProgressMapIt != m_AcqIdToRequestProgressMap.end()) { - auto &requestProgressMap = acqIdToRequestProgressMapIt->second; - auto requestProgressMapIt = requestProgressMap.find(request); - if (requestProgressMapIt != requestProgressMap.end()) { - requestProgressMapIt->second = progress; - qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new progress for request") - << acqIdentifier << request.get() << progress; - } - else { - qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new request") << acqIdentifier - << request.get() << progress; - acqIdToRequestProgressMapIt->second.insert(std::make_pair(request, progress)); - } - } - else { - qCDebug(LOG_AmdaProvider()) << tr("updateRequestProgress new acqIdentifier") - << acqIdentifier << request.get() << progress; - auto requestProgressMap = std::map, double>{}; - requestProgressMap.insert(std::make_pair(request, progress)); - m_AcqIdToRequestProgressMap.insert( - std::make_pair(acqIdentifier, std::move(requestProgressMap))); - } -} diff --git a/plugins/amda/src/AmdaResultParser.cpp b/plugins/amda/src/AmdaResultParser.cpp index 2051e91..9c65411 100644 --- a/plugins/amda/src/AmdaResultParser.cpp +++ b/plugins/amda/src/AmdaResultParser.cpp @@ -5,6 +5,7 @@ #include #include +#include Q_LOGGING_CATEGORY(LOG_AmdaResultParser, "AmdaResultParser") @@ -99,14 +100,21 @@ std::shared_ptr AmdaResultParser::readTxt(const QString &filePath, return nullptr; } - QTextStream stream{&file}; + return std::shared_ptr{AmdaResultParser::readTxt(QTextStream{&file},type)}; +} + +IDataSeries *AmdaResultParser::readTxt(QTextStream stream, + DataSeriesType type) noexcept +{ + if (type == DataSeriesType::UNKNOWN) + { + return nullptr; + } // Checks if the file was found on the server auto firstLine = stream.readLine(); - if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) { - qCCritical(LOG_AmdaResultParser()) - << QObject::tr("Can't retrieve AMDA data from file %1: file was not found on server") - .arg(filePath); + if (firstLine.compare(FILE_NOT_FOUND_MESSAGE) == 0) + { return nullptr; } diff --git a/plugins/amda/src/AmdaResultParserHelper.cpp b/plugins/amda/src/AmdaResultParserHelper.cpp index 64ab7de..b3f1537 100644 --- a/plugins/amda/src/AmdaResultParserHelper.cpp +++ b/plugins/amda/src/AmdaResultParserHelper.cpp @@ -249,9 +249,9 @@ bool ScalarParserHelper::checkProperties() QObject::tr("The x-axis unit could not be found in the file")); } -std::shared_ptr ScalarParserHelper::createSeries() +IDataSeries* ScalarParserHelper::createSeries() { - return std::make_shared(std::move(m_XAxisData), std::move(m_ValuesData), + return new ScalarSeries(std::move(m_XAxisData), std::move(m_ValuesData), m_Properties.value(X_AXIS_UNIT_PROPERTY).value(), m_Properties.value(VALUES_UNIT_PROPERTY).value()); } @@ -307,12 +307,12 @@ bool SpectrogramParserHelper::checkProperties() return true; } -std::shared_ptr SpectrogramParserHelper::createSeries() +IDataSeries* SpectrogramParserHelper::createSeries() { // Before creating the series, we handle its data holes handleDataHoles(); - return std::make_shared( + return new SpectrogramSeries( std::move(m_XAxisData), std::move(m_YAxisData), std::move(m_ValuesData), Unit{"t", true}, // x-axis unit is always a time unit m_Properties.value(Y_AXIS_UNIT_PROPERTY).value(), @@ -406,9 +406,9 @@ bool VectorParserHelper::checkProperties() QObject::tr("The x-axis unit could not be found in the file")); } -std::shared_ptr VectorParserHelper::createSeries() +IDataSeries* VectorParserHelper::createSeries() { - return std::make_shared(std::move(m_XAxisData), std::move(m_ValuesData), + return new VectorSeries(std::move(m_XAxisData), std::move(m_ValuesData), m_Properties.value(X_AXIS_UNIT_PROPERTY).value(), m_Properties.value(VALUES_UNIT_PROPERTY).value()); } diff --git a/plugins/amda/tests/PyTestAmdaWrapper.cpp b/plugins/amda/tests/PyTestAmdaWrapper.cpp index 7b2fce0..f7eee31 100644 --- a/plugins/amda/tests/PyTestAmdaWrapper.cpp +++ b/plugins/amda/tests/PyTestAmdaWrapper.cpp @@ -115,11 +115,11 @@ PYBIND11_MODULE(pytestamda, m){ py::class_, IDataProvider>(m, "AmdaProvider"); - py::class_(m, "AmdaResultParser") - .def_static("readTxt", AmdaResultParser::readTxt) - .def("readScalarTxt", [](const QString& path){ - return std::dynamic_pointer_cast(AmdaResultParser::readTxt(path, DataSeriesType::SCALAR)); - }, py::return_value_policy::copy); +// py::class_(m, "AmdaResultParser") +// .def_static("readTxt", AmdaResultParser::readTxt) +// .def("readScalarTxt", [](const QString& path){ +// return std::dynamic_pointer_cast(AmdaResultParser::readTxt(path, DataSeriesType::SCALAR)); +// }, py::return_value_policy::copy); } diff --git a/plugins/mockplugin/CMakeLists.txt b/plugins/mockplugin/CMakeLists.txt index 350f255..92e7e43 100644 --- a/plugins/mockplugin/CMakeLists.txt +++ b/plugins/mockplugin/CMakeLists.txt @@ -25,5 +25,5 @@ include(sciqlop_tests) add_definitions(-DMOCKPLUGIN_TESTS_RESOURCES_DIR="${CMAKE_CURRENT_LIST_DIR}/tests-resources") -declare_test(TestCosinusAcquisition TestCosinusAcquisition tests/TestCosinusAcquisition.cpp "mockplugin;Qt5::Test") +#declare_test(TestCosinusAcquisition TestCosinusAcquisition tests/TestCosinusAcquisition.cpp "mockplugin;Qt5::Test") diff --git a/plugins/mockplugin/include/CosinusProvider.h b/plugins/mockplugin/include/CosinusProvider.h index 1d02ef6..0bf24ef 100644 --- a/plugins/mockplugin/include/CosinusProvider.h +++ b/plugins/mockplugin/include/CosinusProvider.h @@ -9,7 +9,6 @@ #include #include -Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider) /** * @brief The CosinusProvider class is an example of how a data provider can generate data @@ -18,21 +17,8 @@ class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider { public: std::shared_ptr clone() const override; - /// @sa IDataProvider::requestDataLoading(). The current impl isn't thread safe. - void requestDataLoading(QUuid acqIdentifier, const DataProviderParameters ¶meters) override; - - virtual IDataSeries* getData(const DataProviderParameters ¶meters) override; - /// @sa IDataProvider::requestDataAborting(). The current impl isn't thread safe. - void requestDataAborting(QUuid acqIdentifier) override; - - - /// Provide data - std::shared_ptr provideDataSeries(const DateTimeRange &dataRangeRequested, - const QVariantHash &data); - - private: std::shared_ptr retrieveData(QUuid acqIdentifier, const DateTimeRange &dataRangeRequested, const QVariantHash &data); diff --git a/plugins/mockplugin/src/CosinusProvider.cpp b/plugins/mockplugin/src/CosinusProvider.cpp index 0cfd001..51dc75d 100644 --- a/plugins/mockplugin/src/CosinusProvider.cpp +++ b/plugins/mockplugin/src/CosinusProvider.cpp @@ -13,7 +13,6 @@ #include #include -Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider") namespace { @@ -158,95 +157,6 @@ std::shared_ptr CosinusProvider::clone() const return std::make_shared(); } -std::shared_ptr CosinusProvider::retrieveData(QUuid acqIdentifier, - const DateTimeRange &dataRangeRequested, - const QVariantHash &data) -{ - // TODO: Add Mutex - auto dataIndex = 0; - - // Retrieves cosinus type - auto typeVariant = data.value(COSINUS_TYPE_KEY, COSINUS_TYPE_DEFAULT_VALUE); - if (!typeVariant.canConvert()) { - qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid type"); - return nullptr; - } - - auto type = cosinusType(typeVariant.toString()); - if (!type) { - qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: unknown type"); - return nullptr; - } - - // Retrieves frequency - auto freqVariant = data.value(COSINUS_FREQUENCY_KEY, COSINUS_FREQUENCY_DEFAULT_VALUE); - if (!freqVariant.canConvert()) { - qCCritical(LOG_CosinusProvider()) << tr("Can't retrieve data: invalid frequency"); - return nullptr; - } - - // Gets the timerange from the parameters - double freq = freqVariant.toDouble(); - double start = std::ceil(dataRangeRequested.m_TStart * freq); - double end = std::floor(dataRangeRequested.m_TEnd * freq); - - // We assure that timerange is valid - if (end < start) { - std::swap(start, end); - } - - // Generates scalar series containing cosinus values (one value per second, end value is - // included) - auto dataCount = end - start + 1; - - // Number of components (depending on the cosinus type) - auto componentCount = type->componentCount(); - - auto xAxisData = std::vector{}; - xAxisData.resize(dataCount); - - auto valuesData = std::vector{}; - valuesData.resize(dataCount * componentCount); - - int progress = 0; - auto progressEnd = dataCount; - for (auto time = start; time <= end; ++time, ++dataIndex) { - auto it = m_VariableToEnableProvider.find(acqIdentifier); - if (it != m_VariableToEnableProvider.end() && it.value()) { - const auto x = time / freq; - - xAxisData[dataIndex] = x; - - // Generates values (depending on the type) - type->generateValues(x, valuesData, dataIndex); - - // progression - int currentProgress = (time - start) * 100.0 / progressEnd; - if (currentProgress != progress) { - progress = currentProgress; - - emit dataProvidedProgress(acqIdentifier, progress); - qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::retrieveData" - << QThread::currentThread()->objectName() - << progress; - // NOTE: Try to use multithread if possible - } - } - else { - if (!it.value()) { - qCDebug(LOG_CosinusProvider()) - << "CosinusProvider::retrieveData: ARRET De l'acquisition detecté" - << end - time; - } - } - } - if (progress != 100) { - // We can close progression beacause all data has been retrieved - emit dataProvidedProgress(acqIdentifier, 100); - } - return std::shared_ptr(type->createDataSeries(std::move(xAxisData), std::move(valuesData))); -} - IDataSeries *CosinusProvider::_generate(const DateTimeRange &range, const QVariantHash &metaData) { auto dataIndex = 0; @@ -282,51 +192,8 @@ IDataSeries *CosinusProvider::_generate(const DateTimeRange &range, const QVaria return type->createDataSeries(std::move(xAxisData), std::move(valuesData)); } -void CosinusProvider::requestDataLoading(QUuid acqIdentifier, - const DataProviderParameters ¶meters) -{ - // TODO: Add Mutex - m_VariableToEnableProvider[acqIdentifier] = true; - qCDebug(LOG_CosinusProvider()) << "TORM: CosinusProvider::requestDataLoading" - << QThread::currentThread()->objectName(); - // NOTE: Try to use multithread if possible - const auto times = parameters.m_Times; - - for (const auto &dateTime : qAsConst(times)) { - if (m_VariableToEnableProvider[acqIdentifier]) { - auto scalarSeries = this->retrieveData(acqIdentifier, dateTime, parameters.m_Data); - emit dataProvided(acqIdentifier, scalarSeries, dateTime); - } - } -} - IDataSeries* CosinusProvider::getData(const DataProviderParameters ¶meters) { return _generate(parameters.m_Times.front(),parameters.m_Data); } - -void CosinusProvider::requestDataAborting(QUuid acqIdentifier) -{ - qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataAborting" << acqIdentifier - << QThread::currentThread()->objectName(); - auto it = m_VariableToEnableProvider.find(acqIdentifier); - if (it != m_VariableToEnableProvider.end()) { - it.value() = false; - } - else { - qCDebug(LOG_CosinusProvider()) - << tr("Aborting progression of inexistant identifier detected !!!"); - } -} - -std::shared_ptr CosinusProvider::provideDataSeries(const DateTimeRange &dataRangeRequested, - const QVariantHash &data) -{ - auto uid = QUuid::createUuid(); - m_VariableToEnableProvider[uid] = true; - auto dataSeries = this->retrieveData(uid, dataRangeRequested, data); - - m_VariableToEnableProvider.remove(uid); - return dataSeries; -} diff --git a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp b/plugins/mockplugin/tests/TestCosinusAcquisition.cpp deleted file mode 100644 index 3112e92..0000000 --- a/plugins/mockplugin/tests/TestCosinusAcquisition.cpp +++ /dev/null @@ -1,195 +0,0 @@ -#include "CosinusProvider.h" -#include "MockDefs.h" - -#include -#include -#include -#include