5 #ifndef JODA_NUMBERAGGREGATOR_H
6 #define JODA_NUMBERAGGREGATOR_H
10 #include <unordered_map>
16 static constexpr
auto name =
"EXAMPLE";
36 std::vector<std::unique_ptr<IValueProvider>> &&
params)
43 if (this->
params.size() == 1) {
45 }
else if (this->
params.size() == 2) {
47 if (!this->
params[1]->isConst())
55 auto type = this->
params[0]->getReturnType();
64 assert(
getName() == o->getName());
66 if (o->isAggregated) {
68 T::aggregateRep(this->
val, o->val);
79 val.SetDouble(T::getDouble(this->val));
84 std::unique_ptr<IAggregator>
duplicate()
const override {
85 return std::make_unique<NumberAggregator<T>>(
toPointer,
94 val_ =
params[0]->getAtomValue(json, alloc);
97 rjVal =
params[0]->getValue(json, alloc);
99 if (rjVal !=
nullptr) {
100 if (rjVal->IsNumber()) {
102 T::aggregate(this->
val, rjVal->GetDouble());
105 T::aggregateFirst(this->
val, rjVal->GetDouble());
110 for (
const auto &item : rjVal->GetArray()) {
111 if (item.IsNumber()) {
113 T::aggregate(this->
val, rjVal->GetDouble());
116 T::aggregateFirst(this->
val, rjVal->GetDouble());
124 static constexpr
auto getName_() {
return T::name; }
139 static constexpr
auto name =
"MIN";
144 old = std::min(old, val);
148 old = std::min(old, val);
158 static constexpr
auto name =
"MAX";
162 old = std::max(old, val);
166 old = std::max(old, val);
176 static constexpr
auto name =
"SUM";
189 typedef std::pair<size_t, double>
AggRep;
190 static constexpr
auto name =
"AVG";
196 old.first += val.first;
197 old.second += val.second;
206 return val.second / val.first;
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
Definition: IAggregator.h:25
void checkParamType(unsigned int i, IValueType expected)
Definition: IAggregator.h:139
std::vector< std::unique_ptr< IValueProvider > > params
Definition: IAggregator.h:124
std::vector< std::unique_ptr< IValueProvider > > duplicateParameters() const
Definition: IAggregator.h:154
std::string toPointer
Definition: IAggregator.h:120
Definition: NumberAggregator.h:33
void accumulate(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) override
Definition: NumberAggregator.h:89
static constexpr auto getName_()
Definition: NumberAggregator.h:124
std::unique_ptr< IAggregator > duplicate() const override
Definition: NumberAggregator.h:84
RJValue terminate(RJMemoryPoolAlloc &alloc) override
Definition: NumberAggregator.h:76
T::AggRep val
Definition: NumberAggregator.h:129
const std::string getName() const override
Definition: NumberAggregator.h:126
void merge(IAggregator *other) override
Definition: NumberAggregator.h:61
bool enableArray
Definition: NumberAggregator.h:131
bool isAggregated
Definition: NumberAggregator.h:130
NumberAggregator(const std::string &toPointer, std::vector< std::unique_ptr< IValueProvider >> &¶ms)
Definition: NumberAggregator.h:35
Definition: IValueProvider.h:96
Definition: IValueProvider.h:46
Definition: IValueProvider.h:60
Definition: AttributeStatAggregator.h:12
NumberAggregator< AverageAggregatorFunc > AverageAggregator
Definition: NumberAggregator.h:210
NumberAggregator< MaxAggregatorFunc > MaxAggregator
Definition: NumberAggregator.h:172
NumberAggregator< MinAggregatorFunc > MinAggregator
Definition: NumberAggregator.h:154
NumberAggregator< SumAggregatorFunc > SumAggregator
Definition: NumberAggregator.h:186
@ IV_Number
Definition: IValueProvider.h:35
@ IV_Bool
Definition: IValueProvider.h:36
@ IV_Any
Definition: IValueProvider.h:39
@ IV_Array
Definition: IValueProvider.h:38
Definition: NumberAggregator.h:188
static double getDouble(AggRep &val)
Definition: NumberAggregator.h:205
static void aggregateRep(AggRep &old, AggRep &val)
Definition: NumberAggregator.h:195
std::pair< size_t, double > AggRep
Definition: NumberAggregator.h:189
static void aggregate(AggRep &old, double val)
Definition: NumberAggregator.h:200
static void aggregateFirst(AggRep &old, double val)
Definition: NumberAggregator.h:191
static constexpr auto name
Definition: NumberAggregator.h:190
Definition: NumberAggregator.h:14
static constexpr auto name
Definition: NumberAggregator.h:16
static void aggregateFirst(AggRep &old, double val)
Definition: NumberAggregator.h:18
static void aggregateRep(AggRep &old, AggRep &val)
Definition: NumberAggregator.h:20
static double getDouble(AggRep &val)
Definition: NumberAggregator.h:24
double AggRep
Definition: NumberAggregator.h:15
static void aggregate(AggRep &old, double val)
Definition: NumberAggregator.h:22
Definition: NumberAggregator.h:156
double AggRep
Definition: NumberAggregator.h:157
static void aggregate(AggRep &old, double val)
Definition: NumberAggregator.h:165
static void aggregateRep(AggRep &old, AggRep &val)
Definition: NumberAggregator.h:161
static void aggregateFirst(AggRep &old, double val)
Definition: NumberAggregator.h:159
static double getDouble(AggRep &val)
Definition: NumberAggregator.h:169
static constexpr auto name
Definition: NumberAggregator.h:158
Definition: NumberAggregator.h:137
static void aggregateRep(AggRep &old, AggRep &val)
Definition: NumberAggregator.h:143
static void aggregate(AggRep &old, double val)
Definition: NumberAggregator.h:147
double AggRep
Definition: NumberAggregator.h:138
static double getDouble(AggRep &val)
Definition: NumberAggregator.h:151
static constexpr auto name
Definition: NumberAggregator.h:139
static void aggregateFirst(AggRep &old, double val)
Definition: NumberAggregator.h:141
Definition: NumberAggregator.h:174
static double getDouble(AggRep &val)
Definition: NumberAggregator.h:183
double AggRep
Definition: NumberAggregator.h:175
static constexpr auto name
Definition: NumberAggregator.h:176
static void aggregateFirst(AggRep &old, double val)
Definition: NumberAggregator.h:177
static void aggregate(AggRep &old, double val)
Definition: NumberAggregator.h:181
static void aggregateRep(AggRep &old, AggRep &val)
Definition: NumberAggregator.h:179