Commit f9eb7c3a85a0c31e53b66b8a01ae6ed3cb9263c6

Authored by Erdogan Furkan
1 parent ac860015
Exists in SpeasyGet

For now

config/xsd/parameter/getspeasyproxy.xsd
... ... @@ -7,6 +7,8 @@
7 7  
8 8 <xs:attribute name="speasyUID" type="xs:string" use="required" />
9 9 <xs:attribute name="minSampling" type="xs:string" use="required" />
  10 + <xs:attribute name="dim1" type="xs:integer" />
  11 + <xs:attribute name="dim2" type="xs:integer" />
10 12 </xs:complexType>
11 13  
12 14 <xs:complexType name="speasy-proxy-type">
... ...
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.cc
... ... @@ -17,6 +17,7 @@
17 17 #include "DataSetMgr.hh"
18 18 #include "DicError.hh"
19 19 #include "TimeUtil.hh"
  20 +#include <fstream>
20 21 #include "Helper.hh"
21 22 #define CURL_STATICLIB
22 23 #include <curl/curl.h>
... ... @@ -28,14 +29,15 @@ namespace SpeasyProxyInterface {
28 29  
29 30 ParamGetSpeasyProxy::ParamGetSpeasyProxy(Parameter &parameter) :
30 31 ParamGet_CRTP<ParamGetSpeasyProxy>(parameter),
31   - _paramId(""),_timeStamp(0)
  32 + _paramId(""),_timeStamp(0),_type(TYPE_FLOAT), _container(CONTAINER_SCALAR)
32 33 {
33 34  
34 35 }
35 36  
36 37 ParamGetSpeasyProxy::ParamGetSpeasyProxy(const ParamGetSpeasyProxy &pParamGetSpeasyProxy, Parameter &parameter) :
37 38 ParamGet_CRTP<ParamGetSpeasyProxy>(pParamGetSpeasyProxy, parameter),
38   - _paramId(pParamGetSpeasyProxy._paramId), _timeStamp(pParamGetSpeasyProxy._timeStamp)
  39 + _paramId(pParamGetSpeasyProxy._paramId), _timeStamp(pParamGetSpeasyProxy._timeStamp),
  40 + _type(pParamGetSpeasyProxy._type), _container(pParamGetSpeasyProxy._container)
39 41 {
40 42  
41 43 }
... ... @@ -55,6 +57,27 @@ double ParamGetSpeasyProxy::getMinSampling()
55 57 return 0;
56 58 }
57 59  
  60 +std::string ParamGetSpeasyProxy::readFile(const std::string& filename) {
  61 + // Create an input file stream
  62 + std::ifstream file(filename);
  63 +
  64 + // Check if the file stream was successfully opened
  65 + if (!file.is_open()) {
  66 + throw std::runtime_error("Could not open file");
  67 + }
  68 +
  69 + // Use a stringstream to read the entire file into a string
  70 + std::stringstream buffer;
  71 + buffer << file.rdbuf();
  72 +
  73 + // Close the file stream
  74 + file.close();
  75 +
  76 + // Return the contents of the file as a string
  77 + return buffer.str();
  78 +}
  79 +
  80 +
58 81 /**
59 82 * Downloads timetable file in tmp directory.
60 83 */
... ... @@ -95,8 +118,10 @@ std::string ParamGetSpeasyProxy::download(const std::string&amp; pPath) {
95 118 if (codes == CURLE_OK) {
96 119 localPath = tmpFile;
97 120 } else {
  121 +
  122 + std::string str(errBuf.begin(), errBuf.end());
98 123 LOG4CXX_ERROR(_logger,
99   - "Unable to download " + pPath + " : " + errBuf[0]);
  124 + "Unable to download " + pPath + " : " << str );// errBuf[0]);
100 125 }
101 126 } else {
102 127 LOG4CXX_ERROR(_logger,
... ... @@ -118,6 +143,15 @@ TimeStamp ParamGetSpeasyProxy::init()
118 143 {
119 144 LOG4CXX_DEBUG(gLogger, "ParamGetSpeasyProxy::init");
120 145 // Test si proxy accessible
  146 + // A Faire
  147 +
  148 +
  149 + 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";
  150 + std::string localPath = download(link);
  151 +
  152 + std::string value = readFile(localPath);
  153 +
  154 + _container = CONTAINER_VECTOR; // For now
121 155 return _timeStamp;
122 156 }
123 157  
... ... @@ -142,5 +176,12 @@ void ParamGetSpeasyProxy::updateInfo(Parameter &amp; parameter)
142 176 return;
143 177 }
144 178  
  179 +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  180 + size_t written;
  181 + written = fwrite(ptr, size, nmemb, stream);
  182 + return written;
  183 +}
  184 +
  185 +
