11 collection.push_back(resourceUsageData);
12 if (maxSize && maxSize < collection.size())
14 while (maxSize < collection.size())
16 collection.pop_front();
19 weights.insert(std::map<std::string, Weights>::value_type(identity, Weights()));
32 double diff = abs(weights[identity].last-weights[identity].prev);
34 std::stringstream outMsg;
35 if (diff != weights[identity].diff)
37 outMsg <<
"calculateAverage (" << diff <<
" vs. " << weights[identity].diff <<
") identity: " << identity <<
" steps:{ ";
39 for(std::vector<size_t>::reverse_iterator iter=steps.rbegin();iter!=steps.rend();++iter)
40 outMsg << (*iter) <<
" ";
43 if (diff > weights[identity].diff*2)
52 if (diff != weights[identity].diff)
54 outMsg <<
"} [" << weights[identity].stepIndex <<
"] = " << count;
60 weights[identity].diff = diff;
61 weights[identity].prev = weights[identity].last;
63 return resourceUsageData;
70 for (ResourceUsageCollection::reverse_iterator iter=collection.rbegin();iter!=collection.rend();++iter)
72 resourceUsageData += (*iter);
76 resourceUsageData /= (count < collection.size())?count:collection.size();
77 return resourceUsageData;
84 std::vector<double> listWeights = weights[identity].listWeights;
86 std::stringstream outMsg;
87 outMsg <<
"WEIGHTS RANGE: ";
88 for (
size_t i=0;i<listWeights.size();++i)
89 outMsg << listWeights[i] <<
" ";
92 if (listWeights.size())
94 auto range = std::minmax_element(listWeights.begin(),listWeights.end());
96 outMsg <<
"MIN: " << (*range.first) <<
"\tMAX: " << (*range.second);
100 double resourceUsageRange = (*range.second-*range.first)*100/(*range.second);
102 outMsg <<
"\tmaxAllowedRange: " << maxAllowedRange <<
"\tresourceUsageRange: " << resourceUsageRange;
104 if (maxAllowedRange > resourceUsageRange && resourceUsageRange)
115 : maxSize(0), steps(), weights(), logger(logger_)
124 size_t index = maxSize;
127 steps.push_back(index);
134 if (weights[identity].stepIndex+1 < steps.size())
135 ++(weights[identity].stepIndex);
136 return steps[weights[identity].stepIndex];
141 if (weights[identity].stepIndex > 0)
142 --(weights[identity].stepIndex);
143 return steps[weights[identity].stepIndex];
148 weights[identity].last =
weight;
154 std::map<std::string, Weights>::iterator iter = weights.find(identity);
155 if (iter != weights.end())
156 result = (*iter).second.last;
162 weights[identity].listWeights = listWeights;
167 std::vector<double> listWeights;
168 std::map<std::string, Weights>::iterator iter = weights.find(identity);
169 if (iter != weights.end())
170 listWeights = (*iter).second.listWeights;