diff --git a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc index 7fdf479..21cfb0a 100644 --- a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc +++ b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc @@ -21,9 +21,12 @@ #include "TimeUtil.hh" #include #include "Helper.hh" + +#include #define CURL_STATICLIB #include #include +#include namespace AMDA { @@ -233,27 +236,69 @@ TimeStamp ParamGetSpeasyProxy::init() return _timeStamp; } +std::string ParamGetSpeasyProxy::getURLTime(double time){ + + std::string newTime = TimeUtil::DD2ISO_TimeDate(TimeUtil::double2DD_TimeDate(time)); + std::string delim = ":"; + std::string toReplaceWith = "%3A"; + size_t pos = 0; + + while ((pos = newTime.find(delim, pos)) != std::string::npos) { + newTime.replace(pos, delim.length(), toReplaceWith); + pos += toReplaceWith.length(); + } + + // delim = ".000"; + // newTime.erase(newTime.find(delim),newTime.find(delim) + delim.length()); + + return newTime; +} + +std::string ParamGetSpeasyProxy::getSpeasyProxyLink(){ + // 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 + + std::string path = "http://172.200.0.14:6543/get_data?path="; + std::string delim = "/"; + std::string toReplaceWith = "%2F"; + std::string paramId = _paramId; + size_t pos = 0; + + while ((pos = paramId.find(delim, pos)) != std::string::npos) { + paramId.replace(pos, delim.length(), toReplaceWith); + pos += toReplaceWith.length(); + } + path += paramId + "&start_time=" + getURLTime(_currentInterval->_startTime); + path += "&stop_time=" + getURLTime(_currentInterval->_stopTime); + path += "&format=cdf&zstd_compression=false&output_format=CDF_ISTP&pickle_proto=3"; + + return path; +} unsigned int ParamGetSpeasyProxy::write() { unsigned int result = 0; - - //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"; - std::string localPath = "/home/amda_admin/AMDA/AMDA_Kernel/cdf_speasy.cdf"; + + // Getting parameter ids + std::string timeParamId = "time"; + std::string croptedParamId = _paramId; + std::string delim = "/"; + croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); + + // Creation of the data packet + SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket(); + packet->init(_container,_type,_dim1,_dim2); + + // Downloading and loading FileReader + std::string localPath = download(getSpeasyProxyLink()); FileReaderCDF* fileReaderPtr = new FileReaderCDF(); bool isOpen = fileReaderPtr->open(localPath); + + + if(isOpen) { - std::string timeParamId = "time"; - std::string croptedParamId = _paramId; - std::string delim = "/"; - croptedParamId.erase(0, croptedParamId.find(delim) + delim.length()); - // Call to getParamPacketData to get CDF data - SpeasyProxyParamDataPacket *packet= new SpeasyProxyParamDataPacket(); - packet->init(_container,_type,_dim1,_dim2); - fileReaderPtr->getParamPacketData(timeParamId, croptedParamId, packet); @@ -278,7 +323,8 @@ unsigned int ParamGetSpeasyProxy::write() else { // Nothing to do. } - + if (result != 0) + remove(localPath.c_str()); return result; } diff --git a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh index 9c527ae..26a26ff 100644 --- a/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh +++ b/src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh @@ -150,6 +150,12 @@ public: */ TimeStamp init(); + + std::string getURLTime(double time); + std::string getSpeasyProxyLink(); + + + /** * @overload DataWriter::updateInfo update parameter info in relation to the ParamGet */ -- libgit2 0.21.2