Blame view

src/ParamOutputImpl/DataMining/DataMiningValidInterval.cc 3.78 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
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
/*
 * DataMiningValidInterval.cc
 *
 *  Created on: 3 oct. 2013
 *      Author: CS
 */

#include "DataMiningValidInterval.hh"

// TimeTable
#include "TimeTableCatalogUtil.hh"


using namespace TimeTableCatalog;

namespace AMDA {
	namespace ParamOutputImpl {
		namespace DataMining {

			log4cxx::LoggerPtr DataMiningValidInterval::_logger(log4cxx::Logger::getLogger("AMDA-Kernel.DataMiningValidInterval"));

			DataMiningValidInterval::DataMiningValidInterval(std::string pPrefixTTFileName, LogicalData pDataToMatch, ParamOutputDataMining* pParamOutputDataMining) :
				DataMiningType(pParamOutputDataMining, pPrefixTTFileName),
				_valCurrent(false),
				_beginTimeInterval(0),
				_endTimeInterval(0),
				_dataToMatch(pDataToMatch){
			}

			void DataMiningValidInterval::setTimeInterval(const TimeInterval& pTimeInterval) {
				DataMiningType::setTimeInterval(pTimeInterval);
				_valCurrent = false;
				_beginTimeInterval = 0;
				_endTimeInterval = 0;
			}

			void DataMiningValidInterval::checkTimeIntervalBounds() {
				// If the begin time of the interval is the same value as the start time research,
				// We must not subtract samplingTime / 2 to the _beginTimeInterval (boundary value)
				// TODO prendre en compte une liste d'intervalle de temps
				// et non plus une date de départ suivi d'un délai.
				if (_beginTimeInterval != _inputTimeInterval._startTime) {
					_beginTimeInterval = _beginTimeInterval - (_samplingTime / 2);
				}

				if(_endTimeInterval != _inputTimeInterval._stopTime) {
					_endTimeInterval = _endTimeInterval + (_samplingTime / 2);
				} else {
					// Nothing to do we have reached the end time research so we must not
					// add samplingTime / 2 to the _endTimeInterval (boundary value).
				}
			}

			void DataMiningValidInterval::createInterval(ParamDataLogicalData* pParamData, ParamDataIndexInfo pParamDataIndexInfo) {
				double lTime;
				double lData;

				for (unsigned int index = pParamDataIndexInfo._startIndex; index < pParamDataIndexInfo._nbDataToProcess + pParamDataIndexInfo._startIndex; ++index) {
					lTime = pParamData->getTime(index);
					lData = pParamData->get(index);

					if(_logger->isDebugEnabled()) {
						std::stringstream date;
						writeISOTime(lTime, TimeTable::YYYYMMDDThhmmss, date);

#if 0	// Ne sert à rien !
						std::string lValue;
						if(lData == True) {
							lValue = "True";
						} else if (pParamData->get(index) == False) {
							lValue = "False";
						} else {
							lValue = "Nan";
						}
#endif
//						LOG4CXX_DEBUG(_logger,"Time and Value: " + date.str() + ", " + lValue);
					}

					// Found beginning of a time interval
					if(!_valCurrent && lData == _dataToMatch) {
						_valCurrent = true;
						_beginTimeInterval = lTime;
						_endTimeInterval = lTime;
					}
					// Increase the end of the time interval
					else if(_valCurrent && lData == _dataToMatch) {
						_endTimeInterval = lTime;
					}
					// Found ending of the time interval
					else if(_valCurrent && lData != _dataToMatch) {
						_valCurrent = false;

						// Check time interval bounds.
						checkTimeIntervalBounds();

//						LOG4CXX_DEBUG(_logger,"resultat min sampling:"<<_paramOutputDataMining->getParameter()->getParamData(this)->getMinSampling());
						_timeTable->addInterval(TimeInterval(_beginTimeInterval, _endTimeInterval));
					}
				}
			}

			void DataMiningValidInterval::finalize() {
				// If the last interval is not closed, so close it.
				if(_valCurrent) {
					_timeTable->addInterval(TimeInterval(_beginTimeInterval - (_samplingTime / 2), _inputTimeInterval._stopTime));
				}
			}

			void DataMiningValidInterval::fillInformation(TimeTable::TIME_FORMAT pTimeFormat, std::string pFileName, int pIndex) {
				finalize();

				DataMiningType::fillInformation(pTimeFormat, pFileName, pIndex);
			}

		} // DataMining
	} // ParamOutputImpl
} // AMDA