@@ -1,167 +1,167 | |||
|
1 | 1 | ## amda - CMakeLists.txt |
|
2 | 2 | STRING(TOLOWER ${CMAKE_PROJECT_NAME} LIBRARY_PREFFIX) |
|
3 | 3 | SET(SQPAMDA_LIBRARY_NAME "${LIBRARY_PREFFIX}_amda${DEBUG_SUFFIX}") |
|
4 | 4 | SET(SOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
5 | 5 | SET(INCLUDES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include") |
|
6 | 6 | SET(RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/resources") |
|
7 | 7 | SET(TESTS_RESOURCES_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests-resources") |
|
8 | 8 | |
|
9 | 9 | # Include amda directory |
|
10 | 10 | INCLUDE_DIRECTORIES(${INCLUDES_DIR}) |
|
11 | 11 | INCLUDE_DIRECTORIES(${RESOURCES_DIR}) |
|
12 | 12 | |
|
13 | 13 | # |
|
14 | 14 | # Find Qt modules |
|
15 | 15 | # |
|
16 | SCIQLOP_FIND_QT(Core Widgets) | |
|
16 | SCIQLOP_FIND_QT(Core Widgets Network) | |
|
17 | 17 | |
|
18 | 18 | # |
|
19 | 19 | # Find dependent libraries |
|
20 | 20 | # ======================== |
|
21 | 21 | |
|
22 | 22 | # sciqlop plugin |
|
23 | 23 | find_package(sciqlop-plugin) |
|
24 | 24 | INCLUDE_DIRECTORIES(${SCIQLOP-PLUGIN_INCLUDE_DIR}) |
|
25 | 25 | |
|
26 | 26 | # sciqlop core |
|
27 | 27 | find_package(sciqlop-core) |
|
28 | 28 | INCLUDE_DIRECTORIES(${SCIQLOP-CORE_INCLUDE_DIR}) |
|
29 | 29 | list(APPEND LIBRARIES ${SCIQLOP-CORE_LIBRARIES}) |
|
30 | 30 | |
|
31 | 31 | # sciqlop gui |
|
32 | 32 | find_package(sciqlop-gui) |
|
33 | 33 | INCLUDE_DIRECTORIES(${SCIQLOP-GUI_INCLUDE_DIR}) |
|
34 | 34 | list(APPEND LIBRARIES ${SCIQLOP-GUI_LIBRARIES}) |
|
35 | 35 | |
|
36 | 36 | # Description file |
|
37 | 37 | FILE (GLOB_RECURSE PLUGIN_FILE ${RESOURCES_DIR}/amda.json) |
|
38 | 38 | |
|
39 | 39 | # Resources files |
|
40 | 40 | FILE (GLOB_RECURSE PROJECT_RESOURCES ${RESOURCES_DIR}/*.qrc) |
|
41 | 41 | |
|
42 | 42 | # |
|
43 | 43 | # Compile the library |
|
44 | 44 | # |
|
45 | 45 | |
|
46 | 46 | ADD_DEFINITIONS(-DAMDA_LIB) |
|
47 | 47 | |
|
48 | 48 | FILE (GLOB_RECURSE MODULE_SOURCES |
|
49 | 49 | ${INCLUDES_DIR}/*.h |
|
50 | 50 | ${SOURCES_DIR}/*.c |
|
51 | 51 | ${SOURCES_DIR}/*.cpp |
|
52 | 52 | ${SOURCES_DIR}/*.h |
|
53 | 53 | ${PLUGIN_FILE}) |
|
54 | 54 | |
|
55 | 55 | QT5_ADD_RESOURCES(RCC_AMDA |
|
56 | 56 | ${PROJECT_RESOURCES} |
|
57 | 57 | ) |
|
58 | 58 | |
|
59 | 59 | ADD_LIBRARY(${SQPAMDA_LIBRARY_NAME} ${MODULE_SOURCES} ${RCC_AMDA}) |
|
60 | 60 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD 14) |
|
61 | 61 | set_property(TARGET ${SQPAMDA_LIBRARY_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
62 | 62 | |
|
63 | 63 | INSTALL(TARGETS ${SQPAMDA_LIBRARY_NAME} |
|
64 | 64 | RUNTIME DESTINATION ${INSTALL_BINARY_DIR} |
|
65 | 65 | LIBRARY DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
66 | 66 | ARCHIVE DESTINATION ${INSTALL_PLUGINS_LIBRARY_DIR} |
|
67 | 67 | ) |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | TARGET_LINK_LIBRARIES(${SQPAMDA_LIBRARY_NAME} ${LIBRARIES}) |
|
71 | qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets) | |
|
71 | qt5_use_modules(${SQPAMDA_LIBRARY_NAME} Core Widgets Network) | |
|
72 | 72 | |
|
73 | 73 | add_dependencies(${SQPAMDA_LIBRARY_NAME} ${SQPPLUGIN_LIBRARY_NAME} ${SQPGUI_LIBRARY_NAME} ${SQPCORE_LIBRARY_NAME}) |
|
74 | 74 | |
|
75 | 75 | # From cmake documentation: http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html |
|
76 | 76 | # Entries in the COMPILE_DEFINITIONS are prefixed with -D or /D and added to the compile line in an unspecified order. |
|
77 | 77 | # The DEFINE_SYMBOL target property is also added as a compile definition as a special convenience case for SHARED and MODULE library targets |
|
78 | 78 | IF(BUILD_SHARED_LIBS) |
|
79 | 79 | SET_TARGET_PROPERTIES(${SQPAMDA_LIBRARY_NAME} PROPERTIES COMPILE_DEFINITIONS "SCIQLOP_EXPORT") |
|
80 | 80 | ELSE() |
|
81 | 81 | TARGET_COMPILE_DEFINITIONS(${SQPAMDA_LIBRARY_NAME} PUBLIC "SCIQLOP_STATIC_LIBRARIES") |
|
82 | 82 | ENDIF() |
|
83 | 83 | |
|
84 | 84 | # Set the variable to parent scope so that the other projects can copy the |
|
85 | 85 | # dependent shared libraries |
|
86 | 86 | SCIQLOP_SET_TO_PARENT_SCOPE(SQPAMDA_LIBRARY_NAME) |
|
87 | 87 | |
|
88 | 88 | # Copy extern shared libraries to the lib folder |
|
89 | 89 | SCIQLOP_COPY_TO_TARGET(LIBRARY ${SQPAMDA_LIBRARY_NAME} ${EXTERN_SHARED_LIBRARIES}) |
|
90 | 90 | |
|
91 | 91 | # Add the files to the list of files to be analyzed |
|
92 | 92 | LIST(APPEND CHECKSTYLE_INPUT_FILES ${MODULE_SOURCES}) |
|
93 | 93 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_INPUT_FILES) |
|
94 | 94 | # Vera++ exclusion files |
|
95 | 95 | #LIST(APPEND CHECKSTYLE_EXCLUSION_FILES ${CMAKE_CURRENT_SOURCE_DIR}/vera-exclusions/exclusions.txt) |
|
96 | 96 | SCIQLOP_SET_TO_PARENT_SCOPE(CHECKSTYLE_EXCLUSION_FILES) |
|
97 | 97 | |
|
98 | 98 | # |
|
99 | 99 | # Compile the tests |
|
100 | 100 | # |
|
101 | 101 | IF(BUILD_TESTS) |
|
102 | 102 | INCLUDE_DIRECTORIES(${SOURCES_DIR}) |
|
103 | 103 | FILE (GLOB_RECURSE TESTS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/Test*.cpp) |
|
104 | 104 | FILE (GLOB_RECURSE TESTS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/Test*.h) |
|
105 | 105 | SET( TEST_LIBRARIES ${SQPAMDA_LIBRARY_NAME}) |
|
106 | 106 | |
|
107 | 107 | FOREACH( testFile ${TESTS_SOURCES} ) |
|
108 | 108 | GET_FILENAME_COMPONENT( testDirectory ${testFile} DIRECTORY ) |
|
109 | 109 | GET_FILENAME_COMPONENT( testName ${testFile} NAME_WE ) |
|
110 | 110 | |
|
111 | 111 | # Add to the list of sources files all the sources in the same |
|
112 | 112 | # directory that aren't another test |
|
113 | 113 | FILE (GLOB currentTestSources |
|
114 | 114 | ${testDirectory}/*.c |
|
115 | 115 | ${testDirectory}/*.cpp |
|
116 | 116 | ${testDirectory}/*.h) |
|
117 | 117 | LIST (REMOVE_ITEM currentTestSources ${TESTS_SOURCES}) |
|
118 | 118 | # LIST (REMOVE_ITEM currentTestSources ${TESTS_HEADERS}) |
|
119 | 119 | |
|
120 | 120 | ADD_EXECUTABLE(${testName} ${testFile} ${currentTestSources}) |
|
121 | 121 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD 14) |
|
122 | 122 | set_property(TARGET ${testName} PROPERTY CXX_STANDARD_REQUIRED ON) |
|
123 | 123 | TARGET_LINK_LIBRARIES( ${testName} ${TEST_LIBRARIES} ) |
|
124 | 124 | qt5_use_modules(${testName} Test) |
|
125 | 125 | |
|
126 | 126 | ADD_TEST( NAME ${testName} COMMAND ${testName} ) |
|
127 | 127 | |
|
128 | 128 | SCIQLOP_COPY_TO_TARGET(RUNTIME ${testName} ${EXTERN_SHARED_LIBRARIES}) |
|
129 | 129 | ENDFOREACH( testFile ) |
|
130 | 130 | |
|
131 | 131 | LIST(APPEND testFilesToFormat ${TESTS_SOURCES}) |
|
132 | 132 | LIST(APPEND testFilesToFormat ${TESTS_HEADERS}) |
|
133 | 133 | LIST(APPEND FORMATTING_INPUT_FILES ${testFilesToFormat}) |
|
134 | 134 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
135 | 135 | |
|
136 | 136 | ADD_DEFINITIONS(-DAMDA_TESTS_RESOURCES_DIR="${TESTS_RESOURCES_DIR}") |
|
137 | 137 | ENDIF(BUILD_TESTS) |
|
138 | 138 | |
|
139 | 139 | # |
|
140 | 140 | # Set the files that must be formatted by clang-format. |
|
141 | 141 | # |
|
142 | 142 | LIST (APPEND FORMATTING_INPUT_FILES ${MODULE_SOURCES}) |
|
143 | 143 | SCIQLOP_SET_TO_PARENT_SCOPE(FORMATTING_INPUT_FILES) |
|
144 | 144 | |
|
145 | 145 | # |
|
146 | 146 | # Set the directories that doxygen must browse to generate the |
|
147 | 147 | # documentation. |
|
148 | 148 | # |
|
149 | 149 | # Source directories: |
|
150 | 150 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/docs") |
|
151 | 151 | LIST (APPEND DOXYGEN_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
152 | 152 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_INPUT_DIRS) |
|
153 | 153 | # Source directories to exclude from the documentation generation |
|
154 | 154 | #LIST (APPEND DOXYGEN_EXCLUDE_PATTERNS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir/*") |
|
155 | 155 | SCIQLOP_SET_TO_PARENT_SCOPE(DOXYGEN_EXCLUDE_PATTERNS) |
|
156 | 156 | |
|
157 | 157 | # |
|
158 | 158 | # Set the directories with the sources to analyze and propagate the |
|
159 | 159 | # modification to the parent scope |
|
160 | 160 | # |
|
161 | 161 | # Source directories to analyze: |
|
162 | 162 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src") |
|
163 | 163 | LIST (APPEND ANALYSIS_INPUT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/tests") |
|
164 | 164 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_INPUT_DIRS) |
|
165 | 165 | # Source directories to exclude from the analysis |
|
166 | 166 | #LIST (APPEND ANALYSIS_EXCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/path/to/subdir") |
|
167 | 167 | SCIQLOP_SET_TO_PARENT_SCOPE(ANALYSIS_EXCLUDE_DIRS) |
@@ -1,31 +1,34 | |||
|
1 | 1 | #ifndef SCIQLOP_AMDAPROVIDER_H |
|
2 | 2 | #define SCIQLOP_AMDAPROVIDER_H |
|
3 | 3 | |
|
4 | 4 | #include "AmdaGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Common/spimpl.h> |
|
7 | 7 | |
|
8 | 8 | #include <Data/IDataProvider.h> |
|
9 | 9 | |
|
10 | 10 | #include <QLoggingCategory> |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaProvider) |
|
14 | 14 | |
|
15 | 15 | /** |
|
16 | 16 | * @brief The AmdaProvider class is an example of how a data provider can generate data |
|
17 | 17 | */ |
|
18 | 18 | class SCIQLOP_AMDA_EXPORT AmdaProvider : public IDataProvider { |
|
19 | 19 | public: |
|
20 | 20 | explicit AmdaProvider(); |
|
21 | 21 | |
|
22 | 22 | void requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) override; |
|
23 | 23 | |
|
24 | 24 | private: |
|
25 | 25 | void retrieveData(QUuid token, const DataProviderParameters ¶meters) const; |
|
26 | 26 | |
|
27 | 27 | class AmdaProviderPrivate; |
|
28 | 28 | spimpl::unique_impl_ptr<AmdaProviderPrivate> impl; |
|
29 | ||
|
30 | private slots: | |
|
31 | void httpFinished() noexcept; | |
|
29 | 32 | }; |
|
30 | 33 | |
|
31 | 34 | #endif // SCIQLOP_AMDAPROVIDER_H |
@@ -1,23 +1,78 | |||
|
1 | 1 | #include "AmdaProvider.h" |
|
2 | #include <Data/DataProviderParameters.h> | |
|
3 | ||
|
4 | #include <QNetworkAccessManager> | |
|
5 | #include <QNetworkReply> | |
|
2 | 6 | |
|
3 | 7 | Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider") |
|
4 | 8 | |
|
9 | namespace { | |
|
10 | ||
|
11 | /// URL format for a request on AMDA server. The parameters are as follows: | |
|
12 | /// - %1: start date | |
|
13 | /// - %2: end date | |
|
14 | /// - %3: parameter id | |
|
15 | const auto AMDA_URL_FORMAT = QStringLiteral( | |
|
16 | "http://amda.irap.omp.eu/php/rest/" | |
|
17 | "getParameter.php?startTime=%1&stopTime=%2¶meterID=%3&sampling=60&outputFormat=ASCII&" | |
|
18 | "timeFormat=ISO8601&gzip=0"); | |
|
19 | ||
|
20 | /// Dates format passed in the URL (e.g 2013-09-23T09:00) | |
|
21 | const auto AMDA_TIME_FORMAT = QStringLiteral("yyyy-MM-ddThh:ss"); | |
|
22 | ||
|
23 | /// Formats a time to a date that can be passed in URL | |
|
24 | QString dateFormat(double sqpDateTime) noexcept | |
|
25 | { | |
|
26 | auto dateTime = QDateTime::fromMSecsSinceEpoch(sqpDateTime * 1000.); | |
|
27 | return dateTime.toString(AMDA_TIME_FORMAT); | |
|
28 | } | |
|
29 | ||
|
30 | } // namespace | |
|
31 | ||
|
5 | 32 | struct AmdaProvider::AmdaProviderPrivate { |
|
33 | DataProviderParameters m_Params{}; | |
|
34 | std::unique_ptr<QNetworkAccessManager> m_AccessManager{nullptr}; | |
|
35 | QNetworkReply *m_Reply{nullptr}; | |
|
36 | std::unique_ptr<QTemporaryFile> m_File{nullptr}; | |
|
37 | QUuid m_Token; | |
|
6 | 38 | }; |
|
7 | 39 | |
|
8 | 40 | AmdaProvider::AmdaProvider() : impl{spimpl::make_unique_impl<AmdaProviderPrivate>()} |
|
9 | 41 | { |
|
10 | 42 | } |
|
11 | 43 | |
|
12 | 44 | void AmdaProvider::requestDataLoading(QUuid token, const QVector<SqpDateTime> &dateTimeList) |
|
13 | 45 | { |
|
14 | 46 | // NOTE: Try to use multithread if possible |
|
15 | 47 | for (const auto &dateTime : dateTimeList) { |
|
16 | 48 | retrieveData(token, DataProviderParameters{dateTime}); |
|
17 | 49 | } |
|
18 | 50 | } |
|
19 | 51 | |
|
20 | 52 | void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters ¶meters) const |
|
21 | 53 | { |
|
54 | // /////////// // | |
|
55 | // Creates URL // | |
|
56 | // /////////// // | |
|
57 | ||
|
58 | auto startDate = dateFormat(parameters.m_Time.m_TStart); | |
|
59 | auto endDate = dateFormat(parameters.m_Time.m_TEnd); | |
|
60 | auto productId = QStringLiteral("imf(0)"); | |
|
61 | ||
|
62 | auto url = QUrl{QString{AMDA_URL_FORMAT}.arg(startDate, endDate, productId)}; | |
|
63 | ||
|
64 | // //////////////// // | |
|
65 | // Executes request // | |
|
66 | // //////////////// // | |
|
67 | ||
|
68 | impl->m_Token = token; | |
|
69 | impl->m_Params = parameters; | |
|
70 | impl->m_AccessManager = std::make_unique<QNetworkAccessManager>(); | |
|
71 | impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{url}); | |
|
72 | connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpFinished); | |
|
73 | } | |
|
74 | ||
|
75 | void AmdaProvider::httpFinished() noexcept | |
|
76 | { | |
|
22 | 77 | /// @todo ALX |
|
23 | 78 | } |
General Comments 0
You need to be logged in to leave comments.
Login now