29 RdbStats::~RdbStats( ) {
43 RdbStats::RdbStats( RDB& irdbtable,
const std::string& name )
44 : input_column( NULL ), output_stats( ), num_n( 0 ), colname( 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* colname_ptr = colname.c_str( );
104 while ( suffix[ counter ] )
107 output_stats.reserve( counter + 1 );
110 sprintf( str,
"%s%s", colname_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", colname_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 );
163 std::string to_string( Normalize normalize ) {
165 normalize == Normalize::Average ?
"average" 166 : normalize == Normalize::Median ?
"median" 167 : normalize == Normalize::None ?
"none" 171 std::string to_string( OverrideType override_defn ) {
173 override_defn == OverrideType::Toggle ?
"toggle" 174 : override_defn == OverrideType::String ?
"string" 175 : override_defn == OverrideType::Number ?
"number" 179 std::string to_string( Percentile p) {
180 return std::to_string( p.percentile ) +
'(' + p.colname +
')';
183 std::string to_string( DefOverride d) {
184 return d.colname +
'(' + to_string( d.type ) +
')';
187 std::string to_string( std::string str ) {
return str ; }
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.