RdbStatsPercentiles.h

00001 #ifndef RdbStatsPercentiles_H
00002 #define RdbStatsPercentiles_H
00003 
00004 /* --8<--8<--8<--8<--
00005  *
00006  * Copyright (C) 2006 Smithsonian Astrophysical Observatory
00007  *
00008  * This file is part of rdbstats
00009  *
00010  * rdbstats is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License
00012  * as published by the Free Software Foundation; either version 2
00013  * of the License, or (at your option) any later version.
00014  *
00015  * rdbstats is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the 
00022  *       Free Software Foundation, Inc. 
00023  *       51 Franklin Street, Fifth Floor
00024  *       Boston, MA  02110-1301, USA
00025  *
00026  * -->8-->8-->8-->8-- */
00027 
00028 #include <ostream>
00029 #include <vector>
00030 
00031 #include "RdbStats.h"
00032 
00033 using namespace std;
00034 
00039 class RdbStatsPercentiles : public RdbStats {
00040 
00041 public:
00042 
00043   ~RdbStatsPercentiles( ) throw( ) {
00044 
00045     delete [] the_percentile_result;
00046     the_percentile_result = NULL;
00047 
00048   }
00049 
00050   // The user has specified the percentile to use:
00052   RdbStatsPercentiles( RDB& irdbtable, const string& name,
00053                        const string& percent_list, bool implicitquartile )
00054     throw( Exception );
00055 
00056   // --quartiles
00057   RdbStatsPercentiles( RDB& irdbtable, const string& name ) throw( Exception );
00058 
00059   virtual int calculate_statistics( ) throw( );
00060 
00061   void init( ) throw( );
00062 
00063   virtual void normalize_results( const double norm ) throw( );
00064 
00065   void set_output_columns( RDB& ordbtable ) throw( Exception );
00066 
00067   virtual void update_statistics( ) throw( Exception );
00068 
00069 protected:
00070 
00071   vector< double > data;
00072 
00073   vector< pair< string, double > > the_percentile;
00074 
00075   double the_median;
00076 
00077   double* the_percentile_result;
00078 
00079 private:
00080 
00082   double calculate_median( ) throw( );
00083 
00085   double calculate_percentile( const double percentile ) throw( );
00086 
00087 };
00088 
00089 #endif