From 9aea9f9da288db3ba56314977b9e8a5e0f26e498 Mon Sep 17 00:00:00 2001 From: Hacene SI HADJ MOHAND Date: Wed, 5 May 2021 13:54:58 +0200 Subject: [PATCH] scalar data ok --- src/ExternLib/DataFiltering/DataFiltering.hh | 175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------ src/ExternLib/DataFiltering/DataFilteringCreator.hh | 6 +++--- src/ExternLib/DataFiltering/DataFilteringProcess.cc | 6 +++--- src/ExternLib/DataFiltering/filteringConfig.hh | 2 +- 4 files changed, 146 insertions(+), 43 deletions(-) diff --git a/src/ExternLib/DataFiltering/DataFiltering.hh b/src/ExternLib/DataFiltering/DataFiltering.hh index 3fa7e8e..3f05a98 100644 --- a/src/ExternLib/DataFiltering/DataFiltering.hh +++ b/src/ExternLib/DataFiltering/DataFiltering.hh @@ -14,6 +14,9 @@ #ifndef DATAFILTERING_HH #define DATAFILTERING_HH +#include +#include + #include "Parameter.hh" #include "ParamData.hh" #include "DataTypeMath.hh" @@ -23,11 +26,13 @@ namespace AMDA { namespace Parameters { - namespace DataFiltering{ + namespace DataFiltering { template struct FilteringContainer { + // size of real points(not nan and not spike) int _size = 0; + int _nFilteredPoints = 0; ElemType _sum = 0; ElemType _sumsq = 0; ElemType _ave = 0; @@ -37,11 +42,24 @@ namespace AMDA { }; template + struct FilteringContainer1D { + // size of real points(not nan and not spike) + std::vector _size; + std::vector _nFilteredPoints; + std::vector _sum; + std::vector _sumsq; + std::vector _ave; + std::vector _sig; + std::vector > _values; + std::list _times; + }; + + template class DataFiltering : public Operation { public: // constructor - DataFiltering(Process& pProcess, ParamDataSpec& paramInput, int factor = Default::_factor, int nPoints = Default::_nPoints) : + DataFiltering(Process& pProcess, ParamDataSpec& paramInput, double factor = Default::_factor, int nPoints = Default::_nPoints) : Operation(pProcess), _paramInput(paramInput), _paramOutput(new ParamDataSpec()), @@ -61,45 +79,73 @@ namespace AMDA { ++_index) { double crtTime = _paramInput.getTime(_index); ElemType inputElt = _paramInput.get(_index); - + // initialiser et remplir container - while (_container._size < _nPoints) { - - _container._values.push_back(inputElt); - _container._times.push_back(crtTime); - + if (_container._size < _nPoints) { + + _container._values.push_back(inputElt); + _container._times.push_back(crtTime); + if (!isNAN(inputElt)) { _container._sum += inputElt; _container._sumsq += inputElt*inputElt; _container._size += 1; } - } - _container._ave = (ElemType) _container._sum/_container._size; - _container._sig = std::sqrt((_container._sumsq- _container._sum*_container._sum/_container._size)/_container._size); - - // filter Elements - for(ElemType elt : _container._values){ - if(std::abs(elt-_container._ave) > _factor*_container._sig){ - elt << NotANumber(); - _container._sum -= elt; - _container._sumsq -= elt*elt; + } else { + _container._ave = (ElemType) _container._sum / _container._size; + _container._sig = std::sqrt((_container._sumsq - _container._sum * _container._sum / _container._size) / _container._size); + + // filter Elements + for (auto it = _container._values.begin(); it != _container._values.end(); ++it) { + ElemType crt_val = *it; + if(isNAN(crt_val)) + continue; + if (std::abs(crt_val - _container._ave) > _factor * _container._sig) { + _container._sum -= crt_val; + _container._sumsq -= crt_val*crt_val; + _container._size -= 1; + _container._nFilteredPoints += 1; + *it << NotANumber(); + } + } + _paramOutput->pushTime(_container._times.front()); + _paramOutput->getDataList().push_back(_container._values.front()); + _container._values.pop_front(); + _container._times.pop_front(); + if(!isNAN(_container._values.front())){ _container._size -= 1; - } - } - _paramOutput->pushTime(_container._times.front()); - _paramOutput->getDataList().push_back(_container._values.front()); - _container._values.pop_front(); - _container._times.pop_front(); - _container._size -= 1; - - if(_index == pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess-1){ - std::list::iterator itTimes = _container._times.begin(); - for(ElemType elt : _container._values) { - _paramOutput->pushTime(*itTimes); - _paramOutput->getDataList().push_back(elt); - ++ itTimes; - } - } + _container._sum -= _container._values.front(); + _container._sumsq -= _container._values.front() * _container._values.front(); + } + + _container._values.push_back(inputElt); + _container._times.push_back(crtTime); + if (!isNAN(inputElt)) { + _container._sum += inputElt; + _container._sumsq += inputElt*inputElt; + _container._size += 1; + } + } + // last value filter and write + if (_index == pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess - 1) { + _container._ave = (ElemType) _container._sum / _container._size; + _container._sig = std::sqrt((_container._sumsq - _container._sum * _container._sum / _container._size) / _container._size); + for (auto it = _container._values.begin(); it != _container._values.end(); ++it) { + ElemType crt_val = *it; + if (std::abs(crt_val - _container._ave) > _factor * _container._sig){ + *it << NotANumber(); + _container._nFilteredPoints += 1; + } + } + + std::list::iterator itTimes = _container._times.begin(); + for (ElemType elt : _container._values) { + _paramOutput->pushTime(*itTimes); + _paramOutput->getDataList().push_back(elt); + ++itTimes; + } + } + } } @@ -110,14 +156,71 @@ namespace AMDA { ParamDataSpec* _paramOutput; - int _factor; + double _factor; int _nPoints; FilteringContainer _container; }; + + template + class DataFiltering1D : public Operation { + public: + // constructor + + DataFiltering1D(Process& pProcess, ParamDataSpec >& paramInput, double factor = Default::_factor, int nPoints = Default::_nPoints) : + Operation(pProcess), + _paramInput(paramInput), + _paramOutput(new ParamDataSpec >()), + _factor(factor), + _nPoints(nPoints) { + _paramDataOutput = _paramOutput; + } + + virtual ~DataFiltering1D() { + + } + + void write(ParamDataIndexInfo &pParamDataIndexInfo) { + // init container + std::vector > outputList; + int size = _paramInput.get(pParamDataIndexInfo._startIndex).size(); + std::vector vecInt(size, 0); + std::vector vecElement(size, 0); + _container._size = vecInt; + _container._nFilteredPoints = vecInt; + _container._ave = vecElement; + _container._sum = vecElement; + _container._sumsq = vecElement; + _container._sig = vecElement; + for (int j = 0; j < size; ++j) { + std::list list; + _container._values.push_back(list); + outputList.push_back(list); + } + for (int i = 0; i < size; ++i) { + + } + + + + + } + + + + private: + ParamDataSpec >& _paramInput; + + ParamDataSpec >* _paramOutput; + + double _factor; + int _nPoints; + FilteringContainer1D _container; + + }; + } } } -} #endif /* DATAFILTERING_HH */ diff --git a/src/ExternLib/DataFiltering/DataFilteringCreator.hh b/src/ExternLib/DataFiltering/DataFilteringCreator.hh index b210c67..b2c971e 100644 --- a/src/ExternLib/DataFiltering/DataFilteringCreator.hh +++ b/src/ExternLib/DataFiltering/DataFilteringCreator.hh @@ -25,7 +25,7 @@ namespace AMDA { class DataFilteringCreator : public VisitorOfParamData { public: - DataFilteringCreator(Process& pProcess, ParamData& paramInput, int factor=Default::_factor, int nPoints=Default::_nPoints) : + DataFilteringCreator(Process& pProcess, ParamData& paramInput, double factor=Default::_factor, int nPoints=Default::_nPoints) : _process(pProcess), _paramData(paramInput), _factor(factor), @@ -173,12 +173,12 @@ namespace AMDA { } template void create1DOperation() { - _operation = new DataFiltering::DataFiltering(_process, dynamic_cast &> (_paramData), _factor, _nPoints); + _operation = new DataFiltering::DataFiltering1D(_process, dynamic_cast>&> (_paramData), _factor, _nPoints); } Process &_process; ParamData &_paramData; - int _factor; + double _factor; int _nPoints; Operation* _operation; }; diff --git a/src/ExternLib/DataFiltering/DataFilteringProcess.cc b/src/ExternLib/DataFiltering/DataFilteringProcess.cc index 1272d1b..357dc9a 100644 --- a/src/ExternLib/DataFiltering/DataFilteringProcess.cc +++ b/src/ExternLib/DataFiltering/DataFilteringProcess.cc @@ -45,10 +45,10 @@ namespace AMDA { TimeStamp DataFilteringProcess::init() { TimeStamp timeStamp = _parameterInput->init(this, _timeIntervalList); _paramInput = _parameterInput->getParamData(this).get(); - int factor = Default::_factor; + double factor = Default::_factor; int nPoints = Default::_nPoints; - if (_attributList.size() == 1) - factor = atoi(_attributList[0].c_str()); + if (_attributList.size() >= 1) + factor = std::stod(_attributList[0].c_str()); if (_attributList.size() == 2) nPoints = atoi(_attributList[1].c_str()); DataFilteringCreator ICreator(*this, *_paramInput, factor, nPoints); diff --git a/src/ExternLib/DataFiltering/filteringConfig.hh b/src/ExternLib/DataFiltering/filteringConfig.hh index 099b502..b494491 100644 --- a/src/ExternLib/DataFiltering/filteringConfig.hh +++ b/src/ExternLib/DataFiltering/filteringConfig.hh @@ -31,7 +31,7 @@ namespace AMDA { } namespace Strong{ - extern const int _factor=4; + extern const double _factor=4.0; extern const int _nPoints=100; } -- libgit2 0.21.2