1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "livestatus/stdaggregator.hpp"
6 using namespace icinga;
8 StdAggregator::StdAggregator(String attr)
9 : m_StdAttr(std::move(attr))
12 StdAggregatorState *StdAggregator::EnsureState(AggregatorState **state)
15 *state = new StdAggregatorState();
17 return static_cast<StdAggregatorState *>(*state);
20 void StdAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
22 Column column = table->GetColumn(m_StdAttr);
24 Value value = column.ExtractValue(row);
26 StdAggregatorState *pstate = EnsureState(state);
28 pstate->StdSum += value;
29 pstate->StdQSum += pow(value, 2);
33 double StdAggregator::GetResultAndFreeState(AggregatorState *state) const
35 StdAggregatorState *pstate = EnsureState(&state);
36 double result = sqrt((pstate->StdQSum - (1 / pstate->StdCount) * pow(pstate->StdSum, 2)) / (pstate->StdCount - 1));