DataMiningValidInterval.hh
3.37 KB
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
37
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
* DataMiningValidInterval.hh
*
* Created on: 3 oct. 2013
* Author: guillaume
*/
#ifndef DATAMININGVALIDINTERVAL_HH_
#define DATAMININGVALIDINTERVAL_HH_
#include "DataMiningType.hh"
#include <utility>
#include <vector>
#include <memory>
#include "TimeInterval.hh"
#include "AbstractWriter.hh"
using namespace AMDA::Parameters;
namespace AMDA {
namespace ParamOutputImpl {
namespace DataMining {
class ParamOutputDataMining;
typedef boost::shared_ptr<TimeTable> TimeTableSPtr;
class DataMiningValidInterval : public DataMiningType {
public:
DataMiningValidInterval(std::string pPrefixTTFileName, bool pIsGapFile, ParamOutputDataMining* pParamOutputDataMining);
/**
* @brief Change time interval on which to work.
* @note It also reset static data to begin with proper value and not with the old time interval.
*/
void setTimeInterval(const TimeInterval& pTimeInterval);
/**
* @brief Create interval in which value corresponds to the given value in constructor parameter.
*/
template <typename TParamData>
void createInterval(TParamData* pParamData, ParamDataIndexInfo pParamDataIndexInfo) {
for (unsigned int index = pParamDataIndexInfo._startIndex; index < pParamDataIndexInfo._nbDataToProcess + pParamDataIndexInfo._startIndex; ++index) {
double lTime = pParamData->getTime(index);
typename TParamData::ElementType lData = pParamData->get(index);
typename TParamData::ElementType nullElem;
nullElem << ElemNull();
bool isValid = _isGapFile ? isNAN(lData) : (lData != nullElem) && !isNAN(lData);
// Found beginning of a time interval
if(!_valCurrent && isValid) {
_valCurrent = true;
_beginTimeInterval = lTime;
_endTimeInterval = lTime;
}
// Increase the end of the time interval
else if(_valCurrent && isValid) {
_endTimeInterval = lTime;
}
// Found ending of the time interval
else if(_valCurrent && !isValid) {
_valCurrent = false;
// Check time interval bounds.
checkTimeIntervalBounds();
_timeTable->addInterval(TimeInterval(_beginTimeInterval, _endTimeInterval));
}
}
}
/**
* @brief Fill information (history, description, filename, ...).
*/
void fillInformation(TimeTable::TIME_FORMAT pTimeFormat, std::string pFileName, int pIndex = 0);
protected:
/**
* @brief _valCurrent read, true if current value is True (see LogicalData)
*/
bool _valCurrent;
/**
* @brief _beginTimeInterval identify the beginning value of an interval
*/
double _beginTimeInterval;
/**
* @brief _beginTimeInterval identify the ending value of an interval
*/
double _endTimeInterval;
static log4cxx::LoggerPtr _logger;
private:
bool _isGapFile;
void checkTimeIntervalBounds();
void finalize();
};
struct DataMiningTrue : public DataMiningValidInterval {
DataMiningTrue (ParamOutputDataMining* pParamOutputDataMining) :
DataMiningValidInterval("", false, pParamOutputDataMining) {
}
};
struct DataMiningNoData : public DataMiningValidInterval {
DataMiningNoData (ParamOutputDataMining* pParamOutputDataMining) :
DataMiningValidInterval("Gaps_", true, pParamOutputDataMining) {
}
};
} // DataMining
} // ParamOutputImpl
} // AMDA
#endif /* DATAMININGVALIDINTERVAL_HH_ */