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