29 RdbStats::~RdbStats( ) {
43 RdbStats::RdbStats( RDB& irdbtable,
const std::string& name )
44 : input_column( NULL ), output_stats( ), num_n( 0 ), column_name( name ) {
46 input_column = (RDBColumn*) irdbtable.getColumn( name );
55 the_statistics[ SD ] = 0.0;
57 the_statistics[ SD ] = sqrt( the_statistics[ SUM_T ] / ( num_n - 1 ) );
59 the_statistics[ SUM2 ] = sqrt( the_statistics[ SUM2 ] );
65 double RdbStats::get_value( ) {
66 return input_column->getDataDouble( );
69 #define ARRAY_SIZE(arr)(sizeof(arr)/sizeof((arr)[0])) 71 void RdbStats::init( ) {
75 for (
int ii = 0; ii < ARRAY_SIZE( the_statistics ); ii++ )
76 the_statistics[ ii ] = 0.0;
78 the_statistics[ MAX ] = -DBL_MAX;
79 the_statistics[ MIN ] = DBL_MAX;
87 void RdbStats::normalize_results(
const double norm ) {
89 the_statistics[ SD ] /= norm;
90 the_statistics[ MIN ] /= norm;
91 the_statistics[ MAX ] /= norm;
92 the_statistics[ SUM2 ] /= norm;
96 void RdbStats::set_output_columns( RDB& ordbtable ) {
98 static const char* suffix[] = {
"_n",
"_ave",
"_max",
"_min",
"_dev",
99 "_sum",
"_rss", NULL };
101 const char* column_name_ptr = column_name.c_str( );
104 while ( suffix[ counter ] )
107 output_stats.reserve( counter + 1 );
110 sprintf( str,
"%s%s", column_name_ptr, suffix[ 0 ] );
111 ordbtable.setColumn( str,
"N" );
112 output_stats[ 0 ] = ordbtable.getColumn( ordbtable.nColumns( ) - 1 );
113 output_stats[ 0 ]->mapData( &num_n, 1 );
114 for (
int ii = 1; ii < counter ; ii++ ) {
118 sprintf( str,
"%s%s", column_name_ptr, suffix[ ii ] );
119 ordbtable.setColumn( str,
"N" );
120 output_stats[ ii_1 ] = ordbtable.getColumn( ordbtable.nColumns( ) - 1 ) ;
121 output_stats[ ii_1 ]->mapData( the_statistics + ii_1, 1 );
124 output_stats[ ii ] = NULL;
131 double val = get_value( );
141 the_statistics[ AVG ] = val;
149 double tmp = ( val - the_statistics[ AVG ] );
150 the_statistics[ SUM_T ] += tmp * tmp * ( num_n - 1 ) / num_n;
151 the_statistics[ AVG ] += tmp / num_n;
155 the_statistics[ SUM2 ] += val * val;
156 the_statistics[ SUM ] += val;
157 the_statistics[ MAX ] = std::max( the_statistics[ MAX ], val );
158 the_statistics[ MIN ] = std::min( the_statistics[ MIN ], val );
virtual void update_statistics()
Read the column from RDB++, update the statistics for the column.
virtual int calculate_statistics()
Perform the final statistic for the set.