/** * MinVarStatistic.hh * * Created on: 09 nov. 2014 * Author: AKKA */ #ifndef MINVARSTATISTIC_HH_ #define MINVARSTATISTIC_HH_ #include "ParamData.hh" #include "DataTypeMath.hh" #include "VisitorOfParamData.hh" #include "StatisticData.hh" #include "StatisticOperation.hh" #include "StatisticProcess.hh" #include "MinVarFunction.hh" #include "TimeInterval.hh" namespace AMDA { namespace Statistic { namespace MinVar { using namespace AMDA::Parameters; template class MinVarStatisticOperation : public StatisticOperation> { public: /** * @brief Element type of paramData */ typedef typename TParamData::ElementType ElementType; typedef StatisticDataMatrix TResultData; MinVarStatisticOperation(StatisticProcess& process, TimeIntervalListSPtr pTimeIntervalList, TParamData ¶m) : StatisticOperation(process), _paramInput(param), _timeIntervalList(pTimeIntervalList), _currentTimeInterval(_timeIntervalList->begin()), _nbDataProcessed(0) { _func.reset(); } virtual ~MinVarStatisticOperation(void) { _func.reset(); } virtual void compute(ParamDataIndexInfo &pParamDataIndexInfo) { for (unsigned int index = pParamDataIndexInfo._startIndex; index < pParamDataIndexInfo._startIndex + pParamDataIndexInfo._nbDataToProcess; index++) { _val = _paramInput.get(index); if (isNAN(_val)) continue; if (_func.pushVector(_val)) ++_nbDataProcessed; } } virtual void finalizeCompute(void) { StatisticOperation::_resultData.clear(); std::vector result; if (_func.computeMinVar(result)) { //push function result in StatisticData for (unsigned int i = 0; i < result.size(); ++i) { StatisticDataVector vec; for (unsigned int j = 0; j < result[i].size(); ++j) { StatisticDataScalar data; data._result = result[i][j]; data._nbDataProcessed = _nbDataProcessed; vec.push_back(data); } StatisticOperation::_resultData.push_back(vec); } } } virtual void reset() { StatisticOperation::reset(); //ToDo - StatisticOperation::_resultData << NotANumber(); _nbDataProcessed = 0; _func.reset(); } /** * @brief Get the result dimensiond efinition. */ virtual std::string getResultDimDefinition(bool forCoverage = false) { if (forCoverage) return "1"; return "3x3"; } private: /** * @brief real ParamData Input */ TParamData& _paramInput; TimeIntervalListSPtr _timeIntervalList; TimeIntervalList::iterator _currentTimeInterval; ElementType _val; int _nbDataProcessed; MinVarFunction _func; }; class CreateMinVarStatistic: public VisitorOfParamData { public: /** * @brief constructor */ CreateMinVarStatistic(StatisticProcess& pProcess, TimeIntervalListSPtr pTimeIntervalList, ParamData ¶mData) : _process(pProcess), _timeIntervalList(pTimeIntervalList), _paramData(paramData), _operation(NULL) { _paramData.accept(*this); } StatisticOperationBase* getStatisticOperation(void) { return _operation; } /** * @overload VisitorOfParamData::visit(ParamDataScalaireShort *) */ virtual void visit(ParamDataScalaireShort *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *) */ virtual void visit(ParamDataScalaireFloat *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *) */ virtual void visit(ParamDataScalaireDouble *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *) */ virtual void visit(ParamDataScalaireLongDouble *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataScalaireInt *) */ virtual void visit(ParamDataScalaireInt *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataLogicalData *) */ virtual void visit(ParamDataLogicalData *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DShort *) */ virtual void visit(ParamDataTab1DShort *) { _operation = new MinVarStatisticOperation(_process, _timeIntervalList, dynamic_cast(_paramData)); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *) */ virtual void visit(ParamDataTab1DFloat *) { _operation = new MinVarStatisticOperation(_process, _timeIntervalList, dynamic_cast(_paramData)); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *) */ virtual void visit(ParamDataTab1DDouble *) { _operation = new MinVarStatisticOperation(_process, _timeIntervalList, dynamic_cast(_paramData)); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *) */ virtual void visit(ParamDataTab1DLongDouble *) { _operation = new MinVarStatisticOperation(_process, _timeIntervalList, dynamic_cast(_paramData)); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DInt *) */ virtual void visit(ParamDataTab1DInt *) { _operation = new MinVarStatisticOperation(_process, _timeIntervalList, dynamic_cast(_paramData)); } /** * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *) */ virtual void visit(ParamDataTab1DLogicalData *) { BOOST_THROW_EXCEPTION( AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg( "CreateStatistic operation not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DShort *) */ virtual void visit(ParamDataTab2DShort *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DShort data not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *) */ virtual void visit(ParamDataTab2DFloat *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DFloat data not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *) */ virtual void visit(ParamDataTab2DDouble *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DDouble data not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *) */ virtual void visit(ParamDataTab2DLongDouble *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLongDouble data not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DInt *) */ virtual void visit(ParamDataTab2DInt *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DInt data not supported")); } /** * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *) */ virtual void visit(ParamDataTab2DLogicalData *) { BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_ERROR_UNKNOWN) << AMDA::ex_msg("ParamDataTab2DLogicalData data not supported")); } private: StatisticProcess& _process; TimeIntervalListSPtr& _timeIntervalList; ParamData &_paramData; StatisticOperationBase *_operation; }; } /* namespace MinVar */ } /* namespace Statistic */ } /* namespace AMDA */ #endif /* MINVARSTATISTIC_HH_ */