rdbstats  2.0.7
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 
39 class RdbStats {
40 
41 public:
42 
43  virtual ~RdbStats( );
44 
45  RdbStats( RDB& irdbtable, const std::string& name );
46 
48  virtual int calculate_statistics( );
49 
51  double get_absolute_average( ) const { return fabs( the_statistics[AVG] ); }
52 
53  virtual void init( );
54 
55  virtual void normalize_results( const double norm );
56 
57  virtual void set_output_columns( RDB& ordbtable );
59  virtual void update_statistics( );
60 
61 private:
62 
63  // input_column is the input rdb column ptr. It is
64  // allocated by the library so do not free the memory.
65  RDBColumn* input_column;
66 
67  // The pointer to the output rdb columns.
68  std::vector<RDBColumn*> output_stats;
69 
70 protected:
71 
72  enum Stats { AVG, MAX, MIN, SD, SUM, SUM2, SUM_T };
73 
74  double num_n;
75 
76  std::string column_name;
77 
78  double the_statistics[ 7 ];
79 
80  double get_value( );
81 
82 };
83 
84 
85 #include <sstream>
86 template<typename T>
87 std::string to_string( std::vector<T> values ) {
88 
89  std::stringstream os;
90 
91  bool first_elem = true;
92  for ( const auto& value : values ) {
93  if ( ! first_elem )
94  os << ", ";
95  else
96  first_elem = false;
97  os << value;
98  }
99 
100  return os.str();
101 }
102 
103 #endif
The base class to calculate : average, maximum, minimum, num, stddev and sum.
Definition: RdbStats.h:39
double get_absolute_average() const
To get the absolute value of the average.
Definition: RdbStats.h:51
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