Blame view

src/ExternLib/StatisticProcesses/CountBoolStatistic.hh 14.1 KB
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/* 
 * File:   CountStatistic.hh
 * Author: AKKA
 *
 * Created on December 20, 2019, 1:44 PM
 */

#ifndef COUNTSTATISTIC_HH
#define COUNTSTATISTIC_HH

#include "ParamData.hh"
#include "DataTypeMath.hh"
#include "VisitorOfParamData.hh"
#include "StatisticData.hh"
#include "StatisticOperation.hh"
#include "StatisticProcess.hh"
#include <math.h>
#include "TimeInterval.hh"

namespace AMDA {
    namespace Statistic {
        namespace CountBool {

            using namespace AMDA::Parameters;

            typedef enum {
                FT_COUNT_TRUE,
            } COUNT_BOOL_FUNC_TYPE;

            template <typename TParamData, typename TResultData>
            class CountStatisticOperation : public StatisticOperation<TResultData> {
            public:
                typedef typename TParamData::ElementType ElementType;

                CountStatisticOperation(StatisticProcess& process,
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
37
                        TimeIntervalListSPtr pTimeIntervalList, TParamData &param, COUNT_BOOL_FUNC_TYPE funcType) :
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
                StatisticOperation<TResultData>(process),
                _paramInput(param), _timeIntervalList(pTimeIntervalList),
                _currentTimeInterval(_timeIntervalList->begin()),
                _funcType(funcType), _dimDef("unknown") {
                    resetData(StatisticOperation<TResultData>::_resultData);
                }

                virtual ~CountStatisticOperation(void) {
                }

                virtual void compute(ParamDataIndexInfo &pParamDataIndexInfo) {
                    for (unsigned int index = pParamDataIndexInfo._startIndex;
                            index < pParamDataIndexInfo._startIndex
                            + pParamDataIndexInfo._nbDataToProcess;
                            index++) {
                        _val = _paramInput.get(index);
                        switch (_funcType) {
                            case FT_COUNT_TRUE:
                                countTrue(_val);
                                break;
                        }
                    }
                }

                virtual void finalizeCompute(void) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
63
                    // do nothing averything is ok
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
                }

                virtual std::string getResultDimDefinition(bool /* forCoverage */) {
                    return _dimDef.str();
                }

                virtual void reset() {
                    StatisticOperation<TResultData>::reset();
                    resetData(StatisticOperation<TResultData>::_resultData);
                }
            private:

                template<typename Type>
                void resetData(Type &a) {
                    a._result << NotANumber();
                    a._nbDataProcessed = 0;
                }

                template<typename Type>
                void resetData(std::vector<Type> &a) {
                    a.clear();
                }
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
86
87

                template<typename Type>
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
88
89
                void countTrue(Type &a) {
                    _dimDef.str("1");
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
90
                    if (typeid (a) != typeid ( AMDA::Parameters::LogicalData)) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
91
                        BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("Only boolean params are supported supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
92
93
                        return;
                    }
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
94
95
96
                    if (isNAN(StatisticOperation<TResultData>::_resultData._result))
                        StatisticOperation<TResultData>::_resultData._result = 0;
                    ++StatisticOperation<TResultData>::_resultData._nbDataProcessed;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
97
98
                    if (isNAN(a) || a != AMDA::Parameters::LogicalData::True)
                        return;
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
99
                    ++StatisticOperation<TResultData>::_resultData._result;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
100
                }
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
101
102

                template<typename Type>
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
103
104
105
106
107
                void countTrue(std::vector<Type> &a) {
                    if (StatisticOperation<TResultData>::_resultData.empty()) {
                        _dimDef.str("");
                        _dimDef << a.size();
                        for (unsigned int i = 0; i < a.size(); ++i) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
108
                            if (typeid (a[i]) != typeid ( AMDA::Parameters::LogicalData)) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
109
                                BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("Only boolean params are supported supported"));
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
110
                                return;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
111
                            }
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
112
                            StatisticDataScalar<int> data;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
113
                            resetData(data);
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
114
115
116
117
                            ++data._nbDataProcessed;
                            data._result = 0;
                            if (!isNAN(a[i]) && (int) a[i] == AMDA::Parameters::LogicalData::True)
                                ++ data._result;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
118
119
120
121
122
                            StatisticOperation<TResultData>::_resultData.push_back(data);
                        }
                        return;
                    }
                    for (unsigned int i = 0; i < StatisticOperation<TResultData>::_resultData.size(); ++i) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
123
                        if (isNAN(a[i]))
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
124
125
                            continue;
                        ++StatisticOperation<TResultData>::_resultData[i]._nbDataProcessed;
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
126
127
                        if (a[i] == AMDA::Parameters::LogicalData::True)
                            ++StatisticOperation<TResultData>::_resultData[i]._result;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
128
129
                    }
                }
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
130
131
132
133
134
135
136
137
138
139
140
141

                /**
                 * @brief real ParamData Input
                 */
                TParamData& _paramInput;

                TimeIntervalListSPtr _timeIntervalList;

                TimeIntervalList::iterator _currentTimeInterval;

                ElementType _val;

