Blame view

src/ParamOutputImpl/DataMining/DataMiningValidInterval.hh 3.37 KB
fbe3c2bb   Benjamin Renard   First commit
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
/*
 * 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:
63fff7ed   Benjamin Renard   Support integer i...
34
				DataMiningValidInterval(std::string pPrefixTTFileName, bool pIsGapFile, ParamOutputDataMining* pParamOutputDataMining);
fbe3c2bb   Benjamin Renard   First commit
35
36
37
38
39
40
41
42
43
44

				/**
				 * @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.
				 */
63fff7ed   Benjamin Renard   Support integer i...
45
46
47
48
49
50
51
52
				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();

f44b56f2   Benjamin Renard   Fix bug with Data...
53
						bool isValid = _isGapFile ? isNAN(lData) : (lData != nullElem) && !isNAN(lData);
63fff7ed   Benjamin Renard   Support integer i...
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

						// 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));
						}
					}
				}

fbe3c2bb   Benjamin Renard   First commit
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

				/**
				 * @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:
63fff7ed   Benjamin Renard   Support integer i...
102
				bool _isGapFile;
fbe3c2bb   Benjamin Renard   First commit
103
104
105
106
107
108
109
110

				void checkTimeIntervalBounds();

				void finalize();
			};

			struct DataMiningTrue : public DataMiningValidInterval {
				DataMiningTrue (ParamOutputDataMining* pParamOutputDataMining) :
63fff7ed   Benjamin Renard   Support integer i...
111
					DataMiningValidInterval("", false,  pParamOutputDataMining) {
fbe3c2bb   Benjamin Renard   First commit
112
113
114
115
116
				}
			};

			struct DataMiningNoData : public DataMiningValidInterval {
				DataMiningNoData (ParamOutputDataMining* pParamOutputDataMining) :
63fff7ed   Benjamin Renard   Support integer i...
117
					DataMiningValidInterval("Gaps_", true,  pParamOutputDataMining) {
fbe3c2bb   Benjamin Renard   First commit
118
119
120
121
122
123
124
				}
			};

		} // DataMining
	} // ParamOutputImpl
} // AMDA
#endif /* DATAMININGVALIDINTERVAL_HH_ */