QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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 <cmath>
20
21#include "qgis.h"
22#include "qgis_core.h"
23#include "qgis_sip.h"
24
25#include <QMap>
26#include <QVariant>
27
28/***************************************************************************
29 * This class is considered CRITICAL and any change MUST be accompanied with
30 * full unit tests in testqgsstatisticalsummary.cpp.
31 * See details in QEP #17
32 ****************************************************************************/
33
45
46class CORE_EXPORT QgsStatisticalSummary
47{
48 public:
49
55
56 virtual ~QgsStatisticalSummary() = default;
57
63 Qgis::Statistics statistics() const { return mStatistics; }
64
71 void setStatistics( Qgis::Statistics stats );
72
76 void reset();
77
82 void calculate( const QList<double> &values );
83
98 void addValue( double value );
99
114 void addVariant( const QVariant &value );
115
122 void finalize();
123
130 double statistic( Qgis::Statistic stat ) const;
131
135 int count() const { return mCount; }
136
140 int countMissing() const { return mMissing; }
141
145 double sum() const { return mSum; }
146
151 double mean() const { return mMean; }
152
158 double median() const { return mMedian; }
159
164 double min() const { return mMin; }
165
170 double max() const { return mMax; }
171
176 double range() const { return std::isnan( mMax ) || std::isnan( mMin ) ? std::numeric_limits<double>::quiet_NaN() : mMax - mMin; }
177
184 double first() const { return mFirst; }
185
192 double last() const { return mLast; }
193
200 double stDev() const { return mStdev; }
201
208 double sampleStDev() const { return mSampleStdev; }
209
215 int variety() const { return mValueCount.count(); }
216
224 double minority() const { return mMinority; }
225
233 double majority() const { return mMajority; }
234
242 double firstQuartile() const { return mFirstQuartile; }
243
251 double thirdQuartile() const { return mThirdQuartile; }
252
260 double interQuartileRange() const { return std::isnan( mThirdQuartile ) || std::isnan( mFirstQuartile ) ? std::numeric_limits<double>::quiet_NaN() : mThirdQuartile - mFirstQuartile; }
261
266 static QString displayName( Qgis::Statistic statistic );
267
273 static QString shortName( Qgis::Statistic statistic );
274
275 private:
276
277 Qgis::Statistics mStatistics;
278
279 int mCount;
280 int mMissing;
281 double mSum;
282 double mMean;
283 double mMedian;
284 double mMin;
285 double mMax;
286 double mStdev;
287 double mSampleStdev;
288 double mMinority;
289 double mMajority;
290 double mFirstQuartile;
291 double mThirdQuartile;
292 double mFirst;
293 double mLast;
294 QMap< double, int > mValueCount;
295 QList< double > mValues;
296 bool mRequiresAllValueStorage = false;
297 bool mRequiresHisto = false;
298};
299
300#endif // QGSSTATISTICALSUMMARY_H
Statistic
Available generic statistics.
Definition qgis.h:5848
@ All
All statistics.
Definition qgis.h:5867
QFlags< Statistic > Statistics
Statistics to be calculated for generic values.
Definition qgis.h:5876
double firstQuartile() const
Returns the first quartile of the values.
double sum() const
Returns calculated sum of values.
double mean() const
Returns calculated mean of values.
double last() const
Returns the last value obtained.
double majority() const
Returns majority of values.
int countMissing() const
Returns the number of missing (null) values.
double interQuartileRange() const
Returns the inter quartile range of the values.
double median() const
Returns calculated median of values.
double minority() const
Returns minority of values.
QgsStatisticalSummary(Qgis::Statistics stats=Qgis::Statistic::All)
Constructor for QgsStatisticalSummary.
double sampleStDev() const
Returns sample standard deviation.
double min() const
Returns calculated minimum from values.
virtual ~QgsStatisticalSummary()=default
double first() const
Returns the first value obtained.
Qgis::Statistics statistics() const
Returns flags which specify which statistics will be calculated.
double stDev() const
Returns population standard deviation.
double thirdQuartile() const
Returns the third quartile of the values.
int count() const
Returns calculated count of values.
double range() const
Returns calculated range (difference between maximum and minimum values).
double max() const
Returns calculated maximum from values.
int variety() const
Returns variety of values.