##// END OF EJS Templates
Merge branch 'feature/AmdaProviderImprovements' into develop
Alexandre Leroux -
r418:0ec770a1fa8f merge
parent child
Show More
@@ -0,0 +1,16
1 #ifndef SCIQLOP_AMDADEFS_H
2 #define SCIQLOP_AMDADEFS_H
3
4 #include <QString>
5
6 // ////////////// //
7 // AMDA constants //
8 // ////////////// //
9
10 // Relevant keys in JSON file
11 extern const QString AMDA_COMPONENT_KEY;
12 extern const QString AMDA_PRODUCT_KEY;
13 extern const QString AMDA_ROOT_KEY;
14 extern const QString AMDA_XML_ID_KEY;
15
16 #endif // SCIQLOP_AMDADEFS_H
@@ -0,0 +1,6
1 #include "AmdaDefs.h"
2
3 const QString AMDA_COMPONENT_KEY = QStringLiteral("component");
4 const QString AMDA_PRODUCT_KEY = QStringLiteral("parameter");
5 const QString AMDA_ROOT_KEY = QStringLiteral("dataCenter");
6 const QString AMDA_XML_ID_KEY = QStringLiteral("xml:id");
@@ -9,7 +9,10
9 * @sa IDataProvider
9 * @sa IDataProvider
10 */
10 */
11 struct DataProviderParameters {
11 struct DataProviderParameters {
12 SqpDateTime m_Time;
12 /// Times for which retrieve data
13 QVector<SqpDateTime> m_Times;
14 /// Extra data that can be used by the provider to retrieve data
15 QVariantHash m_Data;
13 };
16 };
14
17
15 #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H
18 #endif // SCIQLOP_DATAPROVIDERPARAMETERS_H
@@ -30,10 +30,9 public:
30 virtual ~IDataProvider() noexcept = default;
30 virtual ~IDataProvider() noexcept = default;
31
31
32 /**
32 /**
33 * @brief requestDataLoading provide datas for the data identified by identifier for all
33 * @brief requestDataLoading provide datas for the data identified by identifier and parameters
34 * SqpDateTime of dateTimeList
35 */
34 */
36 virtual void requestDataLoading(QUuid identifier, const QVector<SqpDateTime> &dateTimeList) = 0;
35 virtual void requestDataLoading(QUuid identifier, const DataProviderParameters &parameters) = 0;
37
36
38 signals:
37 signals:
39 /**
38 /**
@@ -74,10 +74,12 signals:
74 /**
74 /**
75 * Signal emitted when a variable creation is asked for a product
75 * Signal emitted when a variable creation is asked for a product
76 * @param variableName the name of the variable
76 * @param variableName the name of the variable
77 * @param variableMetadata the metadata of the variable
77 * @param variableProvider the provider that will be used to retrieve the data of the variable
78 * @param variableProvider the provider that will be used to retrieve the data of the variable
78 * (can be null)
79 * (can be null)
79 */
80 */
80 void variableCreationRequested(const QString &variableName,
81 void variableCreationRequested(const QString &variableName,
82 const QVariantHash &variableMetadata,
81 std::shared_ptr<IDataProvider> variableProvider);
83 std::shared_ptr<IDataProvider> variableProvider);
82
84
83 private:
85 private:
@@ -25,7 +25,7 public:
25 static const QString NAME_DATA_KEY;
25 static const QString NAME_DATA_KEY;
26
26
27 explicit DataSourceItem(DataSourceItemType type, const QString &name);
27 explicit DataSourceItem(DataSourceItemType type, const QString &name);
28 explicit DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data = {});
28 explicit DataSourceItem(DataSourceItemType type, QVariantHash data = {});
29
29
30 /// @return the actions of the item as a vector
30 /// @return the actions of the item as a vector
31 QVector<DataSourceItemAction *> actions() const noexcept;
31 QVector<DataSourceItemAction *> actions() const noexcept;
@@ -60,7 +60,7 public:
60 QVariant data(const QString &key) const noexcept;
60 QVariant data(const QString &key) const noexcept;
61
61
62 /// Gets all data
62 /// Gets all data
63 const QHash<QString, QVariant> &data() const noexcept;
63 QVariantHash data() const noexcept;
64
64
65 bool isRoot() const noexcept;
65 bool isRoot() const noexcept;
66
66
@@ -22,18 +22,18 class Variable : public QObject {
22 Q_OBJECT
22 Q_OBJECT
23
23
24 public:
24 public:
25 explicit Variable(const QString &name, const QString &unit, const QString &mission,
25 explicit Variable(const QString &name, const SqpDateTime &dateTime,
26 const SqpDateTime &dateTime);
26 const QVariantHash &metadata = {});
27
27
28 QString name() const noexcept;
28 QString name() const noexcept;
29 QString mission() const noexcept;
30 QString unit() const noexcept;
31 SqpDateTime dateTime() const noexcept;
29 SqpDateTime dateTime() const noexcept;
32 void setDateTime(const SqpDateTime &dateTime) noexcept;
30 void setDateTime(const SqpDateTime &dateTime) noexcept;
33
31
34 /// @return the data of the variable, nullptr if there is no data
32 /// @return the data of the variable, nullptr if there is no data
35 IDataSeries *dataSeries() const noexcept;
33 IDataSeries *dataSeries() const noexcept;
36
34
35 QVariantHash metadata() const noexcept;
36
37 bool contains(const SqpDateTime &dateTime) const noexcept;
37 bool contains(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
38 bool intersect(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
39 bool isInside(const SqpDateTime &dateTime) const noexcept;
@@ -60,9 +60,11 public slots:
60 /**
60 /**
61 * Creates a new variable and adds it to the model
61 * Creates a new variable and adds it to the model
62 * @param name the name of the new variable
62 * @param name the name of the new variable
63 * @param metadata the metadata of the new variable
63 * @param provider the data provider for the new variable
64 * @param provider the data provider for the new variable
64 */
65 */
65 void createVariable(const QString &name, std::shared_ptr<IDataProvider> provider) noexcept;
66 void createVariable(const QString &name, const QVariantHash &metadata,
67 std::shared_ptr<IDataProvider> provider) noexcept;
66
68
67 /// Update the temporal parameters of every selected variable to dateTime
69 /// Update the temporal parameters of every selected variable to dateTime
68 void onDateTimeOnSelection(const SqpDateTime &dateTime);
70 void onDateTimeOnSelection(const SqpDateTime &dateTime);
@@ -29,10 +29,11 public:
29 * Creates a new variable in the model
29 * Creates a new variable in the model
30 * @param name the name of the new variable
30 * @param name the name of the new variable
31 * @param dateTime the dateTime of the new variable
31 * @param dateTime the dateTime of the new variable
32 * @param metadata the metadata associated to the new variable
32 * @return the pointer to the new variable
33 * @return the pointer to the new variable
33 */
34 */
34 std::shared_ptr<Variable> createVariable(const QString &name,
35 std::shared_ptr<Variable> createVariable(const QString &name, const SqpDateTime &dateTime,
35 const SqpDateTime &dateTime) noexcept;
36 const QVariantHash &metadata) noexcept;
36
37
37 /**
38 /**
38 * Deletes a variable from the model, if it exists
39 * Deletes a variable from the model, if it exists
@@ -88,13 +88,13 void DataSourceController::setDataProvider(const QUuid &dataSourceUid,
88 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
88 void DataSourceController::loadProductItem(const QUuid &dataSourceUid,
89 const DataSourceItem &productItem) noexcept
89 const DataSourceItem &productItem) noexcept
90 {
90 {
91 if (productItem.type() == DataSourceItemType::PRODUCT) {
91 if (productItem.type() == DataSourceItemType::PRODUCT
92 || productItem.type() == DataSourceItemType::COMPONENT) {
92 /// Retrieves the data provider of the data source (if any)
93 /// Retrieves the data provider of the data source (if any)
93 auto it = impl->m_DataProviders.find(dataSourceUid);
94 auto it = impl->m_DataProviders.find(dataSourceUid);
94 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
95 auto dataProvider = (it != impl->m_DataProviders.end()) ? it->second : nullptr;
95
96
96 /// @todo retrieve timerange, and pass it to the signal
97 emit variableCreationRequested(productItem.name(), productItem.data(), dataProvider);
97 emit variableCreationRequested(productItem.name(), dataProvider);
98 }
98 }
99 else {
99 else {
100 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
100 qCWarning(LOG_DataSourceController()) << tr("Can't load an item that is not a product");
@@ -6,7 +6,7
6 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
6 const QString DataSourceItem::NAME_DATA_KEY = QStringLiteral("name");
7
7
8 struct DataSourceItem::DataSourceItemPrivate {
8 struct DataSourceItem::DataSourceItemPrivate {
9 explicit DataSourceItemPrivate(DataSourceItemType type, QHash<QString, QVariant> data)
9 explicit DataSourceItemPrivate(DataSourceItemType type, QVariantHash data)
10 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
10 : m_Parent{nullptr}, m_Children{}, m_Type{type}, m_Data{std::move(data)}, m_Actions{}
11 {
11 {
12 }
12 }
@@ -14,16 +14,16 struct DataSourceItem::DataSourceItemPrivate {
14 DataSourceItem *m_Parent;
14 DataSourceItem *m_Parent;
15 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
15 std::vector<std::unique_ptr<DataSourceItem> > m_Children;
16 DataSourceItemType m_Type;
16 DataSourceItemType m_Type;
17 QHash<QString, QVariant> m_Data;
17 QVariantHash m_Data;
18 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
18 std::vector<std::unique_ptr<DataSourceItemAction> > m_Actions;
19 };
19 };
20
20
21 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
21 DataSourceItem::DataSourceItem(DataSourceItemType type, const QString &name)
22 : DataSourceItem{type, QHash<QString, QVariant>{{NAME_DATA_KEY, name}}}
22 : DataSourceItem{type, QVariantHash{{NAME_DATA_KEY, name}}}
23 {
23 {
24 }
24 }
25
25
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QHash<QString, QVariant> data)
26 DataSourceItem::DataSourceItem(DataSourceItemType type, QVariantHash data)
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
27 : impl{spimpl::make_unique_impl<DataSourceItemPrivate>(type, std::move(data))}
28 {
28 {
29 }
29 }
@@ -70,7 +70,7 QVariant DataSourceItem::data(const QString &key) const noexcept
70 return impl->m_Data.value(key);
70 return impl->m_Data.value(key);
71 }
71 }
72
72
73 const QHash<QString, QVariant> &DataSourceItem::data() const noexcept
73 QVariantHash DataSourceItem::data() const noexcept
74 {
74 {
75 return impl->m_Data;
75 return impl->m_Data;
76 }
76 }
@@ -9,27 +9,21
9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
9 Q_LOGGING_CATEGORY(LOG_Variable, "Variable")
10
10
11 struct Variable::VariablePrivate {
11 struct Variable::VariablePrivate {
12 explicit VariablePrivate(const QString &name, const QString &unit, const QString &mission,
12 explicit VariablePrivate(const QString &name, const SqpDateTime &dateTime,
13 const SqpDateTime &dateTime)
13 const QVariantHash &metadata)
14 : m_Name{name},
14 : m_Name{name}, m_DateTime{dateTime}, m_Metadata{metadata}, m_DataSeries{nullptr}
15 m_Unit{unit},
16 m_Mission{mission},
17 m_DateTime{dateTime},
18 m_DataSeries{nullptr}
19 {
15 {
20 }
16 }
21
17
22 QString m_Name;
18 QString m_Name;
23 QString m_Unit;
24 QString m_Mission;
25
19
26 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
20 SqpDateTime m_DateTime; // The dateTime available in the view and loaded. not the cache.
21 QVariantHash m_Metadata;
27 std::unique_ptr<IDataSeries> m_DataSeries;
22 std::unique_ptr<IDataSeries> m_DataSeries;
28 };
23 };
29
24
30 Variable::Variable(const QString &name, const QString &unit, const QString &mission,
25 Variable::Variable(const QString &name, const SqpDateTime &dateTime, const QVariantHash &metadata)
31 const SqpDateTime &dateTime)
26 : impl{spimpl::make_unique_impl<VariablePrivate>(name, dateTime, metadata)}
32 : impl{spimpl::make_unique_impl<VariablePrivate>(name, unit, mission, dateTime)}
33 {
27 {
34 }
28 }
35
29
@@ -38,16 +32,6 QString Variable::name() const noexcept
38 return impl->m_Name;
32 return impl->m_Name;
39 }
33 }
40
34
41 QString Variable::mission() const noexcept
42 {
43 return impl->m_Mission;
44 }
45
46 QString Variable::unit() const noexcept
47 {
48 return impl->m_Unit;
49 }
50
51 SqpDateTime Variable::dateTime() const noexcept
35 SqpDateTime Variable::dateTime() const noexcept
52 {
36 {
53 return impl->m_DateTime;
37 return impl->m_DateTime;
@@ -85,6 +69,11 IDataSeries *Variable::dataSeries() const noexcept
85 return impl->m_DataSeries.get();
69 return impl->m_DataSeries.get();
86 }
70 }
87
71
72 QVariantHash Variable::metadata() const noexcept
73 {
74 return impl->m_Metadata;
75 }
76
88 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
77 bool Variable::contains(const SqpDateTime &dateTime) const noexcept
89 {
78 {
90 return impl->m_DateTime.contains(dateTime);
79 return impl->m_DateTime.contains(dateTime);
@@ -102,7 +102,7 void VariableController::deleteVariables(
102 }
102 }
103 }
103 }
104
104
105 void VariableController::createVariable(const QString &name,
105 void VariableController::createVariable(const QString &name, const QVariantHash &metadata,
106 std::shared_ptr<IDataProvider> provider) noexcept
106 std::shared_ptr<IDataProvider> provider) noexcept
107 {
107 {
108
108
@@ -112,14 +112,9 void VariableController::createVariable(const QString &name,
112 return;
112 return;
113 }
113 }
114
114
115
116 /// @todo : for the moment :
117 /// - the provider is only used to retrieve data from the variable for its initialization, but
118 /// it will be retained later
119 /// - default data are generated for the variable, without taking into account the timerange set
120 /// in sciqlop
121 auto dateTime = impl->m_TimeController->dateTime();
115 auto dateTime = impl->m_TimeController->dateTime();
122 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime)) {
116
117 if (auto newVariable = impl->m_VariableModel->createVariable(name, dateTime, metadata)) {
123 auto identifier = QUuid::createUuid();
118 auto identifier = QUuid::createUuid();
124
119
125 // store the provider
120 // store the provider
@@ -186,7 +181,8 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
186 // Ask the provider for each data on the dateTimeListNotInCache
181 // Ask the provider for each data on the dateTimeListNotInCache
187 auto identifier = impl->m_VariableToIdentifier.at(variable);
182 auto identifier = impl->m_VariableToIdentifier.at(variable);
188 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
183 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
189 identifier, std::move(dateTimeListNotInCache));
184 identifier,
185 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
190 }
186 }
191 else {
187 else {
192 emit variable->updated();
188 emit variable->updated();
@@ -60,14 +60,13 VariableModel::VariableModel(QObject *parent)
60 }
60 }
61
61
62 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
62 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
63 const SqpDateTime &dateTime) noexcept
63 const SqpDateTime &dateTime,
64 const QVariantHash &metadata) noexcept
64 {
65 {
65 auto insertIndex = rowCount();
66 auto insertIndex = rowCount();
66 beginInsertRows({}, insertIndex, insertIndex);
67 beginInsertRows({}, insertIndex, insertIndex);
67
68
68 /// @todo For the moment, the other data of the variable is initialized with default values
69 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
69 auto variable = std::make_shared<Variable>(name, QStringLiteral("unit"),
70 QStringLiteral("mission"), dateTime);
71
70
72 impl->m_Variables.push_back(variable);
71 impl->m_Variables.push_back(variable);
73 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
72 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
@@ -35,7 +35,7 void TestVariableCacheController::testProvideNotInCacheDateTimeList()
35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
35 auto sqp2 = SqpDateTime{static_cast<double>(ts2.toMSecsSinceEpoch()),
36 static_cast<double>(te2.toMSecsSinceEpoch())};
36 static_cast<double>(te2.toMSecsSinceEpoch())};
37
37
38 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
38 auto var0 = std::make_shared<Variable>("", sqp0);
39
39
40 variableCacheController.addDateTime(var0, sqp0);
40 variableCacheController.addDateTime(var0, sqp0);
41 variableCacheController.addDateTime(var0, sqp1);
41 variableCacheController.addDateTime(var0, sqp1);
@@ -289,7 +289,7 void TestVariableCacheController::testAddDateTime()
289 static_cast<double>(te03.toMSecsSinceEpoch())};
289 static_cast<double>(te03.toMSecsSinceEpoch())};
290
290
291
291
292 auto var0 = std::make_shared<Variable>("", "", "", sqp0);
292 auto var0 = std::make_shared<Variable>("", sqp0);
293
293
294
294
295 // First case: add the first interval to the variable :sqp0
295 // First case: add the first interval to the variable :sqp0
@@ -25,11 +25,12 public:
25 void addAction(const QString &actionName, ActionFun actionFunction);
25 void addAction(const QString &actionName, ActionFun actionFunction);
26
26
27 /**
27 /**
28 * Adds a new menu to the current menu
28 * Adds a new menu to the current menu and returns it
29 * @param name the name of the menu
29 * @param name the name of the menu
30 * @param icon the icon of the menu (can be null)
30 * @param icon the icon of the menu (can be null)
31 * @returns the created menu, nullptr if it couldn't be created
31 */
32 */
32 void addMenu(const QString &name, const QIcon &icon = {});
33 QMenu *addMenu(const QString &name, const QIcon &icon = {});
33
34
34 /// Adds a separator to the current menu. The separator is added only if the menu already
35 /// Adds a separator to the current menu. The separator is added only if the menu already
35 /// contains entries
36 /// contains entries
@@ -26,9 +26,11 public:
26
26
27 // VariableController <-> DataSourceController
27 // VariableController <-> DataSourceController
28 connect(m_DataSourceController.get(),
28 connect(m_DataSourceController.get(),
29 SIGNAL(variableCreationRequested(const QString &, std::shared_ptr<IDataProvider>)),
29 SIGNAL(variableCreationRequested(const QString &, const QVariantHash &,
30 std::shared_ptr<IDataProvider>)),
30 m_VariableController.get(),
31 m_VariableController.get(),
31 SLOT(createVariable(const QString &, std::shared_ptr<IDataProvider>)));
32 SLOT(createVariable(const QString &, const QVariantHash &,
33 std::shared_ptr<IDataProvider>)));
32
34
33 // VariableController <-> VisualizationController
35 // VariableController <-> VisualizationController
34 connect(m_VariableController.get(),
36 connect(m_VariableController.get(),
@@ -21,7 +21,11 struct GenerateVariableMenuOperation::GenerateVariableMenuOperationPrivate {
21 void visitRootEnter()
21 void visitRootEnter()
22 {
22 {
23 // Creates the root menu
23 // Creates the root menu
24 m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"});
24 if (auto plotMenu
25 = m_PlotMenuBuilder.addMenu(QObject::tr("Plot"), QIcon{":/icones/plot.png"})) {
26 plotMenu->setEnabled(m_Variable && m_Variable->dataSeries() != nullptr);
27 }
28
25 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
29 m_UnplotMenuBuilder.addMenu(QObject::tr("Unplot"), QIcon{":/icones/unplot.png"});
26 }
30 }
27
31
@@ -12,13 +12,16 MenuBuilder::MenuBuilder(QMenu *menu)
12 }
12 }
13 }
13 }
14
14
15 void MenuBuilder::addMenu(const QString &name, const QIcon &icon)
15 QMenu *MenuBuilder::addMenu(const QString &name, const QIcon &icon)
16 {
16 {
17 if (auto currMenu = currentMenu()) {
17 if (auto currMenu = currentMenu()) {
18 m_Menus.push(currMenu->addMenu(icon, name));
18 auto menu = currMenu->addMenu(icon, name);
19 m_Menus.push(menu);
20 return menu;
19 }
21 }
20 else {
22 else {
21 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the new menu");
23 qCCritical(LOG_MenuBuilder()) << QObject::tr("No current menu to attach the new menu");
24 return nullptr;
22 }
25 }
23 }
26 }
24
27
@@ -3,8 +3,6
3
3
4 #include "AmdaGlobal.h"
4 #include "AmdaGlobal.h"
5
5
6 #include <Common/spimpl.h>
7
8 #include <Data/IDataProvider.h>
6 #include <Data/IDataProvider.h>
9
7
10 #include <QLoggingCategory>
8 #include <QLoggingCategory>
@@ -21,18 +19,10 class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider {
21 public:
19 public:
22 explicit AmdaProvider();
20 explicit AmdaProvider();
23
21
24 void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override;
22 void requestDataLoading(QUuid token, const DataProviderParameters &parameters) override;
25
23
26 private:
24 private:
27 void retrieveData(QUuid token, const DataProviderParameters &parameters);
25 void retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data);
28
29 class AmdaProviderPrivate;
30 spimpl::unique_impl_ptr<AmdaProviderPrivate> impl;
31
32 // private slots:
33 // void httpFinished(QNetworkReply *reply, QUuid dataId) noexcept;
34 // void httpDownloadFinished(QNetworkReply *reply, QUuid dataId) noexcept;
35 // void httpDownloadReadyRead(QNetworkReply *reply, QUuid dataId) noexcept;
36 };
26 };
37
27
38 #endif // SCIQLOP_AMDAPROVIDER_H
28 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -1,4 +1,5
1 #include "AmdaParser.h"
1 #include "AmdaParser.h"
2 #include "AmdaDefs.h"
2
3
3 #include <DataSource/DataSourceItem.h>
4 #include <DataSource/DataSourceItem.h>
4
5
@@ -11,18 +12,13 Q_LOGGING_CATEGORY(LOG_AmdaParser, "AmdaParser")
11
12
12 namespace {
13 namespace {
13
14
14 // Significant keys of an AMDA's JSON file
15 const auto COMPONENT_KEY = QStringLiteral("component");
16 const auto PRODUCT_KEY = QStringLiteral("parameter");
17 const auto ROOT_KEY = QStringLiteral("dataCenter");
18
19 /// Returns the correct item type according to the key passed in parameter
15 /// Returns the correct item type according to the key passed in parameter
20 DataSourceItemType itemType(const QString &key) noexcept
16 DataSourceItemType itemType(const QString &key) noexcept
21 {
17 {
22 if (key == PRODUCT_KEY) {
18 if (key == AMDA_PRODUCT_KEY) {
23 return DataSourceItemType::PRODUCT;
19 return DataSourceItemType::PRODUCT;
24 }
20 }
25 else if (key == COMPONENT_KEY) {
21 else if (key == AMDA_COMPONENT_KEY) {
26 return DataSourceItemType::COMPONENT;
22 return DataSourceItemType::COMPONENT;
27 }
23 }
28 else {
24 else {
@@ -98,16 +94,16 std::unique_ptr<DataSourceItem> AmdaParser::readJson(const QString &filePath) no
98 }
94 }
99
95
100 auto jsonDocumentObject = jsonDocument.object();
96 auto jsonDocumentObject = jsonDocument.object();
101 if (!jsonDocumentObject.contains(ROOT_KEY)) {
97 if (!jsonDocumentObject.contains(AMDA_ROOT_KEY)) {
102 qCCritical(LOG_AmdaParser())
98 qCCritical(LOG_AmdaParser())
103 << QObject::tr(
99 << QObject::tr(
104 "Can't retrieve data source tree from file %1: the file is malformed (the key "
100 "Can't retrieve data source tree from file %1: the file is malformed (the key "
105 "for the root element was not found (%2))")
101 "for the root element was not found (%2))")
106 .arg(filePath, ROOT_KEY);
102 .arg(filePath, AMDA_ROOT_KEY);
107 return nullptr;
103 return nullptr;
108 }
104 }
109
105
110 auto rootValue = jsonDocumentObject.value(ROOT_KEY);
106 auto rootValue = jsonDocumentObject.value(AMDA_ROOT_KEY);
111 if (!rootValue.isObject()) {
107 if (!rootValue.isObject()) {
112 qCCritical(LOG_AmdaParser())
108 qCCritical(LOG_AmdaParser())
113 << QObject::tr(
109 << QObject::tr(
@@ -1,4 +1,5
1 #include "AmdaPlugin.h"
1 #include "AmdaPlugin.h"
2 #include "AmdaDefs.h"
2 #include "AmdaParser.h"
3 #include "AmdaParser.h"
3 #include "AmdaProvider.h"
4 #include "AmdaProvider.h"
4
5
@@ -20,16 +21,30 const auto JSON_FILE_PATH = QStringLiteral(":/samples/AmdaSample.json");
20
21
21 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
22 void associateActions(DataSourceItem &item, const QUuid &dataSourceUid)
22 {
23 {
23 if (item.type() == DataSourceItemType::PRODUCT) {
24 auto addLoadAction = [&item, dataSourceUid](const QString &label) {
24 auto itemName = item.name();
25 item.addAction(
25
26 std::make_unique<DataSourceItemAction>(label, [dataSourceUid](DataSourceItem &item) {
26 item.addAction(std::make_unique<DataSourceItemAction>(
27 QObject::tr("Load %1 product").arg(itemName),
28 [itemName, dataSourceUid](DataSourceItem &item) {
29 if (auto app = sqpApp) {
27 if (auto app = sqpApp) {
30 app->dataSourceController().loadProductItem(dataSourceUid, item);
28 app->dataSourceController().loadProductItem(dataSourceUid, item);
31 }
29 }
32 }));
30 }));
31 };
32
33 const auto itemType = item.type();
34 if (itemType == DataSourceItemType::PRODUCT) {
35 /// @todo : As for the moment we do not manage the loading of vectors, in the case of a
36 /// parameter, we update the identifier of download of the data:
37 /// - if the parameter has no component, the identifier remains the same
38 /// - if the parameter has at least one component, the identifier is that of the first
39 /// component (for example, "imf" becomes "imf (0)")
40 if (item.childCount() != 0) {
41 item.setData(AMDA_XML_ID_KEY, item.child(0)->data(AMDA_XML_ID_KEY));
42 }
43
44 addLoadAction(QObject::tr("Load %1 product").arg(item.name()));
45 }
46 else if (itemType == DataSourceItemType::COMPONENT) {
47 addLoadAction(QObject::tr("Load %1 component").arg(item.name()));
33 }
48 }
34
49
35 auto count = item.childCount();
50 auto count = item.childCount();
@@ -1,4 +1,5
1 #include "AmdaProvider.h"
1 #include "AmdaProvider.h"
2 #include "AmdaDefs.h"
2 #include "AmdaResultParser.h"
3 #include "AmdaResultParser.h"
3
4
4 #include <Data/DataProviderParameters.h>
5 #include <Data/DataProviderParameters.h>
@@ -34,74 +35,77 QString dateFormat(double sqpDateTime) noexcept
34 return dateTime.toString(AMDA_TIME_FORMAT);
35 return dateTime.toString(AMDA_TIME_FORMAT);
35 }
36 }
36
37
37
38 } // namespace
38 } // namespace
39
39
40 struct AmdaProvider::AmdaProviderPrivate {
40 AmdaProvider::AmdaProvider()
41 DataProviderParameters m_Params{};
42 std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr};
43 QNetworkReply *m_Reply{nullptr};
44 // std::unique_ptr<QTemporaryFile> m_File{nullptr};
45 QUuid m_Token;
46 };
47
48 AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()}
49 {
41 {
50 qCDebug(LOG_NetworkController()) << tr("AmdaProvider::AmdaProvider")
42 qCDebug(LOG_NetworkController()) << tr("AmdaProvider::AmdaProvider")
51 << QThread::currentThread();
43 << QThread::currentThread();
52 if (auto app = sqpApp) {
44 if (auto app = sqpApp) {
53 auto &networkController = app->networkController();
45 auto &networkController = app->networkController();
54 connect(this, &AmdaProvider::requestConstructed, &networkController,
46 connect(this, SIGNAL(requestConstructed(QNetworkRequest, QUuid,
55 &NetworkController::onProcessRequested);
47 std::function<void(QNetworkReply *, QUuid)>)),
48 &networkController,
49 SLOT(onProcessRequested(QNetworkRequest, QUuid,
50 std::function<void(QNetworkReply *, QUuid)>)));
56 }
51 }
57 }
52 }
58
53
59 void AmdaProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList)
54 void AmdaProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
60 {
55 {
61 // NOTE: Try to use multithread if possible
56 // NOTE: Try to use multithread if possible
62 for (const auto &dateTime : dateTimeList) {
57 const auto times = parameters.m_Times;
63 retrieveData(token, DataProviderParameters{dateTime});
58 const auto data = parameters.m_Data;
59 for (const auto &dateTime : qAsConst(times)) {
60 retrieveData(token, dateTime, data);
64 }
61 }
65 }
62 }
66
63
67 void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters &parameters)
64 void AmdaProvider::retrieveData(QUuid token, const SqpDateTime &dateTime, const QVariantHash &data)
68 {
65 {
66 // Retrieves product ID from data: if the value is invalid, no request is made
67 auto productId = data.value(AMDA_XML_ID_KEY).toString();
68 if (productId.isNull()) {
69 qCCritical(LOG_AmdaProvider()) << tr("Can't retrieve data: unknown product id");
70 return;
71 }
72
69 // /////////// //
73 // /////////// //
70 // Creates URL //
74 // Creates URL //
71 // /////////// //
75 // /////////// //
72
76
73 auto startDate = dateFormat(parameters.m_Time.m_TStart);
77 auto startDate = dateFormat(dateTime.m_TStart);
74 auto endDate = dateFormat(parameters.m_Time.m_TEnd);
78 auto endDate = dateFormat(dateTime.m_TEnd);
75 auto productId = QStringLiteral("imf(0)");
76
79
77 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
80 auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)};
78
81
79 auto tempFile = std::make_shared<QTemporaryFile>();
82 auto tempFile = std::make_shared<QTemporaryFile>();
80
83
81
82 // LAMBDA
84 // LAMBDA
83 auto httpDownloadFinished = [this, tempFile](QNetworkReply *reply, QUuid dataId) noexcept {
85 auto httpDownloadFinished
84
86 = [this, dateTime, tempFile, token](QNetworkReply *reply, QUuid dataId) noexcept {
85 if (tempFile) {
87 Q_UNUSED(dataId);
86 auto replyReadAll = reply->readAll();
88
87 if (!replyReadAll.isEmpty()) {
89 if (tempFile) {
88 tempFile->write(replyReadAll);
90 auto replyReadAll = reply->readAll();
89 }
91 if (!replyReadAll.isEmpty()) {
90 tempFile->close();
92 tempFile->write(replyReadAll);
91
93 }
92 // Parse results file
94 tempFile->close();
93 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
95
94 emit dataProvided(impl->m_Token, dataSeries, impl->m_Params.m_Time);
96 // Parse results file
95 }
97 if (auto dataSeries = AmdaResultParser::readTxt(tempFile->fileName())) {
96 else {
98 emit dataProvided(token, dataSeries, dateTime);
97 /// @todo ALX : debug
99 }
98 }
100 else {
99 }
101 /// @todo ALX : debug
100
102 }
101 // Deletes reply
103 }
102 reply->deleteLater();
104
103 reply = nullptr;
105 // Deletes reply
104 };
106 reply->deleteLater();
107 reply = nullptr;
108 };
105 auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply,
109 auto httpFinishedLambda = [this, httpDownloadFinished, tempFile](QNetworkReply *reply,
106 QUuid dataId) noexcept {
110 QUuid dataId) noexcept {
107
111
@@ -121,8 +125,5 void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters &param
121 // //////////////// //
125 // //////////////// //
122 // Executes request //
126 // Executes request //
123 // //////////////// //
127 // //////////////// //
124
125 impl->m_Token = token;
126 impl->m_Params = parameters;
127 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
128 emit requestConstructed(QNetworkRequest{url}, token, httpFinishedLambda);
128 }
129 }
@@ -14,13 +14,12 Q_DECLARE_LOGGING_CATEGORY(LOG_CosinusProvider)
14 */
14 */
15 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
15 class SCIQLOP_MOCKPLUGIN_EXPORT CosinusProvider : public IDataProvider {
16 public:
16 public:
17 void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override;
17 void requestDataLoading(QUuid token, const DataProviderParameters &parameters) override;
18
18
19
19
20 private:
20 private:
21 /// @sa IDataProvider::retrieveData()
21 /// @sa IDataProvider::retrieveData()
22 std::shared_ptr<IDataSeries> retrieveData(const DataProviderParameters &parameters) const;
22 std::shared_ptr<IDataSeries> retrieveData(const SqpDateTime &dateTime) const;
23 std::shared_ptr<IDataSeries> retrieveDataSeries(const SqpDateTime &dateTime);
24 };
23 };
25
24
26 #endif // SCIQLOP_COSINUSPROVIDER_H
25 #endif // SCIQLOP_COSINUSPROVIDER_H
@@ -10,11 +10,8
10
10
11 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
11 Q_LOGGING_CATEGORY(LOG_CosinusProvider, "CosinusProvider")
12
12
13 std::shared_ptr<IDataSeries>
13 std::shared_ptr<IDataSeries> CosinusProvider::retrieveData(const SqpDateTime &dateTime) const
14 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
15 {
14 {
16 auto dateTime = parameters.m_Time;
17
18 auto dataIndex = 0;
15 auto dataIndex = 0;
19
16
20 // Gets the timerange from the parameters
17 // Gets the timerange from the parameters
@@ -38,13 +35,14 CosinusProvider::retrieveData(const DataProviderParameters &parameters) const
38 return scalarSeries;
35 return scalarSeries;
39 }
36 }
40
37
41 void CosinusProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList)
38 void CosinusProvider::requestDataLoading(QUuid token, const DataProviderParameters &parameters)
42 {
39 {
43 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
40 qCDebug(LOG_CosinusProvider()) << "CosinusProvider::requestDataLoading"
44 << QThread::currentThread()->objectName();
41 << QThread::currentThread()->objectName();
45 // NOTE: Try to use multithread if possible
42 // NOTE: Try to use multithread if possible
46 for (const auto &dateTime : dateTimeList) {
43 const auto times = parameters.m_Times;
47 auto scalarSeries = this->retrieveData(DataProviderParameters{dateTime});
44 for (const auto &dateTime : qAsConst(times)) {
45 auto scalarSeries = this->retrieveData(dateTime);
48 emit dataProvided(token, scalarSeries, dateTime);
46 emit dataProvided(token, scalarSeries, dateTime);
49 }
47 }
50 }
48 }
General Comments 0
You need to be logged in to leave comments. Login now