Commit 65f64dfe8afaa0ea06f5d2e89a3bf6211a28ad98

Authored by Benjamin Renard
1 parent 1bacb719
Exists in amdadev and in 1 other branch SpeasyGet

Fix bugs with correlation, timeShift, mean_, min_, max_, ... processes

src/ExternLib/StatisticFunctions/AMDAPlugin.cc
... ... @@ -31,63 +31,63 @@ extern "C" const char* getPluginVersion() {
31 31 extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm) {
32 32 std::string pluginPath = pm.getCurrentPluginPath();
33 33 ProcessFactory factProcessMinFunc = boost::factory<ProcessMinFunc*>();
34   - ServicesServer::getInstance()->addProcessFactory("min", factProcessMinFunc);
  34 + ServicesServer::getInstance()->addProcessFactory("min", factProcessMinFunc, false);
35 35 ServicesServer::getInstance()->linkProcessWithPlugin("min", pluginPath);
36 36  
37 37 ProcessFactory factProcessMinSmFunc = boost::factory<ProcessMinSmFunc*>();
38   - ServicesServer::getInstance()->addProcessFactory("min_sm", factProcessMinSmFunc);
  38 + ServicesServer::getInstance()->addProcessFactory("min_sm", factProcessMinSmFunc, false);
39 39 ServicesServer::getInstance()->linkProcessWithPlugin("min_sm", pluginPath);
40 40  
41 41 ProcessFactory factProcessMaxFunc = boost::factory<ProcessMaxFunc*>();
42   - ServicesServer::getInstance()->addProcessFactory("max", factProcessMaxFunc);
  42 + ServicesServer::getInstance()->addProcessFactory("max", factProcessMaxFunc, false);
43 43 ServicesServer::getInstance()->linkProcessWithPlugin("max", pluginPath);
44 44  
45 45 ProcessFactory factProcessMaxSmFunc = boost::factory<ProcessMaxSmFunc*>();
46   - ServicesServer::getInstance()->addProcessFactory("max_sm", factProcessMaxSmFunc);
  46 + ServicesServer::getInstance()->addProcessFactory("max_sm", factProcessMaxSmFunc, false);
47 47 ServicesServer::getInstance()->linkProcessWithPlugin("max_sm", pluginPath);
48 48  
49 49 ProcessFactory factProcessVarFunc = boost::factory<ProcessVarFunc*>();
50   - ServicesServer::getInstance()->addProcessFactory("var", factProcessVarFunc);
  50 + ServicesServer::getInstance()->addProcessFactory("var", factProcessVarFunc, false);
51 51 ServicesServer::getInstance()->linkProcessWithPlugin("var", pluginPath);
52 52  
53 53 ProcessFactory factProcessVarSmFunc = boost::factory<ProcessVarSmFunc*>();
54   - ServicesServer::getInstance()->addProcessFactory("var_sm", factProcessVarSmFunc);
  54 + ServicesServer::getInstance()->addProcessFactory("var_sm", factProcessVarSmFunc, false);
55 55 ServicesServer::getInstance()->linkProcessWithPlugin("var_sm", pluginPath);
56 56  
57 57 ProcessFactory factProcessRmsFunc = boost::factory<ProcessRmsFunc*>();
58   - ServicesServer::getInstance()->addProcessFactory("rms", factProcessRmsFunc);
  58 + ServicesServer::getInstance()->addProcessFactory("rms", factProcessRmsFunc, false);
59 59 ServicesServer::getInstance()->linkProcessWithPlugin("rms", pluginPath);
60 60  
61 61 ProcessFactory factProcessRmsSmFunc = boost::factory<ProcessRmsSmFunc*>();
62   - ServicesServer::getInstance()->addProcessFactory("rms_sm", factProcessRmsSmFunc);
  62 + ServicesServer::getInstance()->addProcessFactory("rms_sm", factProcessRmsSmFunc, false);
63 63 ServicesServer::getInstance()->linkProcessWithPlugin("rms_sm", pluginPath);
64 64  
65 65 ProcessFactory factProcessSkewFunc = boost::factory<ProcessSkewFunc*>();
66   - ServicesServer::getInstance()->addProcessFactory("skew", factProcessSkewFunc);
  66 + ServicesServer::getInstance()->addProcessFactory("skew", factProcessSkewFunc, false);
67 67 ServicesServer::getInstance()->linkProcessWithPlugin("skew", pluginPath);
68 68  
69 69 ProcessFactory factProcessSkewSmFunc = boost::factory<ProcessSkewSmFunc*>();
70   - ServicesServer::getInstance()->addProcessFactory("skew_sm", factProcessSkewSmFunc);
  70 + ServicesServer::getInstance()->addProcessFactory("skew_sm", factProcessSkewSmFunc, false);
71 71 ServicesServer::getInstance()->linkProcessWithPlugin("skew_sm", pluginPath);
72 72  
73 73 ProcessFactory factProcessMedianFunc = boost::factory<ProcessMedianFunc*>();
74   - ServicesServer::getInstance()->addProcessFactory("median", factProcessMedianFunc);
  74 + ServicesServer::getInstance()->addProcessFactory("median", factProcessMedianFunc, false);
75 75 ServicesServer::getInstance()->linkProcessWithPlugin("median", pluginPath);
76 76  
77 77 ProcessFactory factCovarianceCorrelation = boost::factory<CovarianceProcess*>();
78   - ServicesServer::getInstance()->addProcessFactory("covariance", factCovarianceCorrelation);
  78 + ServicesServer::getInstance()->addProcessFactory("covariance", factCovarianceCorrelation, false);
79 79 ServicesServer::getInstance()->linkProcessWithPlugin("covariance", pluginPath);
80 80  
81 81 ProcessFactory factPearsonCorrelation = boost::factory<PearsonProcess*>();
82   - ServicesServer::getInstance()->addProcessFactory("pearson", factPearsonCorrelation);
  82 + ServicesServer::getInstance()->addProcessFactory("pearson", factPearsonCorrelation, false);
83 83 ServicesServer::getInstance()->linkProcessWithPlugin("pearson", pluginPath);
84 84  
85 85 ProcessFactory factKendallCorrelation = boost::factory<KendallProcess*>();
86   - ServicesServer::getInstance()->addProcessFactory("kendall", factKendallCorrelation);
  86 + ServicesServer::getInstance()->addProcessFactory("kendall", factKendallCorrelation, false);
87 87 ServicesServer::getInstance()->linkProcessWithPlugin("kendall", pluginPath);
88 88  
89 89 ProcessFactory factSpearmanCorrelation = boost::factory<SpearmanProcess*>();
90   - ServicesServer::getInstance()->addProcessFactory("spearman", factSpearmanCorrelation);
  90 + ServicesServer::getInstance()->addProcessFactory("spearman", factSpearmanCorrelation, false);
91 91 ServicesServer::getInstance()->linkProcessWithPlugin("spearman", pluginPath);
92 92  
93 93 }
... ...
src/ExternLib/StatisticFunctions/AbstractFunc.hh
... ... @@ -74,12 +74,12 @@ public:
74 74  
75 75 _target = time;
76 76 _minWindow = _target - _windowtime / 2.;
77   - if (_minWindow < _currentTimeInterval->_startTime) {
78   - _minWindow = _currentTimeInterval->_startTime;
  77 + if (_minWindow < _currentTimeInterval->_startTime - _windowtime / 2.) {
  78 + _minWindow = _currentTimeInterval->_startTime - _windowtime / 2.;
79 79 }
80 80 _maxWindow = _target + _windowtime / 2.;
81   - if (_maxWindow > _currentTimeInterval->_stopTime) {
82   - _maxWindow = _currentTimeInterval->_stopTime;
  81 + if (_maxWindow > _currentTimeInterval->_stopTime + _windowtime / 2.) {
  82 + _maxWindow = _currentTimeInterval->_stopTime + _windowtime / 2.;
83 83 }
84 84 return true;
85 85 }
... ... @@ -95,7 +95,7 @@ public:
95 95 }
96 96 ++_currentTimeInterval;
97 97 _needInit = true;
98   - resetFunc();
  98 + resetFunc();