145 186 } /* namespace SpeasyProxyInterface */
146 187 } /* namespace AMDA */
... ...
src/ParamGetImpl/SpeasyProxyInterface/ParamGetSpeasyProxy.hh
... ... @@ -13,7 +13,7 @@
13 13 #include <boost/shared_ptr.hpp>
14 14 #include "ParamGet.hh"
15 15 #include "TimeStamp.hh"
16   -// #include "Pusher.hh"
  16 +#include "Pusher.hh"
17 17  
18 18 using namespace AMDA::Parameters;
19 19  
... ... @@ -82,6 +82,8 @@ public:
82 82  
83 83 protected:
84 84  
  85 + std::string readFile(const std::string& filename);
  86 +
85 87  
86 88 std::string download(const std::string& pPath);
87 89  
... ... @@ -91,6 +93,9 @@ protected:
91 93 */
92 94 std::string _paramId;
93 95  
  96 + SpeasyProxyParamType _type;
  97 +
  98 + SpeasyProxyContainerType _container;
94 99  
95 100 /*
96 101 * @brief Time of xml file or 0
... ... @@ -100,11 +105,12 @@ protected:
100 105 /*
101 106 * @brief Data pusher
102 107 */
103   - // PusherBase *_pusher;
  108 + PusherBase *_pusher;
104 109  
105 110 };
106 111  
107 112 typedef boost::shared_ptr<ParamGetSpeasyProxy> ParamGetSpeasyProxySPtr;
  113 +size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream);
