5 #ifndef JODA_ATTRIBUTESTATAGGREGATOR_H
6 #define JODA_ATTRIBUTESTATAGGREGATOR_H
17 std::vector<std::unique_ptr<IValueProvider>> &&
params);
20 std::unique_ptr<IAggregator>
duplicate()
const override;
23 const std::string
getName()
const override;
26 static constexpr
auto getName_() {
return "ATTSTAT"; }
33 if (this->parent !=
nullptr) {
34 DCHECK(!this->name.empty());
35 DCHECK(this->parent !=
this);
47 uint64_t
min_member = std::numeric_limits<uint64_t>::max();
50 uint64_t
min_size = std::numeric_limits<uint64_t>::max();
56 double max_double = std::numeric_limits<double>::lowest();
59 int64_t
max_int = std::numeric_limits<int64_t>::min();
60 int64_t
min_int = std::numeric_limits<int64_t>::max();
74 if (child.name ==
name) {
96 Node n(std::to_string(i),
this);
101 DCHECK(c !=
nullptr);
107 if (o ==
nullptr)
return;
128 for (
const auto &child : o->
children) {
132 for (
size_t i = 0; i < o->
arrMembers.size(); ++i) {
139 RJValue r(rapidjson::kObjectType);
141 r.AddMember(
"Key",
name, alloc);
143 r.AddMember(
"Count_Total",
getCount(), alloc);
144 r.AddMember(
"Count_Object",
count_obj, alloc);
145 if (
min_member < std::numeric_limits<uint64_t>::max()) {
149 r.AddMember(
"Count_Array",
count_arr, alloc);
150 if (
min_size < std::numeric_limits<uint64_t>::max()) {
151 r.AddMember(
"Min_Size",
min_size, alloc);
152 r.AddMember(
"Max_Size",
max_size, alloc);
155 r.AddMember(
"Count_Boolean",
count_bool, alloc);
158 r.AddMember(
"Count_String",
count_str, alloc);
159 if (
min_strsize < std::numeric_limits<uint64_t>::max()) {
163 r.AddMember(
"Count_Int",
count_int, alloc);
165 r.AddMember(
"Min_Int",
min_int, alloc);
166 r.AddMember(
"Max_Int",
max_int, alloc);
175 RJValue ch(rapidjson::kArrayType);
176 for (
const auto &child :
children) {
177 auto child_val = child.toValue(alloc);
178 ch.PushBack(child_val, alloc);
180 r.AddMember(
"Children", ch, alloc);
183 RJValue ch(rapidjson::kArrayType);
185 auto child_val = child.toValue(alloc);
186 ch.PushBack(child_val, alloc);
188 r.AddMember(
"Array_Items", ch, alloc);
205 DCHECK(currnode !=
nullptr);
206 currnode = currnode->
parent;
211 DCHECK(currnode !=
nullptr);
219 DCHECK(currnode !=
nullptr);
232 DCHECK(currnode !=
nullptr);
242 DCHECK(currnode !=
nullptr);
252 DCHECK(currnode !=
nullptr);
262 DCHECK(currnode !=
nullptr);
272 DCHECK(currnode !=
nullptr);
280 bool RawNumber(
const Ch *str, rapidjson::SizeType length,
bool copy) {
282 DCHECK(currnode !=
nullptr);
288 bool String(
const Ch *str, rapidjson::SizeType length,
bool copy) {
290 DCHECK(currnode !=
nullptr);
293 std::min(
static_cast<u_int64_t
>(length), currnode->
min_strsize);
295 std::max(
static_cast<u_int64_t
>(length), currnode->
max_strsize);
302 DCHECK(currnode !=
nullptr);
304 levels.emplace_back(
false);
308 bool Key(
const Ch *str, rapidjson::SizeType length,
bool copy) {
309 auto name = std::string(str, length);
310 DCHECK(!name.empty());
311 DCHECK(currnode !=
nullptr);
317 DCHECK(currnode !=
nullptr);
319 std::min(
static_cast<u_int64_t
>(memberCount), currnode->
min_member);
321 std::max(
static_cast<u_int64_t
>(memberCount), currnode->
max_member);
329 DCHECK(currnode !=
nullptr);
331 levels.emplace_back(
true);
336 DCHECK(currnode !=
nullptr);
338 std::min(
static_cast<u_int64_t
>(elementCount), currnode->
min_size);
340 std::max(
static_cast<u_int64_t
>(elementCount), currnode->
max_size);
347 root = {
"",
nullptr};
361 Level(
bool isArr) : isArr(isArr) {}
368 if (levels.empty())
return;
369 if (levels.back().isArr) {
370 DCHECK(currnode !=
nullptr);
371 currnode = currnode->
findArrElt(levels.back().count);
372 levels.back().count++;
376 Node root{
"",
nullptr};
377 Node *currnode =
nullptr;
378 std::vector<Level> levels{};
rapidjson::MemoryPoolAllocator< RJBaseAlloc > RJMemoryPoolAlloc
Definition: RJFwd.h:26
rapidjson::GenericValue< RJChar, RJMemoryPoolAlloc > RJValue
Definition: RJFwd.h:29
Definition: RapidJsonDocument.h:22
Definition: AttributeStatAggregator.h:29
void reset()
Definition: AttributeStatAggregator.h:346
void finishValue()
Definition: AttributeStatAggregator.h:204
bool Double(double d)
Definition: AttributeStatAggregator.h:270
bool Int64(int64_t i)
Definition: AttributeStatAggregator.h:250
bool StartObject()
Definition: AttributeStatAggregator.h:300
bool StartArray()
Definition: AttributeStatAggregator.h:327
bool Bool(bool b)
Definition: AttributeStatAggregator.h:217
bool String(const Ch *str, rapidjson::SizeType length, bool copy)
Definition: AttributeStatAggregator.h:288
Node finish()
Definition: AttributeStatAggregator.h:352
void merge(const Node &n)
Definition: AttributeStatAggregator.h:202
bool Uint(unsigned i)
Definition: AttributeStatAggregator.h:240
char Ch
Definition: AttributeStatAggregator.h:200
bool Null()
Definition: AttributeStatAggregator.h:209
bool Uint64(uint64_t i)
Definition: AttributeStatAggregator.h:260
bool EndArray(rapidjson::SizeType elementCount)
Definition: AttributeStatAggregator.h:335
bool Int(int i)
Definition: AttributeStatAggregator.h:230
bool Key(const Ch *str, rapidjson::SizeType length, bool copy)
Definition: AttributeStatAggregator.h:308
bool EndObject(rapidjson::SizeType memberCount)
Definition: AttributeStatAggregator.h:316
void finishDocument()
Definition: AttributeStatAggregator.h:354
AttStatHandler()
Definition: AttributeStatAggregator.h:198
bool RawNumber(const Ch *str, rapidjson::SizeType length, bool copy)
Definition: AttributeStatAggregator.h:280
Definition: AttributeStatAggregator.h:13
std::vector< std::string > getAttributes() const override
Definition: AttributeStatAggregator.cpp:46
RJValue terminate(RJMemoryPoolAlloc &alloc) override
Definition: AttributeStatAggregator.cpp:17
const std::string getName() const override
Definition: AttributeStatAggregator.cpp:42
void accumulate(const RapidJsonDocument &json, RJMemoryPoolAlloc &alloc) override
Definition: AttributeStatAggregator.cpp:36
AttStatHandler handler
Definition: AttributeStatAggregator.h:381
void merge(IAggregator *other) override
Definition: AttributeStatAggregator.cpp:9
static constexpr auto getName_()
Definition: AttributeStatAggregator.h:26
AttributeStatAggregator(const std::string &toPointer, std::vector< std::unique_ptr< IValueProvider >> &¶ms)
Definition: AttributeStatAggregator.cpp:28
std::unique_ptr< IAggregator > duplicate() const override
Definition: AttributeStatAggregator.cpp:23
Definition: IAggregator.h:25
std::vector< std::unique_ptr< IValueProvider > > params
Definition: IAggregator.h:124
std::string toPointer
Definition: IAggregator.h:120
Definition: AttributeStatAggregator.h:12
Definition: AttributeStatAggregator.h:31
size_t count_false
Definition: AttributeStatAggregator.h:63
uint64_t max_size
Definition: AttributeStatAggregator.h:49
Node & operator=(Node &&n)=default
uint64_t max_strsize
Definition: AttributeStatAggregator.h:53
size_t count_int
Definition: AttributeStatAggregator.h:58
size_t count_bool
Definition: AttributeStatAggregator.h:61
uint64_t min_size
Definition: AttributeStatAggregator.h:50
Node * findArrElt(size_t i)
Definition: AttributeStatAggregator.h:90
std::string name
Definition: AttributeStatAggregator.h:44
std::vector< Node > arrMembers
Definition: AttributeStatAggregator.h:194
void merge(const Node *o)
Definition: AttributeStatAggregator.h:106
Node(const std::string &name, Node *parent)
Definition: AttributeStatAggregator.h:32
size_t count_double
Definition: AttributeStatAggregator.h:55
Node & operator=(const Node &n)=delete
size_t count_null
Definition: AttributeStatAggregator.h:51
size_t count_str
Definition: AttributeStatAggregator.h:52
int64_t min_int
Definition: AttributeStatAggregator.h:60
double min_double
Definition: AttributeStatAggregator.h:57
Node * findChild(const std::string &name)
Definition: AttributeStatAggregator.h:70
uint64_t min_strsize
Definition: AttributeStatAggregator.h:54
uint64_t max_member
Definition: AttributeStatAggregator.h:46
double max_double
Definition: AttributeStatAggregator.h:56
uint64_t min_member
Definition: AttributeStatAggregator.h:47
Node * parent
Definition: AttributeStatAggregator.h:195
int64_t max_int
Definition: AttributeStatAggregator.h:59
size_t count_true
Definition: AttributeStatAggregator.h:62
size_t getCount() const
Definition: AttributeStatAggregator.h:65
std::vector< Node > children
Definition: AttributeStatAggregator.h:193
Node(const Node &n)=delete
size_t count_arr
Definition: AttributeStatAggregator.h:48
RJValue toValue(RJMemoryPoolAlloc &alloc) const
Definition: AttributeStatAggregator.h:138
size_t count_obj
Definition: AttributeStatAggregator.h:45