Commit 2ed0b75297a332e722e1fc553d472fa7c0b9cbdb
1 parent
fdea19dd
Exists in
master
and in
70 other branches
first last ok
Showing
3 changed files
with
191 additions
and
14 deletions
Show diff stats
src/ExternLib/StatisticProcesses/AMDAPlugin.cc
... | ... | @@ -127,4 +127,17 @@ extern "C" void registerPlugin(AMDA::Plugins::PluginManager & pm) { |
127 | 127 | StatisticProcessFactory factBoolProcess = boost::factory<AMDA::Statistic::CountBool::CountBoolStatisticProcess*>(); |
128 | 128 | ServicesServer::getInstance()->addStatisticProcessFactory("countTrue", factBoolProcess); |
129 | 129 | ServicesServer::getInstance()->linkStatisticProcessWithPlugin("countTrue", pluginPath); |
130 | + | |
131 | + StatisticProcessFactory factFirstProcess = boost::factory<AMDA::Statistic::MinMaxMean::FirstValueStatisticProcess*>(); | |
132 | + ServicesServer::getInstance()->addStatisticProcessFactory("firstValue", factFirstProcess); | |
133 | + ServicesServer::getInstance()->linkStatisticProcessWithPlugin("firstValue", pluginPath); | |
134 | + | |
135 | + StatisticProcessFactory factMiddleProcess = boost::factory<AMDA::Statistic::MinMaxMean::MiddleValueStatisticProcess*>(); | |
136 | + ServicesServer::getInstance()->addStatisticProcessFactory("middeleIntervalValue", factMiddleProcess); | |
137 | + ServicesServer::getInstance()->linkStatisticProcessWithPlugin("middeleIntervalValue", pluginPath); | |
138 | + | |
139 | + StatisticProcessFactory factLastProcess = boost::factory<AMDA::Statistic::MinMaxMean::LastValueStatisticProcess*>(); | |
140 | + ServicesServer::getInstance()->addStatisticProcessFactory("lastValue", factLastProcess); | |
141 | + ServicesServer::getInstance()->linkStatisticProcessWithPlugin("lastValue", pluginPath); | |
142 | + | |
130 | 143 | } | ... | ... |
src/ExternLib/StatisticProcesses/MinMaxMeanStatistic.hh
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | #include "StatisticOperation.hh" |
16 | 16 | #include "StatisticProcess.hh" |
17 | 17 | #include <math.h> |
18 | +#include <type_traits> | |
18 | 19 | |
19 | 20 | #include "TimeInterval.hh" |
20 | 21 | |
... | ... | @@ -46,6 +47,9 @@ namespace AMDA { |
46 | 47 | */ |
47 | 48 | typedef typename TParamData::ElementType ElementType; |
48 | 49 | |
50 | + | |
51 | + using TimeDataList = std::vector<std::pair<double, ElementType>>; | |
52 | + | |
49 | 53 | MinMaxMeanStatisticOperation(StatisticProcess& process, |
50 | 54 | TimeIntervalListSPtr pTimeIntervalList, TParamData ¶m, FUNC_TYPE funcType) : |
51 | 55 | StatisticOperation<TResultData>(process), |
... | ... | @@ -64,6 +68,7 @@ namespace AMDA { |
64 | 68 | + pParamDataIndexInfo._nbDataToProcess; |
65 | 69 | index++) { |
66 | 70 | _val = _paramInput.get(index); |
71 | + double crtTime = _paramInput.getTime(index); | |
67 | 72 | switch (_funcType) { |
68 | 73 | case FT_MIN: |
69 | 74 | computeMin(_val); |
... | ... | @@ -93,12 +98,15 @@ namespace AMDA { |
93 | 98 | addForMean(_val); |
94 | 99 | generateVector(_val); |
95 | 100 | break; |
96 | - case FT_FIRST_VALUE: | |
97 | 101 | case FT_MIDDLE_VALUE: |
102 | + addForMean(_val); | |
103 | + generateTimeDataVector(crtTime, _val); | |
104 | + case FT_FIRST_VALUE: | |
98 | 105 | case FT_LAST_VALUE: |
106 | + addForMean(_val); | |
99 | 107 | generateVector(_val); |
100 | 108 | break; |
101 | - | |
109 | + | |
102 | 110 | } |
103 | 111 | } |
104 | 112 | } |
... | ... | @@ -121,8 +129,10 @@ namespace AMDA { |
121 | 129 | finalizeMeanResult(StatisticOperation<TResultData>::_resultData); |
122 | 130 | finalizeVarianceResult(StatisticOperation<TResultData>::_resultData); |
123 | 131 | finalizeKurtosisResult(StatisticOperation<TResultData>::_resultData); |
124 | - }else if(_funcType == FT_FIRST_VALUE){ | |
125 | - finalizeFirstResult(StatisticOperation<TResultData>::_resultData); | |
132 | + } else if (_funcType == FT_FIRST_VALUE) { | |
133 | + finalizeFirstValueResult(StatisticOperation<TResultData>::_resultData); | |
134 | + }else if (_funcType == FT_LAST_VALUE) { | |
135 | + finalizeLastValueResult(StatisticOperation<TResultData>::_resultData); | |
126 | 136 | } |
127 | 137 | } |
128 | 138 | |
... | ... | @@ -368,6 +378,40 @@ namespace AMDA { |
368 | 378 | } |
369 | 379 | |
370 | 380 | template<typename Type> |
381 | + void generateTimeDataVector(double time, Type &a) { | |
382 | + _dimDef.str("1"); | |
383 | + if (isNAN(a)) | |
384 | + return; | |
385 | + if (isNAN(StatisticOperation<TResultData>::_resultData._result)) | |
386 | + StatisticOperation<TResultData>::_resultData._result = a; | |
387 | + _timeDataList.push_back(std::make_pair(time, a)); | |
388 | + } | |
389 | + | |
390 | + template<typename Type> | |
391 | + void generateTimeDataVector(double time, std::vector<Type> &a) { | |
392 | + if (StatisticOperation<TResultData>::_resultData.empty()) { | |
393 | + _dimDef.str(""); | |
394 | + _dimDef << a.size(); | |
395 | + | |
396 | + for (unsigned int i = 0; i < a.size(); ++i) { | |
397 | + StatisticDataScalar<Type> data; | |
398 | + resetData(data); | |
399 | + data._result = a[i]; | |
400 | + if (!isNAN(a)) | |
401 | + ++data._nbDataProcessed; | |
402 | + StatisticOperation<TResultData>::_resultData.push_back(data); | |
403 | + } | |
404 | + } | |
405 | + // fill timeDataList | |
406 | + for (int i = 0; i < a.size(); i++) { | |
407 | + std::vector<Type> vec; | |
408 | + vec.push_back(a[i]); | |
409 | + _timeDataList.push_back(std::make_pair(time, vec)); | |
410 | + vec.clear(); | |
411 | + } | |
412 | + } | |
413 | + | |
414 | + template<typename Type> | |
371 | 415 | void finalizeMeanResult(Type& a) { |
372 | 416 | if (!isNAN(a._result) && a._nbDataProcessed > 0) |
373 | 417 | a._result /= a._nbDataProcessed; |
... | ... | @@ -426,20 +470,89 @@ namespace AMDA { |
426 | 470 | } |
427 | 471 | } |
428 | 472 | } |
429 | - | |
430 | - | |
431 | - template<typename Type> | |
473 | + | |
474 | + template<typename Type> | |
432 | 475 | void finalizeFirstValueResult(Type & a) { |
433 | - a._result = _dataList[0]; | |
476 | + if (_dataList.size() == 0) | |
477 | + return; | |
478 | + a._result = _dataList[0]; | |
434 | 479 | } |
435 | 480 | |
436 | 481 | template<typename Type> |
437 | 482 | void finalizeFirstValueResult(std::vector<Type>& a) { |
438 | 483 | for (int i = 0; i < a.size(); i++) { |
439 | - a[i]._result = _dataList[i][0]; | |
484 | + if (_dataList[i].size() == 0) | |
485 | + return; | |
486 | + a[i]._result = _dataList[i][0]; | |
487 | + } | |
488 | + } | |
489 | + | |
490 | + template<typename Type> | |
491 | + void finalizeLastValueResult(Type & a) { | |
492 | + if (_dataList.size() == 0) | |
493 | + return; | |
494 | + a._result = _dataList.back(); | |
495 | + } | |
496 | + | |
497 | + template<typename Type> | |
498 | + void finalizeLastValueResult(std::vector<Type>& a) { | |
499 | + for (int i = 0; i < a.size(); i++) { | |
500 | + if (_dataList[i].size() == 0) | |
501 | + return; | |
502 | + a[i]._result = _dataList[i].back(); | |
503 | + } | |
504 | + } | |
505 | + | |
506 | + /* | |
507 | + template<typename Type> | |
508 | + void finalizeMiddleValueResult(Type & a) { | |
509 | + if (_timeDataList.size() == 0) | |
510 | + return; | |
511 | + if (_timeDataList.size() == 1) { | |
512 | + a._result = _timeDataList[0].second; | |
513 | + return; | |
514 | + } else { | |
515 | + a._result = getMiddleValue(_timeDataList); | |
516 | + } | |
517 | + } | |
518 | + | |
519 | + template<typename Type> | |
520 | + void finalizeMiddleValueResult(std::vector<Type> & a) { | |
521 | + | |
522 | + //vector of pair <time dataScalar> | |
523 | + std::vector<std::pair<double, Type>> timeDataList; | |
524 | + for (int i = 0; i < a.size(); i++) { | |
525 | + for (auto val : _timeDataList) { | |
526 | + if (!isNAN(val.second[i])){ | |
527 | + | |
528 | + timeDataList.push_back(std::make_pair(val.first, val.second[i])); | |
529 | + } | |
440 | 530 | } |
531 | + if (timeDataList.size() == 0) | |
532 | + continue; | |
533 | + a[i].result = getMiddleValue(timeDataList); | |
534 | + timeDataList.clear(); | |
535 | + } | |
441 | 536 | } |
442 | - | |
537 | + | |
538 | + | |
539 | + template<typename Type> | |
540 | + Type getMiddleValue(std::vector<std::pair<double, StatisticDataScalar<Type> >> time1DDataList) { | |
541 | + if (time1DDataList.size() == 1) { | |
542 | + return time1DDataList[0].second; | |
543 | + } | |
544 | + double middeTime = (time1DDataList.front().first + time1DDataList.back().first) / 2; | |
545 | + for (int i = 0; i < time1DDataList.size(); i++) { | |
546 | + if (time1DDataList[i].first == middeTime) { | |
547 | + return time1DDataList[i].second; | |
548 | + } else if (time1DDataList[i].first > middeTime) { | |
549 | + return time1DDataList[i - 1].second + (time1DDataList[i].second - time1DDataList[i - 1].second)* | |
550 | + ((middeTime - time1DDataList[i - 1].first) / (time1DDataList[i].first - time1DDataList[i - 1].first)); | |
551 | + | |
552 | + } | |
553 | + } | |
554 | + } | |
555 | +*/ | |
443 | 556 | template<typename Type> |
444 | 557 | void finalizeVarianceResult(Type & a) { |
445 | 558 | if (_dataList.size() == 0) |
... | ... | @@ -480,7 +593,7 @@ namespace AMDA { |
480 | 593 | |
481 | 594 | template<typename Type> |
482 | 595 | void finalizeSkewnessResult(std::vector<Type> & a) { |
483 | - for (int i = 0; i < a.size(); i++) { | |
596 | + for (int i = 0; i < a.size(); i++) { | |
484 | 597 | int n = _dataList[i].size(); |
485 | 598 | if (n == 0) |
486 | 599 | return; |
... | ... | @@ -535,6 +648,12 @@ namespace AMDA { |
535 | 648 | |
536 | 649 | std::vector<ElementType> _dataList; |
537 | 650 | |
651 | + /* | |
652 | + * vector of pair<time, data> | |
653 | + */ | |
654 | + TimeDataList _timeDataList; | |
655 | + | |
656 | + | |
538 | 657 | FUNC_TYPE _funcType; |
539 | 658 | |
540 | 659 | std::stringstream _dimDef; | ... | ... |
src/ExternLib/StatisticProcesses/MinMaxMeanStatisticProcess.cc
... | ... | @@ -196,7 +196,7 @@ void FirstValueStatisticProcess::createOperation(void) |
196 | 196 | { |
197 | 197 | AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get(); |
198 | 198 | CreateMinMaxMeanStatistic lCreateFirstValueStatistic( *this, _timeIntervalList, *paramInput, FUNC_TYPE::FT_FIRST_VALUE); |
199 | - _operation = lCreateKurtosisStatistic.getStatisticOperation(); | |
199 | + _operation = lCreateFirstValueStatistic.getStatisticOperation(); | |
200 | 200 | } |
201 | 201 | |
202 | 202 | std::string FirstValueStatisticProcess::getUCD(void) |
... | ... | @@ -205,9 +205,54 @@ std::string FirstValueStatisticProcess::getUCD(void) |
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
208 | - * | |
209 | - * / | |
208 | + * Middle Value | |
209 | + */ | |
210 | + | |
211 | +MiddleValueStatisticProcess::MiddleValueStatisticProcess(AMDA::Parameters::Parameter ¶meter, const int& index) : | |
212 | + AMDA::Parameters::StatisticProcess(parameter, false,index) | |
213 | +{ | |
214 | +} | |
215 | + | |
216 | +MiddleValueStatisticProcess::~MiddleValueStatisticProcess(void) | |
217 | +{ | |
218 | +} | |
219 | + | |
220 | +void MiddleValueStatisticProcess::createOperation(void) | |
221 | +{ | |
222 | + AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get(); | |
223 | + CreateMinMaxMeanStatistic lCreateMiddleValueStatistic( *this, _timeIntervalList, *paramInput, FUNC_TYPE::FT_MIDDLE_VALUE); | |
224 | + _operation = lCreateMiddleValueStatistic.getStatisticOperation(); | |
225 | +} | |
226 | + | |
227 | +std::string MiddleValueStatisticProcess::getUCD(void) | |
228 | +{ | |
229 | + return "stat.middleValue"; | |
230 | +} | |
231 | + | |
232 | +/** | |
233 | + * Last Value | |
234 | + */ | |
235 | + | |
236 | +LastValueStatisticProcess::LastValueStatisticProcess(AMDA::Parameters::Parameter ¶meter, const int& index) : | |
237 | + AMDA::Parameters::StatisticProcess(parameter, false,index) | |
238 | +{ | |
239 | +} | |
240 | + | |
241 | +LastValueStatisticProcess::~LastValueStatisticProcess(void) | |
242 | +{ | |
243 | +} | |
244 | + | |
245 | +void LastValueStatisticProcess::createOperation(void) | |
246 | +{ | |
247 | + AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get(); | |
248 | + CreateMinMaxMeanStatistic lCreateLastValueStatistic( *this, _timeIntervalList, *paramInput, FUNC_TYPE::FT_LAST_VALUE); | |
249 | + _operation = lCreateLastValueStatistic.getStatisticOperation(); | |
250 | +} | |
210 | 251 | |
252 | +std::string LastValueStatisticProcess::getUCD(void) | |
253 | +{ | |
254 | + return "stat.lastValue"; | |
255 | +} | |
211 | 256 | } /* namespace MinMaxMean */ |
212 | 257 | } /* namespace Statistic */ |
213 | 258 | } /* namespace AMDA */ | ... | ... |