108 114  
109 115 } /* namespace SpeasyProxyInterface */
110 116 } /* namespace AMDA */
... ...
src/ParamGetImpl/SpeasyProxyInterface/Pusher.hh 0 → 100644
... ... @@ -0,0 +1,295 @@
  1 +/*
  2 + * Pusher.hh
  3 + *
  4 + * Created on: Jan 30, 2019
  5 + * Author: AKKA
  6 + */
  7 +
  8 +#ifndef PUSHER_H_
  9 +#define PUSHER_H_
  10 +
  11 +#include <vector>
  12 +#include "ParamData.hh"
  13 +
  14 +
  15 +#include "SpeasyProxyParamData.hh"
  16 +
  17 +namespace AMDA {
  18 +namespace SpeasyProxyInterface {
  19 +
  20 +// int getNbDataByPacket(ConstantParamType paramType, int dim1, int dim2);
  21 +
  22 +/**
  23 + * @class PusherBase
  24 + * @details This class is the operation responsible to transform raw data from local file into a ParamData
  25 + * of the corresponding type ( scalar or vector of short or int or float or double or ... type).
  26 + */
  27 +struct PusherBase {
  28 +public:
  29 + /*
  30 + * @brief Constructor
  31 + */
  32 + PusherBase (double sampling, double value, int dim1 = 1, int dim2 = 1) : _paramData(NULL), _sampling(sampling), _value(value), _dim1(dim1), _dim2(dim2)
  33 + {
  34 + }
  35 +
  36 + /*
  37 + * @brief Destructor
  38 + */
  39 + virtual ~PusherBase()
  40 + {
  41 + }
  42 +
  43 + /*
  44 + * @brief Get the ParamData
  45 + */
  46 + AMDA::Parameters::ParamData* getParamData(void)
  47 + {
  48 + return _paramData;
  49 + }
  50 +
  51 + /*
  52 + * @brief Virtual method to put a packet in the ParamData
  53 + */
  54 + virtual int put(double startTime, double stopTime, int lastIndex) = 0;
  55 +
  56 +protected:
  57 + /*
  58 + * @brief Pointer to the paramData
  59 + */
  60 + AMDA::Parameters::ParamData* _paramData;
  61 +
  62 + /*
  63 + * @brief Sampling value
  64 + */
  65 + double _sampling;
  66 +
  67 + /*
  68 + * @brief Constant value
  69 + */
  70 + double _value;
  71 +
  72 + /*
  73 + * @brief For Vector and Tab2D dimension
  74 + */
  75 + int _dim1;
  76 +
  77 + /*
  78 + * @brief For Tab2D dimension
  79 + */
  80 + int _dim2;
  81 +
  82 + /*
  83 + * @brief Nb data returned by one packet
  84 + */
  85 + // int _nbDataByPacket;
  86 +};
  87 +
  88 +
  89 +template <SpeasyProxyParamType type>
  90 +struct MapType { typedef void Type; };
  91 +
  92 +template <> struct MapType<SpeasyProxyParamType::TYPE_SHORT> { typedef short Type; };
  93 +template <> struct MapType<SpeasyProxyParamType::TYPE_INT> { typedef int Type; };
  94 +template <> struct MapType<SpeasyProxyParamType::TYPE_FLOAT> { typedef float Type; };
  95 +template <> struct MapType<SpeasyProxyParamType::TYPE_DOUBLE> { typedef double Type; };
  96 +
  97 +
  98 +template<SpeasyProxyParamType type, SpeasyProxyContainerType container = CONTAINER_VECTOR>
  99 +class Pusher;
  100 +
  101 +/**
  102 + * @brief Pusher implementation for the Tab2D.
  103 + */
  104 +template<SpeasyProxyParamType type>
  105 +class Pusher<type,CONTAINER_MATRIX> : public PusherBase
  106 +{
  107 +public:
  108 + /*
  109 + * @brief Define some usefull types
  110 + */
  111 + typedef typename MapType<type>::Type BaseElemenType;
  112 + typedef AMDA::Parameters::Tab2DData<BaseElemenType> ElemenType;
  113 + typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;
  114 +
  115 + SpecParamData* _specParamData;
  116 +
  117 + /*
  118 + * @brief Constructor
  119 + */
  120 + Pusher(double sampling, double value, int dim1, int dim2) : PusherBase(sampling, value, dim1, dim2)
  121 + {
  122 + _paramData = _specParamData = createParamData();
  123 + // _nbDataByPacket = getNbDataByPacket(type, dim1, dim2);
  124 + }
  125 +
  126 + /*
  127 + * @brief Put packet in a "vector" ParamData
  128 + */
  129 + virtual int put(double startTime, double stopTime, int lastIndex)
  130 + {
  131 + // _specParamData->getDataList().resize(_nbDataByPacket);
  132 +
  133 + // for (int index = 0; index < _nbDataByPacket; ++index)
  134 + // {
  135 + // //get time
  136 + // double time = startTime + (lastIndex + index) * _sampling;
  137 + // if (time > stopTime) {
  138 + // return index;
  139 + // }
  140 + // //this element will be deleted by the Container designed by "_specParamData->getDataList()"
  141 + // ElemenType elem = ElemenType(_dim1,_dim2);
  142 + // for (int dim1Index = 0; dim1Index < _dim1; ++dim1Index)
  143 + // {
  144 + // for (int dim2Index = 0; dim2Index < _dim2; ++dim2Index)
  145 + // {
  146 + // BaseElemenType baseElem = _value;
  147 + // elem[dim1Index][dim2Index] = baseElem;
  148 + // }
  149 + // }
  150 +
  151 + // //push time and element in the ParamData
  152 + // _specParamData->getDataList().push_back(elem);
  153 + // _specParamData->getTimeList().push_back(time);
  154 + // }
  155 +
  156 + // //return nb of processed records
  157 + // return _nbDataByPacket;
  158 +
  159 + return 0;
  160 + }
  161 +
  162 + /*
  163 + * @brief ParamData creation
  164 + */
  165 + SpecParamData* createParamData()
  166 + {
  167 + return new AMDA::Parameters::ParamDataSpec<AMDA::Parameters::Tab2DData<typename MapType<type>::Type> >(_dim1,_dim2);
  168 + }
  169 +};
  170 +
  171 +/**
  172 + * @brief Pusher implementation for the vector.
  173 + */
  174 +template<SpeasyProxyParamType type>
  175 +class Pusher<type,CONTAINER_VECTOR> : public PusherBase
  176 +{
  177 +public:
  178 + /*
  179 + * @brief Define some usefull types
  180 + */
  181 + typedef typename MapType<type>::Type BaseElemenType;
  182 + typedef std::vector<BaseElemenType> ElemenType;
  183 + typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;
  184 +
  185 + SpecParamData* _specParamData;
  186 +
  187 + /*
  188 + * @brief Constructor
  189 + */
  190 + Pusher(double sampling, double value, int dim) : PusherBase(sampling, value, dim)
  191 + {
  192 + _paramData = _specParamData = createParamData();
  193 + // _nbDataByPacket = getNbDataByPacket(type, dim, 1);
  194 + }
  195 +
  196 + /*
  197 + * @brief Put packet in a "vector" ParamData
  198 + */
  199 + virtual int put(double startTime, double stopTime, int lastIndex)
  200 + {
  201 + // _specParamData->getDataList().resize(_nbDataByPacket);
  202 +
  203 + // for (int index = 0; index < _nbDataByPacket; ++index)
  204 + // {
  205 + // //get time
  206 + // double time = startTime + (lastIndex + index) * _sampling;
  207 + // if (time > stopTime) {
  208 + // return index;
  209 + // };
  210 +
  211 + // ElemenType elem;
  212 + // for (int dimIndex = 0; dimIndex < _dim1; ++dimIndex)
  213 + // {
  214 + // BaseElemenType baseElem = _value;
  215 + // elem.push_back(baseElem);
  216 + // }
  217 +
  218 + // //push time and element in the ParamData
  219 + // _specParamData->getDataList().push_back(elem);
  220 + // _specParamData->getTimeList().push_back(time);
  221 + // }
  222 +
  223 + // //return nb of processed records
  224 + // return _nbDataByPacket;
  225 + return 0;
  226 + }
  227 +
  228 + /*
  229 + * @brief ParamData creation
  230 + */
  231 + SpecParamData* createParamData()
  232 + {
  233 + return new AMDA::Parameters::ParamDataSpec< std::vector<typename MapType<type>::Type> >(_dim1);
  234 + }
  235 +};
  236 +
  237 +/**
  238 + * @brief Pusher implementation for the scalar.
  239 + */
  240 +template<SpeasyProxyParamType type>
  241 +class Pusher<type,CONTAINER_SCALAR> : public PusherBase {
  242 +public:
  243 + /*
  244 + * @brief Define some usefull types
  245 + */
  246 + typedef typename MapType<type>::Type BaseElemenType;
  247 + typedef BaseElemenType ElemenType;
  248 + typedef AMDA::Parameters::ParamDataSpec<ElemenType> SpecParamData;
  249 +
  250 + SpecParamData* _specParamData;
  251 +
  252 + /*
  253 + * @brief Constructor
  254 + */
  255 + Pusher(double sampling, double value) : PusherBase(sampling, value)
  256 + {
  257 + _paramData = _specParamData = createParamData();
  258 + // _nbDataByPacket = getNbDataByPacket(type, 1, 1);
  259 + }
  260 +
  261 + /*
  262 + * @brief Put packet in a "scalar" ParamData
  263 + */
  264 + virtual int put(double startTime, double stopTime, int lastIndex)
  265 + {
  266 + // //ParamData is created, add data
  267 + // _specParamData->getDataList().resize(_nbDataByPacket);
  268 +
  269 + // for (int index = 0; index < _nbDataByPacket; ++index)
  270 + // {
  271 + // //get time
  272 + // double time = startTime + (lastIndex + index) * _sampling;
  273 + // if (time > stopTime) {
  274 + // return index;
  275 + // }
  276 +
  277 + // BaseElemenType baseElem = _value;
  278 +
  279 + // //push time and element in the ParamData
  280 + // _specParamData->getDataList().push_back(baseElem);
  281 + // _specParamData->getTimeList().push_back(time);
  282 + // }
  283 +
  284 + // return _nbDataByPacket;
  285 + return 0;
  286 + }
  287 +
  288 + SpecParamData* createParamData() {
  289 + return new SpecParamData();
  290 + }
  291 +};
  292 +
  293 +} /* namespace SpeasyProxyInterface */
  294 +} /* namespace AMDA */
  295 +#endif /* PUSHER_H_ */
