/* * 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) { for (unsigned int index = pParamDataIndexInfo._startIndex; index < pParamDataIndexInfo._nbDataToProcess + pParamDataIndexInfo._startIndex; ++index) { double lTime = pParamData->getTime(index); double 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