99 99 }
100 100  
101 101 virtual bool nextTarget() = 0;
... ... @@ -165,12 +165,13 @@ public:
165 165 _paramOutput->pushTime(getTarget());
166 166 _paramOutput->push(compute());
167 167 pushData(crtTime, crtVal);
168   - nextTarget();
169   - bool skip = false;
170   - while (!skip && needToChangeTarget(crtTime)) {
171   - _paramOutput->pushTime(getTarget());
172   - _paramOutput->push(compute());
173   - skip = nextTarget();
  168 + if (nextTarget()) {
  169 + bool skip = false;
  170 + while (!skip && needToChangeTarget(crtTime)) {
  171 + _paramOutput->pushTime(getTarget());
  172 + _paramOutput->push(compute());
  173 + skip = nextTarget();
  174 + }
174 175 }
175 176 }
176 177 else {
... ... @@ -182,14 +183,14 @@ public:
182 183 }
183 184 }
184 185 if (pParamDataIndexInfo._timeIntToProcessChanged || pParamDataIndexInfo._noMoreTimeInt) {
185   - if (!needInit()) {
186   - do {
187   - if (inInt(getTarget())) {
188   - _paramOutput->pushTime(getTarget());
189   - _paramOutput->push(compute());
190   - }
191   - } while (nextTarget());
  186 + if (!needInit()) {
  187 + do {
  188 + if (inInt(getTarget())) {
  189 + _paramOutput->pushTime(getTarget());
  190 + _paramOutput->push(compute());
192 191 }
  192 + } while (nextTarget());
  193 + }
193 194 }
194 195 }
195 196  
... ... @@ -245,12 +246,13 @@ public:
245 246 _paramOutput->pushTime(getTarget());
246 247 _paramOutput->push(compute());
247 248 pushData(crtTime, crtVal1, crtVal2);
248   - nextTarget();
249   - bool skip = false;
250   - while (!skip && needToChangeTarget(crtTime)) {
251   - _paramOutput->pushTime(getTarget());
252   - _paramOutput->push(compute());
253   - skip = nextTarget();
  249 + if (nextTarget()) {
  250 + bool skip = false;
  251 + while (!skip && needToChangeTarget(crtTime)) {
  252 + _paramOutput->pushTime(getTarget());
  253 + _paramOutput->push(compute());
  254 + skip = nextTarget();
  255 + }
254 256 }
255 257 }
256 258 else {
... ... @@ -302,11 +304,11 @@ public:
302 304  
303 305 virtual bool nextTarget() {
304 306 double target = AbstractFunc<InputElemType,OutputElemType>::getTarget() + AbstractFunc<InputElemType,OutputElemType>::getWindowTime();
305   - bool res = AbstractFunc<InputElemType,OutputElemType>::setTarget(target);
306   - while (!_mem.empty() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(_mem.front().first)) {
307   - _mem.pop_front();
308   - }
309   - return res;
  307 + bool res = AbstractFunc<InputElemType,OutputElemType>::setTarget(target);
  308 + while (!_mem.empty() && !AbstractFunc<InputElemType,OutputElemType>::inWindow(_mem.front().first)) {
  309 + _mem.pop_front();
  310 + }
  311 + return res;
310 312 }
311 313  
312 314 virtual bool needToChangeTarget(double crtTime) {
... ...
src/ExternLib/StatisticFunctions/CorrelationProcess.cc
... ... @@ -51,7 +51,9 @@ namespace AMDA {
51 51 ParameterSPtr lParameter = creator.getOneParameterFromExpression(_parameter,_expression, isUserProcess());
52 52 _paramNameList[lParameter->getId()].first = lParameter;
53 53 _firstParamName = lParameter->getId();
  54 +
54 55 lParameter = creator.getOneParameterFromExpression(_parameter,_attributList[0], isUserProcess());
  56 + lParameter = _parameter.getParameterManager().getSampledParameterUnderRefParam(lParameter->getId(), _firstParamName, isUserProcess());
55 57 _paramNameList[lParameter->getId()].first = lParameter;
56 58 _secondParamName = lParameter->getId();
57 59 }
... ...
src/ExternLib/StatisticFunctions/ProcessStatisticFunctions.cc
... ... @@ -56,18 +56,25 @@ TimeStamp ProcessStatisticFunctions::init() {
56 56 TimeIntervalListSPtr lTimeIntervalList(new TimeIntervalList());
57 57  
58 58 // Add shift time for each time interval
  59 + std::cout << "BRE - A" << std::endl;
59 60 for (TimeIntervalList::iterator it = _timeIntervalList->begin(); it != _timeIntervalList->end(); ++it) {
60 61 if ((*it)._startTime - _windowtime/2. > 0) {
  62 + std::cout << "BRE - B" << std::endl;
61 63 lTimeIntervalList->push_back(TimeInterval( (*it)._startTime - _windowtime/2., (*it)._stopTime + _windowtime/2.));
62 64 }
63 65 else {
  66 + std::cout << "BRE - C" << std::endl;
64 67 lTimeIntervalList->push_back(TimeInterval( 0, (*it)._stopTime + _windowtime/2.));
65 68 }
66 69 }
  70 +
  71 + std::cout << "BRE - D" << std::endl;
67 72 TimeStamp time = _parameterInput->init( this, lTimeIntervalList);
68 73  
  74 + std::cout << "BRE - E" << std::endl;
69 75 _paramInput = _parameterInput->getParamData(this).get();
70 76  
  77 + std::cout << "BRE - F" << std::endl;
71 78 StatisticFunctionsCreator lCreator(*this, _timeIntervalList, *_paramInput, _type, _windowtime);
72 79 _operation = lCreator.getOperation();
73 80 _paramData = ParamDataSPtr(_operation->getParamOutput());
... ... @@ -78,6 +85,7 @@ TimeStamp ProcessStatisticFunctions::init() {
78 85 gapThreshold = 1;
79 86 }
80 87 _parameter.setGapThreshold(gapThreshold);
  88 + std::cout << "BRE - G" << std::endl;
81 89 return time;
82 90 }
83 91  
... ...
src/ExternLib/TimeShifted/AMDAPlugin.cc
... ... @@ -77,6 +77,6 @@ extern &quot;C&quot; const char* getPluginVersion()
77 77 extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm)
78 78 {
79 79 ProcessFactory factProcessTimeShifted = boost::factory<ProcessTimeShifted*>();
80   - ServicesServer::getInstance()->addProcessFactory("timeShift", factProcessTimeShifted);
81   - ServicesServer::getInstance()->linkProcessWithPlugin("timeShift", pm.getCurrentPluginPath());
  80 + ServicesServer::getInstance()->addProcessFactory("timeShift", factProcessTimeShifted, false);
  81 + ServicesServer::getInstance()->linkProcessWithPlugin("timeShift", pm.getCurrentPluginPath());
82 82 }
... ...
src/ExternLib/sum_into_table_indexes/AMDAPlugin.cc
... ... @@ -77,6 +77,6 @@ extern &quot;C&quot; const char* getPluginVersion()
77 77 extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm)
78 78 {
79 79 ProcessFactory factProcessSumIntoTableIndexes = boost::factory<ProcessSumIntoTableIndexes*>();
80   - ServicesServer::getInstance()->addProcessFactory("sum_into_table_indexes", factProcessSumIntoTableIndexes);
  80 + ServicesServer::getInstance()->addProcessFactory("sum_into_table_indexes", factProcessSumIntoTableIndexes, false);
81 81 ServicesServer::getInstance()->linkProcessWithPlugin("sum_into_table_indexes", pm.getCurrentPluginPath());
82 82 }
... ...
src/ExternLib/sum_into_table_range/AMDAPlugin.cc
... ... @@ -77,6 +77,6 @@ extern &quot;C&quot; const char* getPluginVersion()
77 77 extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm)
78 78 {
79 79 ProcessFactory factProcessSumIntoTableRange = boost::factory<ProcessSumIntoTableRange*>();
80   - ServicesServer::getInstance()->addProcessFactory("sum_into_table_range", factProcessSumIntoTableRange);
  80 + ServicesServer::getInstance()->addProcessFactory("sum_into_table_range", factProcessSumIntoTableRange, false);
81 81 ServicesServer::getInstance()->linkProcessWithPlugin("sum_into_table_range", pm.getCurrentPluginPath());
82 82 }
... ...
src/InternLib/AMDAPlugin.cc
... ... @@ -85,10 +85,10 @@ extern &quot;C&quot; void registerPlugin(AMDA::Plugins::PluginManager&amp; pm) {
85 85 ServicesServer::getInstance()->addProcessFactory("standard", factProcessStandard);
86 86 ServicesServer::getInstance()->linkProcessWithPlugin("standard", pluginPath);
87 87  
88   - ServicesServer::getInstance()->addProcessFactory("sampling_classic", factProcessSamplingClassic);
  88 + ServicesServer::getInstance()->addProcessFactory("sampling_classic", factProcessSamplingClassic, false);
89 89 ServicesServer::getInstance()->linkProcessWithPlugin("sampling_classic", pluginPath);
90 90  
91   - ServicesServer::getInstance()->addProcessFactory("sampling_under_refparam", factProcessSamplingUnderRefParam);
  91 + ServicesServer::getInstance()->addProcessFactory("sampling_under_refparam", factProcessSamplingUnderRefParam, false);
92 92 ServicesServer::getInstance()->linkProcessWithPlugin("sampling_under_refparam", pluginPath);
93 93  
94 94 ServicesServer::getInstance()->addProcessFactory("tableparamtoparameter", factParamTableProcess);
... ...
src/Parameters/ServicesServer.hh
... ... @@ -194,8 +194,15 @@ namespace AMDA {
194 194 return (lIt == _processFactory.end()) ? nullptr : lIt->second(parameter);
195 195 }
196 196  
197   - void addProcessFactory(std::string processId, ProcessFactory processFactory) {
  197 + void addProcessFactory(std::string processId, ProcessFactory processFactory, bool injectResamplingBeforeProcess = true) {
198 198 _processFactory[processId] = processFactory;
  199 + _injectResamplingBeforeProcess[processId] = injectResamplingBeforeProcess;
  200 + }
  201 +
  202 + bool getInjectResamplingBeforeProcess(std::string processId) {
  203 + auto lIt = _injectResamplingBeforeProcess.find(processId);
  204 + std::cout << "BRE - getInjectResamplingBeforeProcess - " << processId << " - " << ((lIt == _injectResamplingBeforeProcess.end()) ? true : lIt->second) << std::endl;
  205 + return (lIt == _injectResamplingBeforeProcess.end()) ? true : lIt->second;
199 206 }
200 207  
201 208 // Get methods
... ... @@ -272,6 +279,8 @@ namespace AMDA {
272 279 */
273 280 ProcessFactories _processFactory;
274 281  
  282 + std::map<std::string, bool> _injectResamplingBeforeProcess;
  283 +
275 284 /**
276 285 * Factory of ParamOutput
277 286 * for a string are a sourceParmOutput, use
... ...
src/XMLParameterConfigurator/ProcessNode.cc
... ... @@ -7,12 +7,14 @@
7 7  
8 8 #include <sstream>
9 9 #include <algorithm>
  10 +#include <regex>
10 11  
11 12 #include "ProcessNode.hh"
12 13  
13 14  
14 15 #include <boost/shared_ptr.hpp>
15 16  
  17 +
16 18 #include <Parameter.hh>
17 19 #include <Process.hh>
18 20 #include <Parameter.hh>
... ... @@ -39,25 +41,52 @@ std::string injectResamplingIntoProcess(const std::string&amp; pProcessName, const s
39 41  
40 42 unsigned int length = pExpression.size();
41 43 std::string part;
42   - for ( unsigned int i = 0; i < length; ++i) {
  44 +
  45 + bool isSpecialCase = false;
  46 + std::string pattern;
  47 + std::string proc;
  48 + std::size_t found;
  49 +
  50 + for ( unsigned int i = 0; i < length; ++i) {
  51 +
43 52 switch(pExpression[i]) {
44 53 case '#':
45   - part = pExpression.substr(i);
46   - if (part.find("#sum_into_table_range($") == 0) {
47   - int patternSize = std::string("#sum_into_table_range($").size();
48   - i += patternSize;
49   - //special case with sum_into_table_range
50   - lBuffer << "#" << pProcessName << "(#sum_into_table_range($";
51   - part = part.substr(patternSize);
52   - std::size_t pos = part.find(";");
53   - lBuffer << part.substr(0, pos);
54   - i += pos;
55   - part = part.substr(pos);
56   - pos = part.find(")");
57   - lBuffer << part.substr(0, pos);
58   - i += pos;
59   - lBuffer << ");" << pProcessParams << ")";
60   - }
  54 +
  55 + part = pExpression.substr(i);
  56 + found = part.find("(");
  57 + if (found != std::string::npos) {
  58 + // Test if special case
  59 + proc = part.substr(1, found-1);
  60 + isSpecialCase = !ServicesServer::getInstance()->getInjectResamplingBeforeProcess(proc);
  61 + pattern = "#";
  62 + pattern += proc;
  63 + pattern += "(";
  64 + }
  65 + if (isSpecialCase) {
  66 + int patternSize = pattern.size();
  67 + i += patternSize;
  68 + //special case with sum_into_table_range
  69 + lBuffer << "#" << pProcessName << "(" << pattern;
  70 + part = part.substr(patternSize);
  71 +
  72 + int openBracket = 0;
  73 + int pos = 0;
  74 + for (unsigned int j = 0; j < part.size(); ++j) {
  75 + if (part[j] == '(') {
  76 + openBracket++;
  77 + }
  78 + else if (part[j] == ')') {
  79 + if (openBracket == 0) {
  80 + pos = j;
  81 + break;
  82 + }
  83 + openBracket--;
  84 + }
  85 + }
  86 + lBuffer << part.substr(0, pos);
  87 + i += pos;
  88 + lBuffer << ");" << pProcessParams << ")";
  89 + }
61 90 else {
62 91 lBuffer << pExpression[i];
63 92 }
... ...