... ...
src/ParamGetImpl/SpeasyProxyInterface/SpeasyProxyParamData.hh 0 → 100644
... ... @@ -0,0 +1,48 @@
  1 +/*
  2 + * SpeasyProxyParamData.hh
  3 + *
  4 + * Created on: Jan 30, 2019
  5 + * Author: AKKA
  6 + */
  7 +
  8 +
  9 +#ifndef SPEASYPROXYPARAMDATA_HH_
  10 +#define SPEASYPROXYPARAMDATA_HH_
  11 +
  12 +namespace AMDA {
  13 +namespace SpeasyProxyInterface {
  14 +
  15 +/*
  16 + * @brief Container type
  17 + */
  18 +enum SpeasyProxyContainerType
  19 +{
  20 + CONTAINER_SCALAR,
  21 + CONTAINER_VECTOR,
  22 + CONTAINER_MATRIX
  23 +};
  24 +
  25 +/*
  26 + * @brief Param type
  27 + */
  28 +enum SpeasyProxyParamType
  29 +{
  30 + TYPE_UNKNOWN,
  31 + TYPE_FLOAT,
  32 + TYPE_DOUBLE,
  33 + TYPE_EPOCH16,
  34 + TYPE_SHORT,
  35 + TYPE_INT,
  36 + TYPE_TT2000
  37 +};
  38 +
  39 +/*
  40 + * @brief Define the maximum bytes available for one packet
  41 + */
  42 +// #define PARAMPACKET_MAX_DATABYTES 80000
  43 +// #define PARAMPACKET_MIN_NBDATABYPACKET 1000
  44 +
  45 +} /* SpeasyProxyInterface */
  46 +} /* AMDA */
  47 +
  48 +#endif /* SPEASYPROXYPARAMDATA_HH_ */
... ...