diff --git a/core/include/Data/AcquisitionRequest.h b/core/include/Data/AcquisitionRequest.h index 9e2b0de..2095b5e 100644 --- a/core/include/Data/AcquisitionRequest.h +++ b/core/include/Data/AcquisitionRequest.h @@ -28,8 +28,6 @@ struct AcquisitionRequest { QUuid m_AcqIdentifier; QUuid m_vIdentifier; DataProviderParameters m_DataProviderParameters; - SqpRange m_RangeRequested; - SqpRange m_CacheRangeRequested; int m_Size; int m_Progression; std::shared_ptr m_Provider; diff --git a/core/include/Variable/VariableAcquisitionWorker.h b/core/include/Variable/VariableAcquisitionWorker.h index f5badbc..9b5ee8c 100644 --- a/core/include/Variable/VariableAcquisitionWorker.h +++ b/core/include/Variable/VariableAcquisitionWorker.h @@ -28,8 +28,8 @@ public: explicit VariableAcquisitionWorker(QObject *parent = 0); virtual ~VariableAcquisitionWorker(); - QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, SqpRange rangeRequested, - SqpRange cacheRangeRequested, DataProviderParameters parameters, + QUuid pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, + DataProviderParameters parameters, std::shared_ptr provider); void abortProgressRequested(QUuid vIdentifier); @@ -37,9 +37,7 @@ public: void initialize(); void finalize(); signals: - void dataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, - const SqpRange &cacheRangeRequested, - QVector dataAcquired); + void dataProvided(QUuid vIdentifier, QVector dataAcquired); void variableRequestInProgress(QUuid vIdentifier, double progress); diff --git a/core/include/Variable/VariableController.h b/core/include/Variable/VariableController.h index 9238f8a..969b071 100644 --- a/core/include/Variable/VariableController.h +++ b/core/include/Variable/VariableController.h @@ -112,9 +112,7 @@ public slots: void onUpdateDateTime(std::shared_ptr variable, const SqpRange &dateTime); - void onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, - const SqpRange &cacheRangeRequested, - QVector dataAcquired); + void onDataProvided(QUuid vIdentifier, QVector dataAcquired); void onVariableRetrieveDataInProgress(QUuid identifier, double progress); diff --git a/core/src/Variable/VariableAcquisitionWorker.cpp b/core/src/Variable/VariableAcquisitionWorker.cpp index 479293a..bb2a7c0 100644 --- a/core/src/Variable/VariableAcquisitionWorker.cpp +++ b/core/src/Variable/VariableAcquisitionWorker.cpp @@ -29,9 +29,6 @@ struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { void removeVariableRequest(QUuid vIdentifier); - /// Remove the current request and execute the next one if exist - void updateToNextRequest(QUuid vIdentifier); - /// Remove and/or abort all AcqRequest in link with varRequestId void cancelVarRequest(QUuid varRequestId); void removeAcqRequest(QUuid acqRequestId); @@ -41,7 +38,7 @@ struct VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate { std::map > m_AcqIdentifierToAcqDataPacketVectorMap; std::map m_AcqIdentifierToAcqRequestMap; - std::map > m_VIdentifierToCurrrentAcqIdNextIdPairMap; + std::map m_VIdentifierToCurrrentAcqIdMap; VariableAcquisitionWorker *q; }; @@ -60,26 +57,23 @@ VariableAcquisitionWorker::~VariableAcquisitionWorker() QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid vIdentifier, - SqpRange rangeRequested, - SqpRange cacheRangeRequested, DataProviderParameters parameters, std::shared_ptr provider) { qCDebug(LOG_VariableAcquisitionWorker()) - << tr("TORM VariableAcquisitionWorker::pushVariableRequest ") << cacheRangeRequested; + << tr("TORM VariableAcquisitionWorker::pushVariableRequest varRequestId: ") << varRequestId + << "vId: " << vIdentifier; auto varRequestIdCanceled = QUuid(); // Request creation auto acqRequest = AcquisitionRequest{}; - qCDebug(LOG_VariableAcquisitionWorker()) << tr("PushVariableRequest ") << vIdentifier - << varRequestId; acqRequest.m_VarRequestId = varRequestId; acqRequest.m_vIdentifier = vIdentifier; acqRequest.m_DataProviderParameters = parameters; - acqRequest.m_RangeRequested = rangeRequested; - acqRequest.m_CacheRangeRequested = cacheRangeRequested; acqRequest.m_Size = parameters.m_Times.size(); acqRequest.m_Provider = provider; + qCInfo(LOG_VariableAcquisitionWorker()) << tr("Add acqRequest ") << acqRequest.m_AcqIdentifier + << acqRequest.m_Size; // Register request @@ -87,33 +81,32 @@ QUuid VariableAcquisitionWorker::pushVariableRequest(QUuid varRequestId, QUuid v impl->m_AcqIdentifierToAcqRequestMap.insert( std::make_pair(acqRequest.m_AcqIdentifier, acqRequest)); - auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); - if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { - // A current request already exists, we can replace the next one - auto oldAcqId = it->second.second; + auto it = impl->m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier); + if (it != impl->m_VIdentifierToCurrrentAcqIdMap.cend()) { + // A current request already exists, we can cancel it + // remove old acqIdentifier from the worker + auto oldAcqId = it->second; auto acqIdentifierToAcqRequestMapIt = impl->m_AcqIdentifierToAcqRequestMap.find(oldAcqId); if (acqIdentifierToAcqRequestMapIt != impl->m_AcqIdentifierToAcqRequestMap.cend()) { auto oldAcqRequest = acqIdentifierToAcqRequestMapIt->second; varRequestIdCanceled = oldAcqRequest.m_VarRequestId; } - - it->second.second = acqRequest.m_AcqIdentifier; impl->unlock(); - - // remove old acqIdentifier from the worker impl->cancelVarRequest(varRequestIdCanceled); - // impl->m_AcqIdentifierToAcqRequestMap.erase(oldAcqId); } else { - // First request for the variable, it must be stored and executed - impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.insert( - std::make_pair(vIdentifier, std::make_pair(acqRequest.m_AcqIdentifier, QUuid()))); impl->unlock(); - - QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, - Q_ARG(QUuid, acqRequest.m_AcqIdentifier)); } + // Request for the variable, it must be stored and executed + impl->lockWrite(); + impl->m_VIdentifierToCurrrentAcqIdMap.insert( + std::make_pair(vIdentifier, acqRequest.m_AcqIdentifier)); + impl->unlock(); + + QMetaObject::invokeMethod(this, "onExecuteRequest", Qt::QueuedConnection, + Q_ARG(QUuid, acqRequest.m_AcqIdentifier)); + return varRequestIdCanceled; } @@ -121,18 +114,15 @@ void VariableAcquisitionWorker::abortProgressRequested(QUuid vIdentifier) { impl->lockRead(); - auto it = impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); - if (it != impl->m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { - auto currentAcqId = it->second.first; + auto it = impl->m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier); + if (it != impl->m_VIdentifierToCurrrentAcqIdMap.cend()) { + auto currentAcqId = it->second; auto it = impl->m_AcqIdentifierToAcqRequestMap.find(currentAcqId); if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { auto request = it->second; impl->unlock(); - // Remove the current request from the worker - impl->updateToNextRequest(vIdentifier); - // notify the request aborting to the provider request.m_Provider->requestDataAborting(currentAcqId); } @@ -151,22 +141,29 @@ void VariableAcquisitionWorker::onVariableRetrieveDataInProgress(QUuid acqIdenti double progress) { qCDebug(LOG_VariableAcquisitionWorker()) << tr("TORM: onVariableRetrieveDataInProgress ") + << QThread::currentThread()->objectName() << acqIdentifier << progress; impl->lockRead(); auto aIdToARit = impl->m_AcqIdentifierToAcqRequestMap.find(acqIdentifier); if (aIdToARit != impl->m_AcqIdentifierToAcqRequestMap.cend()) { - auto currentPartSize = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0; + auto progressPartSize + = (aIdToARit->second.m_Size != 0) ? 100 / aIdToARit->second.m_Size : 0; auto currentPartProgress - = std::isnan(progress) ? 0.0 : (progress * currentPartSize) / 100.0; - auto currentAlreadyProgress = aIdToARit->second.m_Progression * currentPartSize; + = std::isnan(progress) ? 0.0 : (progress * progressPartSize) / 100.0; + + // We can only give an approximation of the currentProgression since its upgrade is async. + auto currentProgression = aIdToARit->second.m_Progression; + if (currentProgression == aIdToARit->second.m_Size) { + currentProgression = aIdToARit->second.m_Size - 1; + } + + auto currentAlreadyProgress = progressPartSize * currentProgression; + auto finalProgression = currentAlreadyProgress + currentPartProgress; emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, finalProgression); - qCDebug(LOG_VariableAcquisitionWorker()) - << tr("TORM: onVariableRetrieveDataInProgress ") - << QThread::currentThread()->objectName() << aIdToARit->second.m_vIdentifier - << currentPartSize << currentAlreadyProgress << currentPartProgress << finalProgression; + if (finalProgression == 100.0) { emit variableRequestInProgress(aIdToARit->second.m_vIdentifier, 0.0); } @@ -183,14 +180,10 @@ void VariableAcquisitionWorker::onVariableAcquisitionFailed(QUuid acqIdentifier) if (it != impl->m_AcqIdentifierToAcqRequestMap.cend()) { auto request = it->second; impl->unlock(); - qCDebug(LOG_VariableAcquisitionWorker()) << tr("onVariableAcquisitionFailed") - << acqIdentifier << request.m_vIdentifier - << QThread::currentThread(); emit variableCanceledRequested(request.m_vIdentifier); } else { impl->unlock(); - // TODO log no acqIdentifier recognized } } @@ -228,17 +221,12 @@ void VariableAcquisitionWorker::onVariableDataAcquired(QUuid acqIdentifier, // removed the finished request if (acqRequest.m_Size == acqRequest.m_Progression) { auto varId = acqRequest.m_vIdentifier; - auto rangeRequested = acqRequest.m_RangeRequested; - auto cacheRangeRequested = acqRequest.m_CacheRangeRequested; // Return the data aIdToADPVit = impl->m_AcqIdentifierToAcqDataPacketVectorMap.find(acqIdentifier); if (aIdToADPVit != impl->m_AcqIdentifierToAcqDataPacketVectorMap.cend()) { - emit dataProvided(varId, rangeRequested, cacheRangeRequested, aIdToADPVit->second); + emit dataProvided(varId, aIdToADPVit->second); } impl->unlock(); - - // Update to the next request - impl->updateToNextRequest(acqRequest.m_vIdentifier); } else { impl->unlock(); @@ -260,6 +248,8 @@ void VariableAcquisitionWorker::onExecuteRequest(QUuid acqIdentifier) auto request = it->second; impl->unlock(); emit variableRequestInProgress(request.m_vIdentifier, 0.1); + qCDebug(LOG_VariableAcquisitionWorker()) << tr("Start request 10%") << acqIdentifier + << QThread::currentThread(); request.m_Provider->requestDataLoading(acqIdentifier, request.m_DataProviderParameters); } else { @@ -290,61 +280,30 @@ void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeVariable QUuid vIdentifier) { lockWrite(); - auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); + auto it = m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier); - if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { + if (it != m_VIdentifierToCurrrentAcqIdMap.cend()) { // A current request already exists, we can replace the next one - m_AcqIdentifierToAcqRequestMap.erase(it->second.first); - m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.first); - - m_AcqIdentifierToAcqRequestMap.erase(it->second.second); - m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second.second); + qCDebug(LOG_VariableAcquisitionWorker()) + << "VariableAcquisitionWorkerPrivate::removeVariableRequest " + << QThread::currentThread()->objectName() << it->second; + m_AcqIdentifierToAcqRequestMap.erase(it->second); + m_AcqIdentifierToAcqDataPacketVectorMap.erase(it->second); } - m_VIdentifierToCurrrentAcqIdNextIdPairMap.erase(vIdentifier); - unlock(); -} -void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::updateToNextRequest( - QUuid vIdentifier) -{ - lockRead(); - auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); - if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { - if (it->second.second.isNull()) { - unlock(); - // There is no next request, we can remove the variable request - removeVariableRequest(vIdentifier); - } - else { - auto acqIdentifierToRemove = it->second.first; - // Move the next request to the current request - auto nextRequestId = it->second.second; - it->second.first = nextRequestId; - it->second.second = QUuid(); - unlock(); - // Remove AcquisitionRequest and results; - lockWrite(); - m_AcqIdentifierToAcqRequestMap.erase(acqIdentifierToRemove); - m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqIdentifierToRemove); - unlock(); - // Execute the current request - QMetaObject::invokeMethod(q, "onExecuteRequest", Qt::QueuedConnection, - Q_ARG(QUuid, nextRequestId)); - } - } - else { - unlock(); - qCCritical(LOG_VariableAcquisitionWorker()) - << tr("Impossible to execute the acquisition on an unfound variable "); - } + // stop any progression + emit q->variableRequestInProgress(vIdentifier, 0.0); + + m_VIdentifierToCurrrentAcqIdMap.erase(vIdentifier); + unlock(); } void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::cancelVarRequest( QUuid varRequestId) { qCDebug(LOG_VariableAcquisitionWorker()) - << "VariableAcquisitionWorkerPrivate::cancelVarRequest 0"; + << "VariableAcquisitionWorkerPrivate::cancelVarRequest start"; lockRead(); // get all AcqIdentifier in link with varRequestId QVector acqIdsToRm; @@ -377,22 +336,15 @@ void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqReque vIdentifier = acqIt->second.m_vIdentifier; provider = acqIt->second.m_Provider; - auto it = m_VIdentifierToCurrrentAcqIdNextIdPairMap.find(vIdentifier); - if (it != m_VIdentifierToCurrrentAcqIdNextIdPairMap.cend()) { - if (it->second.first == acqRequestId) { + auto it = m_VIdentifierToCurrrentAcqIdMap.find(vIdentifier); + if (it != m_VIdentifierToCurrrentAcqIdMap.cend()) { + if (it->second == acqRequestId) { // acqRequest is currently running -> let's aborting it unlock(); - // Remove the current request from the worker - updateToNextRequest(vIdentifier); - // notify the request aborting to the provider provider->requestDataAborting(acqRequestId); } - else if (it->second.second == acqRequestId) { - it->second.second = QUuid(); - unlock(); - } else { unlock(); } @@ -409,6 +361,7 @@ void VariableAcquisitionWorker::VariableAcquisitionWorkerPrivate::removeAcqReque m_AcqIdentifierToAcqDataPacketVectorMap.erase(acqRequestId); m_AcqIdentifierToAcqRequestMap.erase(acqRequestId); + m_VIdentifierToCurrrentAcqIdMap.erase(vIdentifier); unlock(); qCDebug(LOG_VariableAcquisitionWorker()) diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index 916d0cb..18958df 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -368,11 +368,6 @@ VariableController::createVariable(const QString &name, const QVariantHash &meta this->onRequestDataLoading(QVector >{newVariable}, range, false); - // auto varRequestId = QUuid::createUuid(); - // qCInfo(LOG_VariableController()) << "createVariable: " << varId << varRequestId; - // impl->processRequest(newVariable, range, varRequestId); - // impl->updateVariableRequest(varRequestId); - emit variableAdded(newVariable); return newVariable; @@ -390,20 +385,6 @@ void VariableController::onDateTimeOnSelection(const SqpRange &dateTime) auto selectedRows = impl->m_VariableSelectionModel->selectedRows(); // NOTE we only permit the time modification for one variable - // DEPRECATED - // auto variables = QVector >{}; - // for (const auto &selectedRow : qAsConst(selectedRows)) { - // if (auto selectedVariable = - // impl->m_VariableModel->variable(selectedRow.row())) { - // variables << selectedVariable; - - // // notify that rescale operation has to be done - // emit rangeChanged(selectedVariable, dateTime); - // } - // } - // if (!variables.isEmpty()) { - // this->onRequestDataLoading(variables, dateTime, synchro); - // } if (selectedRows.size() == 1) { if (auto selectedVariable @@ -441,8 +422,7 @@ void VariableController::onUpdateDateTime(std::shared_ptr variable, this->onRequestDataLoading(QVector >{variable}, dateTime, synchro); } -void VariableController::onDataProvided(QUuid vIdentifier, const SqpRange &rangeRequested, - const SqpRange &cacheRangeRequested, +void VariableController::onDataProvided(QUuid vIdentifier, QVector dataAcquired) { qCDebug(LOG_VariableController()) << tr("onDataProvided") << QThread::currentThread(); @@ -459,6 +439,8 @@ void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub << "TORM: variableController::onVariableRetrieveDataInProgress" << QThread::currentThread()->objectName() << progress; if (auto var = impl->findVariable(identifier)) { + qCDebug(LOG_VariableController()) + << "TORM: variableController::onVariableRetrieveDataInProgress FOUND"; impl->m_VariableModel->setDataProgress(var, progress); } else { @@ -590,7 +572,7 @@ void VariableController::onRequestDataLoading(QVector } impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); for (const auto &var : variables) { - qCDebug(LOG_VariableController()) << "processRequest for" << var->name() << varRequestId + qCDebug(LOG_VariableController()) << "onRequestDataLoading: for" << varRequestId << varIds.size(); impl->processRequest(var, range, varRequestId); } @@ -609,6 +591,8 @@ void VariableController::onRequestDataLoading(QVector for (auto vId : vSyncIds) { varIds.push_back(vId); } + qCDebug(LOG_VariableController()) << "onRequestDataLoading sync: for" << varRequestId + << varIds.size(); impl->m_VarGroupIdToVarIds.insert(std::make_pair(varRequestId, varIds)); for (auto vId : vSyncIds) { @@ -850,8 +834,6 @@ void VariableController::VariableControllerPrivate::updateVariables(QUuid varReq auto &varIds = varGroupIdToVarIdsIt->second; auto varIdsEnd = varIds.end(); bool processVariableUpdate = true; - qCDebug(LOG_VariableController()) << "VariableControllerPrivate::updateVariables" - << varRequestId << varIds.size(); for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd) && processVariableUpdate; ++varIdsIt) { auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); @@ -861,7 +843,6 @@ void VariableController::VariableControllerPrivate::updateVariables(QUuid varReq } if (processVariableUpdate) { - qCDebug(LOG_VariableController()) << "Final update OK for the var request" << varIds.size(); for (auto varIdsIt = varIds.begin(); varIdsIt != varIdsEnd; ++varIdsIt) { auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { @@ -880,7 +861,6 @@ void VariableController::VariableControllerPrivate::updateVariables(QUuid varReq << var->nbPoints(); emit var->updated(); - qCDebug(LOG_VariableController()) << tr("Update OK"); } else { qCCritical(LOG_VariableController()) @@ -912,13 +892,22 @@ void VariableController::VariableControllerPrivate::updateVariableRequest(QUuid auto &varIds = varGroupIdToVarIdsIt->second; auto varIdsEnd = varIds.end(); + + // First pass all canUpdate of handler to false for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { auto varHandler = itVarHandler->second.get(); varHandler->m_CanUpdate = false; + } + } + // Second update requests of handler + for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { + auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); + if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { + auto varHandler = itVarHandler->second.get(); switch (varHandler->m_State) { case VariableRequestHandlerState::OFF: { @@ -961,6 +950,17 @@ void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid auto &varIds = varGroupIdToVarIdsIt->second; auto varIdsEnd = varIds.end(); + + // First pass all canUpdate of handler to false + for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { + auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); + if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { + + auto varHandler = itVarHandler->second.get(); + varHandler->m_CanUpdate = false; + } + } + for (auto varIdsIt = varIds.begin(); (varIdsIt != varIdsEnd); ++varIdsIt) { auto itVarHandler = m_VarIdToVarRequestHandler.find(*varIdsIt); if (itVarHandler != m_VarIdToVarRequestHandler.cend()) { @@ -983,7 +983,6 @@ void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid itVarHandler->first); } m_VariableModel->setDataProgress(var, 0.0); - varHandler->m_CanUpdate = false; varHandler->m_State = VariableRequestHandlerState::OFF; varHandler->m_RunningVarRequest = VariableRequest{}; } @@ -1002,7 +1001,6 @@ void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid itVarHandler->first); } m_VariableModel->setDataProgress(var, 0.0); - varHandler->m_CanUpdate = false; varHandler->m_State = VariableRequestHandlerState::RUNNING; varHandler->m_RunningVarRequest = varHandler->m_PendingVarRequest; varHandler->m_PendingVarRequest = VariableRequest{}; @@ -1034,8 +1032,6 @@ void VariableController::VariableControllerPrivate::cancelVariableRequest(QUuid void VariableController::VariableControllerPrivate::executeVarRequest(std::shared_ptr var, VariableRequest &varRequest) { - qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest"); - auto varIdIt = m_VariableToIdentifierMap.find(var); if (varIdIt == m_VariableToIdentifierMap.cend()) { qCWarning(LOG_VariableController()) << tr( @@ -1059,8 +1055,7 @@ void VariableController::VariableControllerPrivate::executeVarRequest(std::share qCDebug(LOG_VariableController()) << "executeVarRequest " << varRequest.m_RangeRequested << varRequest.m_CacheRangeRequested; m_VariableAcquisitionWorker->pushVariableRequest( - varRequest.m_VariableGroupId, varId, varRequest.m_RangeRequested, - varRequest.m_CacheRangeRequested, + varRequest.m_VariableGroupId, varId, DataProviderParameters{std::move(notInCacheRangeList), var->metadata()}, varProvider); } @@ -1074,6 +1069,8 @@ void VariableController::VariableControllerPrivate::executeVarRequest(std::share } } else { + qCDebug(LOG_VariableController()) << "All already in the cache " + << varRequest.m_RangeRequested; acceptVariableRequest(varId, var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested)); } diff --git a/gui/src/Visualization/VisualizationGraphWidget.cpp b/gui/src/Visualization/VisualizationGraphWidget.cpp index 6f5b3f9..80653ad 100644 --- a/gui/src/Visualization/VisualizationGraphWidget.cpp +++ b/gui/src/Visualization/VisualizationGraphWidget.cpp @@ -246,7 +246,7 @@ VisualizationGraphWidget::VisualizationGraphWidget(const QString &name, QWidget &VisualizationGraphWidget::onMouseDoubleClick); connect(ui->widget->xAxis, static_cast( &QCPAxis::rangeChanged), - this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); + this, &VisualizationGraphWidget::onRangeChanged, Qt::DirectConnection); // Activates menu when right clicking on the graph ui->widget->setContextMenuPolicy(Qt::CustomContextMenu); diff --git a/plugins/amda/src/AmdaProvider.cpp b/plugins/amda/src/AmdaProvider.cpp index ff7d177..3395bd5 100644 --- a/plugins/amda/src/AmdaProvider.cpp +++ b/plugins/amda/src/AmdaProvider.cpp @@ -135,12 +135,16 @@ void AmdaProvider::onReplyDownloadProgress(QUuid acqIdentifier, finalProgress = finalProgress / fraq; } - qCDebug(LOG_AmdaProvider()) << tr("Current final progress: ") << fraq << finalProgress; + qCDebug(LOG_AmdaProvider()) << tr("final progress: ") + << QThread::currentThread()->objectName() << acqIdentifier + << 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 + qCDebug(LOG_AmdaProvider()) << tr("Acquisition request not found: final progress: 100 : ") + << QThread::currentThread()->objectName() << acqIdentifier; emit dataProvidedProgress(acqIdentifier, 100.0); } } @@ -169,7 +173,6 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa 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 @@ -211,8 +214,8 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa if (reply->error() == QNetworkReply::NoError) { auto downloadFileUrl = QUrl{QString{reply->readAll()}.trimmed()}; - qCInfo(LOG_AmdaProvider()) - << tr("TORM AmdaProvider::retrieveData downloadFileUrl:") << downloadFileUrl; + qCDebug(LOG_AmdaProvider()) << tr("AmdaProvider::retrieveData downloadFileUrl:") + << downloadFileUrl; // Executes request for downloading file // // Creates destination file @@ -238,7 +241,6 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa // //////////////// // 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); @@ -247,7 +249,6 @@ void AmdaProvider::retrieveData(QUuid token, const SqpRange &dateTime, const QVa 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; diff --git a/plugins/amda/tests/FuzzingDefs.cpp b/plugins/amda/tests/FuzzingDefs.cpp index 5d2502e..f7b7524 100644 --- a/plugins/amda/tests/FuzzingDefs.cpp +++ b/plugins/amda/tests/FuzzingDefs.cpp @@ -13,6 +13,7 @@ const QString PROVIDER_PROPERTY = QStringLiteral("provider"); const QString OPERATION_DELAY_BOUNDS_PROPERTY = QStringLiteral("operationDelays"); const QString VALIDATORS_PROPERTY = QStringLiteral("validators"); const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY = QStringLiteral("validationFrequencyBounds"); +const QString CUSTOM_OPERATIONS_PROPERTY = QStringLiteral("customOperations"); // //////////// // // FuzzingState // diff --git a/plugins/amda/tests/FuzzingDefs.h b/plugins/amda/tests/FuzzingDefs.h index 6b66508..42b3656 100644 --- a/plugins/amda/tests/FuzzingDefs.h +++ b/plugins/amda/tests/FuzzingDefs.h @@ -62,6 +62,9 @@ extern const QString VALIDATORS_PROPERTY; /// Min/max number of operations to execute before calling validation of the current test's state extern const QString VALIDATION_FREQUENCY_BOUNDS_PROPERTY; +/// Custom operations to execute instead of random operations +extern const QString CUSTOM_OPERATIONS_PROPERTY; + // /////// // // Structs // // /////// // diff --git a/plugins/amda/tests/FuzzingOperations.cpp b/plugins/amda/tests/FuzzingOperations.cpp index 059c233..7526b6e 100644 --- a/plugins/amda/tests/FuzzingOperations.cpp +++ b/plugins/amda/tests/FuzzingOperations.cpp @@ -178,7 +178,7 @@ struct SynchronizeOperation : public IFuzzingOperation { fuzzingState.synchronizeVariable(variableId, syncGroupId); variableController.onRequestDataLoading({variableState.m_Variable}, variableState.m_Range, - false); + true); } }; diff --git a/plugins/amda/tests/TestAmdaFuzzing.cpp b/plugins/amda/tests/TestAmdaFuzzing.cpp index b2d299c..9dec84e 100644 --- a/plugins/amda/tests/TestAmdaFuzzing.cpp +++ b/plugins/amda/tests/TestAmdaFuzzing.cpp @@ -57,6 +57,12 @@ struct OperationProperty { using VariableOperation = std::pair >; using VariablesOperations = std::vector; +struct CustomVariableOperation { + VariableOperation m_VariableOperation{}; + bool m_WaitAcquisition{false}; +}; +using CustomVariablesOperations = std::vector; + using OperationsTypes = std::map; using OperationsPool = std::map, OperationProperty>; @@ -67,30 +73,150 @@ using Validators = std::vector >; // ///////// // // Defaults values used when the associated properties have not been set for the test -const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 30000; -const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 100; -const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 1; -const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 1; +const auto ACQUISITION_TIMEOUT_DEFAULT_VALUE = 100000; +const auto NB_MAX_OPERATIONS_DEFAULT_VALUE = 160; +const auto NB_MAX_SYNC_GROUPS_DEFAULT_VALUE = 8; +const auto NB_MAX_VARIABLES_DEFAULT_VALUE = 30; const auto AVAILABLE_OPERATIONS_DEFAULT_VALUE = QVariant::fromValue( - OperationsTypes{{FuzzingOperationType::CREATE, {1., true}}, - {FuzzingOperationType::DELETE, {0.1}}, // Delete operation is less frequent + OperationsTypes{{FuzzingOperationType::CREATE, {40000., true}}, + {FuzzingOperationType::DELETE, {0.0}}, // Delete operation is less frequent {FuzzingOperationType::PAN_LEFT, {1.}}, {FuzzingOperationType::PAN_RIGHT, {1.}}, {FuzzingOperationType::ZOOM_IN, {1.}}, {FuzzingOperationType::ZOOM_OUT, {1.}}, - {FuzzingOperationType::SYNCHRONIZE, {0.8}}, - {FuzzingOperationType::DESYNCHRONIZE, {0.4}}}); + {FuzzingOperationType::SYNCHRONIZE, {500.0}}, + {FuzzingOperationType::DESYNCHRONIZE, {0.0}}}); const auto CACHE_TOLERANCE_DEFAULT_VALUE = 0.2; /// Min/max delays between each operation (in ms) -const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(100, 3000)); +const auto OPERATION_DELAY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(20, 3000)); /// Validators for the tests (executed in the order in which they're defined) const auto VALIDATORS_DEFAULT_VALUE = QVariant::fromValue( ValidatorsTypes{{FuzzingValidatorType::RANGE, FuzzingValidatorType::DATA}}); /// Min/max number of operations to execute before calling validation -const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(1, 10)); +const auto VALIDATION_FREQUENCY_BOUNDS_DEFAULT_VALUE = QVariant::fromValue(std::make_pair(2, 10)); + + +// /////// ////// +// CUSTOM CASE // +// /////// ////// + +auto op = [](auto type){ + return FuzzingOperationFactory::create(type); +}; + + +const QVariant CUSTOM_CASE_ONE =QVariant::fromValue(CustomVariablesOperations{{{0, op(FuzzingOperationType::CREATE)}, true}, + {{0, op(FuzzingOperationType::SYNCHRONIZE)}}, + {{1, op(FuzzingOperationType::CREATE)}, true}, + {{1, op(FuzzingOperationType::SYNCHRONIZE)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_LEFT)}}, + {{0, op(FuzzingOperationType::PAN_RIGHT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + {{0, op(FuzzingOperationType::PAN_LEFT)}}, + {{1, op(FuzzingOperationType::PAN_RIGHT)}}, + }); + +const QVariant CUSTOM_CASE_TWO =QVariant::fromValue(CustomVariablesOperations{{{0, op(FuzzingOperationType::CREATE)}, true}, + {{0, op(FuzzingOperationType::SYNCHRONIZE)}}, + {{1, op(FuzzingOperationType::CREATE)}, true}, + {{1, op(FuzzingOperationType::SYNCHRONIZE)}}, + {{1, op(FuzzingOperationType::ZOOM_OUT)}}, + {{1, op(FuzzingOperationType::ZOOM_IN)}}, + }); // /////// // // Methods // @@ -193,9 +319,6 @@ public: void execute() { - qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbMaxOperations() << "operations on" - << nbMaxVariables() << "variable(s)..."; - // Inits the count of the number of operations before the next validation int nextValidationCounter = 0; @@ -207,28 +330,52 @@ public: }; updateValidationCounter(); + // Get custom operations + auto customOperations = m_Properties.value(CUSTOM_OPERATIONS_PROPERTY).value(); + auto isCustomTest = !customOperations.empty(); + + auto nbOperations = isCustomTest ? customOperations.size() : nbMaxOperations(); + + qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Running" << nbOperations << "operations on" + << nbMaxVariables() << "variable(s)..."; + auto canExecute = true; - for (auto i = 0; i < nbMaxOperations() && canExecute; ++i) { - // Retrieves all operations that can be executed in the current context - VariablesOperations variableOperations{}; - Weights weights{}; - std::tie(variableOperations, weights) - = availableOperations(m_FuzzingState, operationsPool()); - - canExecute = !variableOperations.empty(); - if (canExecute) { - --nextValidationCounter; + for (auto i = 0; i < nbOperations && canExecute; ++i) { + VariableOperation variableOperation{}; + auto forceWait = false; + + if(isCustomTest){ + auto customOperation = customOperations.front(); + variableOperation = customOperation.m_VariableOperation; + customOperations.erase(customOperations.begin()); + + canExecute = variableOperation.second->canExecute(variableOperation.first, m_FuzzingState); + forceWait = customOperation.m_WaitAcquisition; + } else { + // Retrieves all operations that can be executed in the current context + VariablesOperations variableOperations{}; + Weights weights{}; + std::tie(variableOperations, weights) + = availableOperations(m_FuzzingState, operationsPool()); // Of the operations available, chooses a random operation and executes it - auto variableOperation + variableOperation = RandomGenerator::instance().randomChoice(variableOperations, weights); + canExecute = !variableOperations.empty(); + forceWait = operationsPool().at(variableOperation.second).m_WaitAcquisition; + } + + if (canExecute) { + --nextValidationCounter; auto variableId = variableOperation.first; auto fuzzingOperation = variableOperation.second; auto waitAcquisition = nextValidationCounter == 0 - || operationsPool().at(fuzzingOperation).m_WaitAcquisition; + || forceWait; + qCInfo(LOG_TestAmdaFuzzing()).noquote() << "Operation :" << i +1 << " on" + << nbOperations; fuzzingOperation->execute(variableId, m_FuzzingState, m_VariableController, m_Properties); @@ -293,6 +440,7 @@ private: } // namespace Q_DECLARE_METATYPE(OperationsTypes) +Q_DECLARE_METATYPE(CustomVariablesOperations) class TestAmdaFuzzing : public QObject { Q_OBJECT @@ -306,7 +454,7 @@ private slots: void TestAmdaFuzzing::testFuzzing_data() { // Note: Comment this line to run fuzzing tests - QSKIP("Fuzzing tests are disabled by default"); +// QSKIP("Fuzzing tests are disabled by default"); // ////////////// // // Test structure // @@ -318,17 +466,34 @@ void TestAmdaFuzzing::testFuzzing_data() // Test cases // // ////////// // - auto maxRange = SqpRange::fromDateTime({2017, 1, 1}, {0, 0}, {2017, 1, 5}, {0, 0}); - MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "imf"}}}; + auto maxRange = SqpRange::fromDateTime({2017, 1, 5}, {8, 0}, {2017, 1, 5}, {16, 0}); + MetadataPool metadataPool{{{"dataType", "vector"}, {"xml:id", "c1_b"}}}; // Note: we don't use auto here as we want to pass std::shared_ptr as is in the // QVariant std::shared_ptr provider = std::make_shared(); + + // Case Custom one : Only lot of pan on two variables synchronized +// QTest::newRow("fuzzingTestPan") << Properties{ +// {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, +// {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, +// {PROVIDER_PROPERTY, QVariant::fromValue(provider)}, +// {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_ONE}}; + +// QTest::newRow("fuzzingTestZoom") << Properties{ +// {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, +// {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, +// {PROVIDER_PROPERTY, QVariant::fromValue(provider)}, +// {CUSTOM_OPERATIONS_PROPERTY, CUSTOM_CASE_TWO}}; + + +//// Fuzzing QTest::newRow("fuzzingTest") << Properties{ - {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, - {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, - {PROVIDER_PROPERTY, QVariant::fromValue(provider)}}; + {MAX_RANGE_PROPERTY, QVariant::fromValue(maxRange)}, + {METADATA_POOL_PROPERTY, QVariant::fromValue(metadataPool)}, + {PROVIDER_PROPERTY, QVariant::fromValue(provider)}}; + } void TestAmdaFuzzing::testFuzzing()