QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
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 <QMap>
20#include <QVariant>
21#include <cmath>
22#include "qgis_core.h"
23#include "qgis_sip.h"
24#include "qgis.h"
25
26/***************************************************************************
27 * This class is considered CRITICAL and any change MUST be accompanied with
28 * full unit tests in testqgsstatisticalsummary.cpp.
29 * See details in QEP #17
30 ****************************************************************************/
31
44class CORE_EXPORT QgsStatisticalSummary
45{
46 public:
47
53
54 virtual ~QgsStatisticalSummary() = default;
55
61 Qgis::Statistics statistics() const { return mStatistics; }
62
69 void setStatistics( Qgis::Statistics stats );
70
74 void reset();
75
80 void calculate( const QList<double> &values );
81
96 void addValue( double value );
97
112 void addVariant( const QVariant &value );
113
120 void finalize();
121
128 double statistic( Qgis::Statistic stat ) const;
129
133 int count() const { return mCount; }
134
138 int countMissing() const { return mMissing; }
139
143 double sum() const { return mSum; }
144
149 double mean() const { return mMean; }
150
156 double median() const { return mMedian; }
157
162 double min() const { return mMin; }
163
168 double max() const { return mMax; }
169
174 double range() const { return std::isnan( mMax ) || std::isnan( mMin ) ? std::numeric_limits<double>::quiet_NaN() : mMax - mMin; }
175
182 double first() const { return mFirst; }
183
190 double last() const { return mLast; }
191
198 double stDev() const { return mStdev; }
199
206 double sampleStDev() const { return mSampleStdev; }
207
213 int variety() const { return mValueCount.count(); }
214
222 double minority() const { return mMinority; }
223
231 double majority() const { return mMajority; }
232
240 double firstQuartile() const { return mFirstQuartile; }
241
249 double thirdQuartile() const { return mThirdQuartile; }
250
258 double interQuartileRange() const { return std::isnan( mThirdQuartile ) || std::isnan( mFirstQuartile ) ? std::numeric_limits<double>::quiet_NaN() : mThirdQuartile - mFirstQuartile; }
259
264 static QString displayName( Qgis::Statistic statistic );
265
271 static QString shortName( Qgis::Statistic statistic );
272
273 private:
274
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:5432
@ All
All statistics.
QFlags< Statistic > Statistics
Statistics to be calculated for generic values.
Definition qgis.h:5460
Calculator for summary statistics for a list of doubles.
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.
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.