StatisticProcess.cc
2.97 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
125
126
127
128
/*
* StatisticProcess.cc
*
* Created on: Nov 05, 2014
* Author: AKKA
*/
#include "StatisticOperation.hh"
#include "StatisticProcess.hh"
#include "ParamData.hh"
using namespace std;
using namespace boost;
using namespace log4cxx;
namespace AMDA {
namespace Parameters {
LoggerPtr StatisticProcess::_logger(Logger::getLogger("AMDA-Kernel.StatisticProcess"));
/**
*
* Default constructor.
*/
StatisticProcess::StatisticProcess(Parameter ¶meter, bool isCoverageIndependantOfResultType, int index) :
DataClient(),
_parameter(parameter), _args(),
_isCoverageIndependantOfResultType(isCoverageIndependantOfResultType),
_index(index), _timeIntervalList(),
_currentTimeInterval(), _operation(NULL){
}
/**
* Default destructor.
*/
StatisticProcess::~StatisticProcess() {
//_parameter.closeConnection(this);
if (_operation != NULL)
delete _operation;
_operation = NULL;
}
/**
* @overload DataClient::establishConnection
*/
void StatisticProcess::establishConnection()
{
_parameter.openConnection(this);
}
/**
* @brief initializes time attribute
*/
TimeStamp StatisticProcess::init(TimeIntervalListSPtr pTimeIntervalList)
{
LOG4CXX_DEBUG(_logger,"StatisticProcess::init");
_timeIntervalList = pTimeIntervalList;
_currentTimeInterval = _timeIntervalList->begin();
TimeStamp stamp = _parameter.init(this,pTimeIntervalList);
createOperation();
return stamp;
}
/*
* @brief Set arguments map
*/
void StatisticProcess::setArguments(std::map<std::string,std::string>& args)
{
_args = args;
}
/**
* @brief compute statistic result
*/
void StatisticProcess::compute(std::vector<std::string> &result, std::vector<std::string> &coverage)
{
//clear result vectors
result.clear();
coverage.clear();
//get data and compute statistic result
ParamDataIndexInfo lparamDataIndexInfo = _parameter.getAsync(this).get();
while ((!lparamDataIndexInfo._noMoreTimeInt && !lparamDataIndexInfo._timeIntToProcessChanged) || (lparamDataIndexInfo._nbDataToProcess > 0))
{
_operation->compute(lparamDataIndexInfo);
if (lparamDataIndexInfo._timeIntToProcessChanged || lparamDataIndexInfo._noMoreTimeInt)
break;
lparamDataIndexInfo = _parameter.getAsync(this).get();
}
//finalize computation
_operation->finalizeCompute();
//compute ideal number of data on the current interval
AMDA::Parameters::ParamData *paramInput = _parameter.getParamData(this).get();
int ideal = ((_currentTimeInterval->_stopTime - _currentTimeInterval->_startTime) / paramInput->getMinSampling()) + 1;
//push result
_operation->pushResult(result,coverage,ideal,_isCoverageIndependantOfResultType,_index);
//go to next interval
++_currentTimeInterval;
_operation->reset();
}
std::string StatisticProcess::getResultDimDefinition(bool forCoverage)
{
if (_operation == NULL)
return "unknown";
if (_index >= 0)
return "1";
return _operation->getResultDimDefinition(forCoverage);
}
std::string StatisticProcess::getUCD(void)
{
return "stat";
}
} /* namespace Parameters */
} /* namespace AMDA */