]> granicus.if.org Git - icinga2/blob - lib/livestatus/minaggregator.cpp
Docs: Explain across midnight time periods with an overlapping range
[icinga2] / lib / livestatus / minaggregator.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "livestatus/minaggregator.hpp"
4
5 using namespace icinga;
6
7 MinAggregator::MinAggregator(String attr)
8         : m_MinAttr(std::move(attr))
9 { }
10
11 MinAggregatorState *MinAggregator::EnsureState(AggregatorState **state)
12 {
13         if (!*state)
14                 *state = new MinAggregatorState();
15
16         return static_cast<MinAggregatorState *>(*state);
17 }
18
19 void MinAggregator::Apply(const Table::Ptr& table, const Value& row, AggregatorState **state)
20 {
21         Column column = table->GetColumn(m_MinAttr);
22
23         Value value = column.ExtractValue(row);
24
25         MinAggregatorState *pstate = EnsureState(state);
26
27         if (value < pstate->Min)
28                 pstate->Min = value;
29 }
30
31 double MinAggregator::GetResultAndFreeState(AggregatorState *state) const
32 {
33         MinAggregatorState *pstate = EnsureState(&state);
34
35         double result;
36
37         if (pstate->Min == DBL_MAX)
38                 result = 0;
39         else
40                 result = pstate->Min;
41
42         delete pstate;
43
44         return result;
45 }