Commit f2b9334fb60d202356a5c9f600da9655b9024440

Authored by Erdogan Furkan
1 parent ae3e8cdf
Exists in SpeasyGet

Working from request - TBC

src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc
@@ -21,9 +21,12 @@ @@ -21,9 +21,12 @@
21 #include "TimeUtil.hh" 21 #include "TimeUtil.hh"
22 #include <fstream> 22 #include <fstream>
23 #include "Helper.hh" 23 #include "Helper.hh"
  24 +
  25 +#include <iostream>
24 #define CURL_STATICLIB 26 #define CURL_STATICLIB
25 #include <curl/curl.h> 27 #include <curl/curl.h>
26 #include <curl/easy.h> 28 #include <curl/easy.h>
  29 +#include <cstdio>
27 30
28 namespace AMDA { 31 namespace AMDA {
29 32
@@ -233,27 +236,69 @@ TimeStamp ParamGetSpeasyProxy::init() @@ -233,27 +236,69 @@ TimeStamp ParamGetSpeasyProxy::init()
233 return _timeStamp; 236 return _timeStamp;
234 } 237 }
235 238
  239 +std::string ParamGetSpeasyProxy::getURLTime(double time){
  240 +
  241 + std::string newTime = TimeUtil::DD2ISO_TimeDate(TimeUtil::double2DD_TimeDate(time));
  242 + std::string delim = ":";
  243 + std::string toReplaceWith = "%3A";
  244 + size_t pos = 0;
  245 +
  246 + while ((pos = newTime.find(delim, pos)) != std::string::npos) {
  247 + newTime.replace(pos, delim.length(), toReplaceWith);
  248 + pos += toReplaceWith.length();
  249 + }
  250 +
  251 + // delim = ".000";
  252 + // newTime.erase(newTime.find(delim),newTime.find(delim) + delim.length());
  253 +
  254 + return newTime;
  255 +}
  256 +
  257 +std::string ParamGetSpeasyProxy::getSpeasyProxyLink(){
  258 + // http://172.200.0.14:6543/get_data?path=amda%2Fc1_b_gsm&start_time=2018-10-24T00%3A00%3A00&stop_time=2018-10-24T02%3A00%3A00&format=cdf&zstd_compression=false&output_format=CDF_ISTP&pickle_proto=3
  259 +
  260 + std::string path = "http://172.200.0.14:6543/get_data?path=";
  261 + std::string delim = "/";
  262 + std::string toReplaceWith = "%2F";
  263 + std::string paramId = _paramId;
  264 + size_t pos = 0;
  265 +
  266 + while ((pos = paramId.find(delim, pos)) != std::string::npos) {
  267 + paramId.replace(pos, delim.length(), toReplaceWith);
  268 + pos += toReplaceWith.length();
  269 + }
  270 + path += paramId + "&start_time=" + getURLTime(_currentInterval->_startTime);
  271 + path += "&stop_time=" + getURLTime(_currentInterval->_stopTime);
  272 + path += "&format=cdf&zstd_compression=false&output_format=CDF_ISTP&pickle_proto=3";
  273 +
  274 + return path;
  275 +}
236 276
237 unsigned int ParamGetSpeasyProxy::write() 277 unsigned int ParamGetSpeasyProxy::write()
238 { 278 {
239 unsigned int result = 0; 279 unsigned int result = 0;
240 -  
241 - //std::string link = "http://172.200.0.14:6543/get_data?path=amda%2Fimf&start_time=2008-01-01T00%3A00%3A00&stop_time=2008-01-02T00%3A00%3A00&format=json&zstd_compression=false&pickle_proto=3";  
242 - std::string localPath = "/home/amda_admin/AMDA/AMDA_Kernel/cdf_speasy.cdf"; 280 +
  281 + // Getting parameter ids
  282 + std::string timeParamId = "time";
  283 + std::string croptedParamId = _paramId;
  284 + std::string delim = "/";
  285 + croptedParamId.erase(0, croptedParamId.find(delim) + delim.length());
  286 +
  287 + // Creation of the data packet
  288 + SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket();
  289 + packet->init(_container,_type,_dim1,_dim2);
  290 +
  291 + // Downloading and loading FileReader
  292 + std::string localPath = download(getSpeasyProxyLink());
243 FileReaderCDF* fileReaderPtr = new FileReaderCDF(); 293 FileReaderCDF* fileReaderPtr = new FileReaderCDF();
244 bool isOpen = fileReaderPtr->open(localPath); 294 bool isOpen = fileReaderPtr->open(localPath);
  295 +
  296 +
  297 +
245 if(isOpen) 298 if(isOpen)
246 { 299 {
247 - std::string timeParamId = "time";  
248 - std::string croptedParamId = _paramId;  
249 - std::string delim = "/";  
250 - croptedParamId.erase(0, croptedParamId.find(delim) + delim.length());  
251 -  
252 // Call to getParamPacketData to get CDF data 300 // Call to getParamPacketData to get CDF data
253 301
254 - SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket();  
255 - packet->init(_container,_type,_dim1,_dim2);  
256 -  
257 fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, packet); 302 fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, packet);
258 303
259 304
@@ -278,7 +323,8 @@ unsigned int ParamGetSpeasyProxy::write() @@ -278,7 +323,8 @@ unsigned int ParamGetSpeasyProxy::write()
278 else { 323 else {
279 // Nothing to do. 324 // Nothing to do.
280 } 325 }
281 - 326 + if (result != 0)
  327 + remove(localPath.c_str());
282 return result; 328 return result;
283 } 329 }
284 330
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh
@@ -150,6 +150,12 @@ public: @@ -150,6 +150,12 @@ public:
150 */ 150 */
151 TimeStamp init(); 151 TimeStamp init();
152 152
  153 +
  154 + std::string getURLTime(double time);
  155 + std::string getSpeasyProxyLink();
  156 +
  157 +
  158 +
153 /** 159 /**
154 * @overload DataWriter::updateInfo update parameter info in relation to the ParamGet 160 * @overload DataWriter::updateInfo update parameter info in relation to the ParamGet
155 */ 161 */