QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
54
55 virtual ~QgsStatisticalSummary() = default;
56
62 Qgis::Statistics statistics() const { return mStatistics; }
63
70 void setStatistics( Qgis::Statistics stats );
71
75 void reset();
76
81 void calculate( const QList<double> &values );
82
97 void addValue( double value );
98
113 void addVariant( const QVariant &value );
114
121 void finalize();
122
129 double statistic( Qgis::Statistic stat ) const;
130
134 int count() const { return mCount; }
135
139 int countMissing() const { return mMissing; }
140
144 double sum() const { return mSum; }
145
150 double mean() const { return mMean; }
151
157 double median() const { return mMedian; }
158
163 double min() const { return mMin; }
164
169 double max() const { return mMax; }
170
175 double range() const { return std::isnan( mMax ) || std::isnan( mMin ) ? std::numeric_limits<double>::quiet_NaN() : mMax - mMin; }
176
183 double first() const { return mFirst; }
184
191 double last() const { return mLast; }
192
199 double stDev() const { return mStdev; }
200
207 double sampleStDev() const { return mSampleStdev; }
208
214 int variety() const { return mValueCount.count(); }
215
223 double minority() const { return mMinority; }
224
232 double majority() const { return mMajority; }
233
241 double firstQuartile() const { return mFirstQuartile; }
242
250 double thirdQuartile() const { return mThirdQuartile; }
251
259 double interQuartileRange() const { return std::isnan( mThirdQuartile ) || std::isnan( mFirstQuartile ) ? std::numeric_limits<double>::quiet_NaN() : mThirdQuartile - mFirstQuartile; }
260
265 static QString displayName( Qgis::Statistic statistic );
266
272 static QString shortName( Qgis::Statistic statistic );
273
274 private:
275 Qgis::Statistics mStatistics;
276
277 int mCount;
278 int mMissing;
279 double mSum;
280 double mMean;
281 double mMedian;
282 double mMin;
283 double mMax;
284 double mStdev;
285 double mSampleStdev;
286 double mMinority;
287 double mMajority;
288 double mFirstQuartile;
289 double mThirdQuartile;
290 double mFirst;
291 double mLast;
292 QMap< double, int > mValueCount;
293 QList< double > mValues;
294 bool mRequiresAllValueStorage = false;
295 bool mRequiresHisto = false;
296};
297
298#endif // QGSSTATISTICALSUMMARY_H
Statistic
Available generic statistics.
Definition qgis.h:6206
@ All
All statistics.
Definition qgis.h:6225
QFlags< Statistic > Statistics
Statistics to be calculated for generic values.
Definition qgis.h:6234
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.