rdbstats  2.0.9
RdbStats.h
1 #ifndef RdbStats_H
2 #define RdbStats_H
3 
4 /* --8<--8<--8<--8<--
5  *
6  * Copyright (C) 2006 Smithsonian Astrophysical Observatory
7  *
8  * This file is part of rdbstats
9  *
10  * rdbstats is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * rdbstats is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the
22  * Free Software Foundation, Inc.
23  * 51 Franklin Street, Fifth Floor
24  * Boston, MA 02110-1301, USA
25  *
26  * -->8-->8-->8-->8-- */
27 
28 #include <rdbxx/RDB.h>
29 #include <cmath> // sqrt fabs
30 
31 #include <string>
32 
33 enum struct Normalize { Average, Median, None };
34 enum struct OverrideType { Toggle, String, Number };
35 
36 struct DefOverride {
37  std::string colname;
38  OverrideType type;
39 
40  DefOverride( const std::string& colname_, OverrideType type_ ) : colname(colname_), type(type_) {}
41 
42 };
43 
44 using DefOverrideList = std::vector<DefOverride>;
45 
46 struct Percentile {
47  std::string colname;
48  double percentile;
49 
50  Percentile( const std::string& colname_, double percentile_ ) : colname(colname_), percentile(percentile_) {}
51 
52 };
53 using PercentileList = std::vector<Percentile>;
54 
55 
61 class RdbStats {
62 
63 public:
64 
65  virtual ~RdbStats( );
66 
67  RdbStats( RDB& irdbtable, const std::string& name );
68 
70  virtual int calculate_statistics( );
71 
73  double get_absolute_average( ) const { return fabs( the_statistics[AVG] ); }
74 
75  virtual void init( );
76 
77  virtual void normalize_results( const double norm );
78 
79  virtual void set_output_columns( RDB& ordbtable );
81  virtual void update_statistics( );
82 
83 private:
84 
85  // input_column is the input rdb column ptr. It is
86  // allocated by the library so do not free the memory.
87  RDBColumn* input_column;
88 
89  // The pointer to the output rdb columns.
90  std::vector<RDBColumn*> output_stats;
91 
92 protected:
93 
94  enum Stats { AVG, MAX, MIN, SD, SUM, SUM2, SUM_T };
95 
96  double num_n;
97 
98  std::string colname;
99 
100  double the_statistics[ 7 ];
101 
102  double get_value( );
103 
104 };
105 
106 
107 std::string to_string( std::string ); // this is so ugly
108 std::string to_string( Normalize );
109 std::string to_string( OverrideType );
110 std::string to_string( Percentile );
111 std::string to_string( DefOverride );
112 
113 #include <sstream>
114 template<typename T>
115 std::string to_string( std::vector<T> values ) {
116 
117  using namespace std;
118  std::stringstream os;
119 
120  bool first_elem = true;
121  for ( const auto& value : values ) {
122  if ( ! first_elem )
123  os << ", ";
124  else
125  first_elem = false;
126  os << to_string(value);
127  }
128 
129  return os.str();
130 }
131 
132 #endif
The base class to calculate : average, maximum, minimum, num, stddev and sum.
Definition: RdbStats.h:61
double get_absolute_average() const
To get the absolute value of the average.
Definition: RdbStats.h:73
virtual void update_statistics()
Read the column from RDB++, update the statistics for the column.
Definition: RdbStats.cc:129
virtual int calculate_statistics()
Perform the final statistic for the set.
Definition: RdbStats.cc:49