3ee220fe   Hacene SI HADJ MOHAND   covrage ok
142
                COUNT_BOOL_FUNC_TYPE _funcType;
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

                std::stringstream _dimDef;

            }; //Class Count

            class CreateCountBoolStatistic : public VisitorOfParamData {
            public:

                CreateCountBoolStatistic(StatisticProcess& pProcess,
                        TimeIntervalListSPtr pTimeIntervalList,
                        ParamData &paramData, COUNT_BOOL_FUNC_TYPE type) :
                _process(pProcess), _timeIntervalList(pTimeIntervalList),
                _paramData(paramData), _operation(NULL), _type(type) {
                    _paramData.accept(*this);
                }

                StatisticOperationBase* getStatisticOperation(void) {
                    return _operation;
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireShort *)
                 */
                virtual void visit(ParamDataScalaireShort *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
167
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
168
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
169
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
170
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
171
172
173
174
175
176
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireFloat *)
                 */
                virtual void visit(ParamDataScalaireFloat *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
177
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
178
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
179
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
180
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
181
182
183
184
185
186
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireDouble *)
                 */
                virtual void visit(ParamDataScalaireDouble *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
187
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
188
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
189
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
190
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
191
192
193
194
195
196
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireLongDouble *)
                 */
                virtual void visit(ParamDataScalaireLongDouble *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
197
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
198
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
199
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
200
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
201
202
203
204
205
206
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataScalaireInt *)
                 */
                virtual void visit(ParamDataScalaireInt *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
207
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
208
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
209
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
210
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
211
212
213
214
215
216
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataLogicalData *)
                 */
                virtual void visit(ParamDataLogicalData *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
217
                    _operation = new CountStatisticOperation<ParamDataLogicalData, StatisticDataScalar<int>>(_process,
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
218
219
220
221
222
223
224
                            _timeIntervalList, dynamic_cast<ParamDataLogicalData &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DShort *)
                 */
                virtual void visit(ParamDataTab1DShort *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
225
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
226
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
227
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
228
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
229
230
231
232
233
234
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DFloat *)
                 */
                virtual void visit(ParamDataTab1DFloat *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
235
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
236
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
237
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
238
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
239
240
241
242
243
244
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DDouble *)
                 */
                virtual void visit(ParamDataTab1DDouble *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
245
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
246
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
247
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
248
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
249
250
251
252
253
254
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DLongDouble *)
                 */
                virtual void visit(ParamDataTab1DLongDouble *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
255
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
256
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
257
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
258
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
259
260
261
262
263
264
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DInt *)
                 */
                virtual void visit(ParamDataTab1DInt *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
265
                    BOOST_THROW_EXCEPTION(
d735ed8f   Hacene SI HADJ MOHAND   handling error
266
                            AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL)
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
267
                            << AMDA::ex_msg(
d735ed8f   Hacene SI HADJ MOHAND   handling error
268
                            "Only boolean parameters are supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
269
270
271
272
273
274
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab1DLogicalData *)
                 */
                virtual void visit(ParamDataTab1DLogicalData *) {
3ee220fe   Hacene SI HADJ MOHAND   covrage ok
275
                    _operation = new CountStatisticOperation<ParamDataTab1DLogicalData, StatisticDataVector<int>>(_process,
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
276
277
278
279
280
281
282
                            _timeIntervalList, dynamic_cast<ParamDataTab1DLogicalData &> (_paramData), _type);
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DShort *)
                 */
                virtual void visit(ParamDataTab2DShort *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
283
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DShort data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
284
285
286
287
288
289
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DFloat *)
                 */
                virtual void visit(ParamDataTab2DFloat *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
290
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DFloat data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
291
292
293
294
295
296
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DDouble *)
                 */
                virtual void visit(ParamDataTab2DDouble *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
297
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DDouble data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
298
299
300
301
302
303
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DLongDouble *)
                 */
                virtual void visit(ParamDataTab2DLongDouble *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
304
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DLongDouble data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
305
306
307
308
309
310
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DInt *)
                 */
                virtual void visit(ParamDataTab2DInt *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
311
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DInt data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
312
313
314
315
316
317
                }

                /**
                 * @overload VisitorOfParamData::visit(ParamDataTab2DLogicalData *)
                 */
                virtual void visit(ParamDataTab2DLogicalData *) {
d735ed8f   Hacene SI HADJ MOHAND   handling error
318
                    BOOST_THROW_EXCEPTION(AMDA::AMDA_exception() << AMDA::errno_code(AMDA_STAT_NOT_BOOL) << AMDA::ex_msg("ParamDataTab2DLogicalData data not supported"));
3b301911   Hacene SI HADJ MOHAND   ok for countTrue
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
                }

            private:
                StatisticProcess& _process;

                TimeIntervalListSPtr& _timeIntervalList;

                ParamData &_paramData;

                StatisticOperationBase *_operation;

                COUNT_BOOL_FUNC_TYPE _type;


            };

        }//Count
    }//STATISTIC
} //AMDA



#endif /* COUNTSTATISTIC_HH */