1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "livestatus/invavgaggregator.hpp"
5 using namespace icinga;
7 InvAvgAggregator::InvAvgAggregator(String attr)
8 : m_InvAvgAttr(std::move(attr))
11 InvAvgAggregatorState *InvAvgAggregator::EnsureState(AggregatorState **state)
14 *state = new InvAvgAggregatorState();
16 return static_cast<InvAvgAggregatorState *>(*state);
19 void InvAvgAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
21 Column column = table->GetColumn(m_InvAvgAttr);
23 Value value = column.ExtractValue(row);
25 InvAvgAggregatorState *pstate = EnsureState(state);
27 pstate->InvAvg += (1.0 / value);
28 pstate->InvAvgCount++;
31 double InvAvgAggregator::GetResultAndFreeState(AggregatorState *state) const
33 InvAvgAggregatorState *pstate = EnsureState(&state);
34 double result = pstate->InvAvg / pstate->InvAvgCount;