QGIS API Documentation  2.12.0-Lyon
qgsstatisticalsummary.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstatisticalsummary.h
3  --------------------------------------
4  Date : May 2015
5  Copyright : (C) 2015 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSSTATISTICALSUMMARY_H
17 #define QGSSTATISTICALSUMMARY_H
18 
19 #include <QMap>
20 
33 class CORE_EXPORT QgsStatisticalSummary
34 {
35  public:
36 
38  enum Statistic
39  {
40  Count = 1,
41  Sum = 2,
42  Mean = 4,
43  Median = 8,
44  StDev = 16,
45  StDevSample = 32,
46  Min = 64,
47  Max = 128,
48  Range = 256,
49  Minority = 512,
50  Majority = 1024,
51  Variety = 2048,
52  FirstQuartile = 4096,
53  ThirdQuartile = 8192,
54  InterQuartileRange = 16384,
55  All = Count | Sum | Mean | Median | StDev | Max | Min | Range | Minority | Majority | Variety | FirstQuartile | ThirdQuartile | InterQuartileRange
56  };
57  Q_DECLARE_FLAGS( Statistics, Statistic )
58 
59 
62  QgsStatisticalSummary( const QgsStatisticalSummary::Statistics& stats = Statistics( 0 ) );
63 
64  virtual ~QgsStatisticalSummary();
65 
70  Statistics statistics() const { return mStatistics; }
71 
77  void setStatistics( const Statistics& stats ) { mStatistics = stats; }
78 
81  void reset();
82 
86  void calculate( const QList<double>& values );
87 
92  double statistic( Statistic stat ) const;
93 
96  int count() const { return mCount; }
97 
100  double sum() const { return mSum; }
101 
104  double mean() const { return mMean; }
105 
109  double median() const { return mMedian; }
110 
113  double min() const { return mMin; }
114 
117  double max() const { return mMax; }
118 
121  double range() const { return mMax - mMin; }
122 
127  double stDev() const { return mStdev; }
128 
133  double sampleStDev() const { return mSampleStdev; }
134 
139  int variety() const { return mValueCount.count(); }
140 
146  double minority() const { return mMinority; }
147 
153  double majority() const { return mMajority; }
154 
160  double firstQuartile() const { return mFirstQuartile; }
161 
167  double thirdQuartile() const { return mThirdQuartile; }
168 
174  double interQuartileRange() const { return mThirdQuartile - mFirstQuartile; }
175 
179  static QString displayName( Statistic statistic );
180 
181  private:
182 
183  Statistics mStatistics;
184 
185  int mCount;
186  double mSum;
187  double mMean;
188  double mMedian;
189  double mMin;
190  double mMax;
191  double mStdev;
192  double mSampleStdev;
193  double mMinority;
194  double mMajority;
195  double mFirstQuartile;
196  double mThirdQuartile;
197  QMap< double, int > mValueCount;
198 };
199 
200 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsStatisticalSummary::Statistics )
201 
202 #endif // QGSSTATISTICALSUMMARY_H
Statistic
Enumeration of flags that specify statistics to be calculated.
double min() const
Returns calculated minimum from values.
int variety() const
Returns variety of values.
double mean() const
Returns calculated mean of values.
void setStatistics(const Statistics &stats)
Sets flags which specify which statistics will be calculated.
double firstQuartile() const
Returns the first quartile of the values.
double range() const
Returns calculated range (difference between maximum and minimum values).
int count() const
Returns calculated count of values.
double minority() const
Returns minority of values.
double stDev() const
Returns population standard deviation.
double sampleStDev() const
Returns sample standard deviation.
double median() const
Returns calculated median of values.
double majority() const
Returns majority of values.
double sum() const
Returns calculated sum of values.
double thirdQuartile() const
Returns the third quartile of the values.
double max() const
Returns calculated maximum from values.
Calculator for summary statistics for a list of doubles.
double interQuartileRange() const
Returns the inter quartile range of the values.