Evoplex  0.2.1
stats.h
1 /* Evoplex <https://evoplex.org>
2  * Copyright (C) 2016-present - Marcos Cardinot <marcos@cardinot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef STATS_H
18 #define STATS_H
19 
20 #include <vector>
21 
22 #include "attributes.h"
23 
24 namespace evoplex {
25 
29 class Stats
30 {
31 public:
41  template<typename ConstIterator>
42  static std::vector<Value> count(ConstIterator entityBegin, ConstIterator entityEnd,
43  const int attrIdx, std::vector<Value> header)
44  {
45  std::vector<Value> ret(header.size(), 0);
46  while (entityBegin != entityEnd) {
47  const size_t i = std::find(header.begin(), header.end(), entityBegin->second.attr(attrIdx)) - header.begin();
48  if (i != header.size()) {
49  ret[i] = ret[i].toInt() + 1;
50  }
51  ++entityBegin;
52  }
53  return ret;
54  }
55 
57  template<typename Container>
58  static std::vector<Value> count(Container entity, const int attrIdx, std::vector<Value> values)
59  {
60  return count(entity.cbegin(), entity.cend(), attrIdx, values);
61  }
62 };
63 
64 }
65 #endif // STATS_H
static std::vector< Value > count(ConstIterator entityBegin, ConstIterator entityEnd, const int attrIdx, std::vector< Value > header)
Count frequency of the header values in the container.
Definition: stats.h:42
The Stats class.
Definition: stats.h:29
static std::vector< Value > count(Container entity, const int attrIdx, std::vector< Value > values)
Count frequency of the header values in the container.
Definition: stats.h:58
Definition: abstractgraph.h:29