From 0915b3ef56dfac3113cce55a59a5765dc94976be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:34:54 +0200 Subject: Adding upstream version 2.13.6. Signed-off-by: Daniel Baumann --- lib/livestatus/invavgaggregator.cpp | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/livestatus/invavgaggregator.cpp (limited to 'lib/livestatus/invavgaggregator.cpp') diff --git a/lib/livestatus/invavgaggregator.cpp b/lib/livestatus/invavgaggregator.cpp new file mode 100644 index 0000000..33cf85c --- /dev/null +++ b/lib/livestatus/invavgaggregator.cpp @@ -0,0 +1,38 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "livestatus/invavgaggregator.hpp" + +using namespace icinga; + +InvAvgAggregator::InvAvgAggregator(String attr) + : m_InvAvgAttr(std::move(attr)) +{ } + +InvAvgAggregatorState *InvAvgAggregator::EnsureState(AggregatorState **state) +{ + if (!*state) + *state = new InvAvgAggregatorState(); + + return static_cast(*state); +} + +void InvAvgAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state) +{ + Column column = table->GetColumn(m_InvAvgAttr); + + Value value = column.ExtractValue(row); + + InvAvgAggregatorState *pstate = EnsureState(state); + + pstate->InvAvg += (1.0 / value); + pstate->InvAvgCount++; +} + +double InvAvgAggregator::GetResultAndFreeState(AggregatorState *state) const +{ + InvAvgAggregatorState *pstate = EnsureState(&state); + double result = pstate->InvAvg / pstate->InvAvgCount; + delete pstate; + + return result; +} -- cgit v1.2.3