|
| 1 | +/** \ingroup core |
| 2 | + * \class QgsStatisticalSummary |
| 3 | + * \brief Calculator for summary statistics for a list of doubles. |
| 4 | + * |
| 5 | + * Statistics are calculated by calling @link calculate @endlink and passing a list of doubles. The |
| 6 | + * individual statistics can then be retrieved using the associated methods. Note that not all statistics |
| 7 | + * are calculated by default. Statistics which require slower computations are only calculated by |
| 8 | + * specifying the statistic in the constructor or via @link setStatistics @endlink. |
| 9 | + * |
| 10 | + * \note Added in version 2.9 |
| 11 | + */ |
| 12 | + |
| 13 | +class QgsStatisticalSummary |
| 14 | +{ |
| 15 | +%TypeHeaderCode |
| 16 | +#include <qgsstatisticalsummary.h> |
| 17 | +%End |
| 18 | + |
| 19 | + public: |
| 20 | + |
| 21 | + //! Enumeration of flags that specify statistics to be calculated |
| 22 | + enum Statistic |
| 23 | + { |
| 24 | + Count, //!< Count |
| 25 | + Sum, //!< Sum of values |
| 26 | + Mean, //!< Mean of values |
| 27 | + Median, //!< Median of values |
| 28 | + StDev, //!< Standard deviation of values |
| 29 | + StDevSample, //!< Sample standard deviation of values |
| 30 | + Min, //!< Min of values |
| 31 | + Max, //!< Max of values |
| 32 | + Range, //!< Range of values (max - min) |
| 33 | + Minority, //!< Minority of values |
| 34 | + Majority, //!< Majority of values |
| 35 | + Variety, //!< Variety (count of distinct) values |
| 36 | + FirstQuartile, //!< First quartile |
| 37 | + ThirdQuartile, //!< Third quartile |
| 38 | + InterQuartileRange, //!< Inter quartile range (IQR) |
| 39 | + All |
| 40 | + }; |
| 41 | + typedef QFlags<QgsStatisticalSummary::Statistic> Statistics; |
| 42 | + |
| 43 | + /** Constructor for QgsStatisticalSummary |
| 44 | + * @param stats flags for statistics to calculate |
| 45 | + */ |
| 46 | + QgsStatisticalSummary( QgsStatisticalSummary::Statistics stats = QgsStatisticalSummary::Statistics( 0 ) ); |
| 47 | + |
| 48 | + virtual ~QgsStatisticalSummary(); |
| 49 | + |
| 50 | + /** Returns flags which specify which statistics will be calculated. Some statistics |
| 51 | + * are always calculated (eg sum, min and max). |
| 52 | + * @see setStatistics |
| 53 | + */ |
| 54 | + QgsStatisticalSummary::Statistics statistics() const; |
| 55 | + |
| 56 | + /** Sets flags which specify which statistics will be calculated. Some statistics |
| 57 | + * are always calculated (eg sum, min and max). |
| 58 | + * @param stats flags for statistics to calculate |
| 59 | + * @see statistics |
| 60 | + */ |
| 61 | + void setStatistics( QgsStatisticalSummary::Statistics stats ); |
| 62 | + |
| 63 | + /** Resets the calculated values |
| 64 | + */ |
| 65 | + void reset(); |
| 66 | + |
| 67 | + /** Calculates summary statistics for a list of values |
| 68 | + * @param values list of doubles |
| 69 | + */ |
| 70 | + void calculate( const QList<double>& values ); |
| 71 | + |
| 72 | + /** Returns calculated count of values |
| 73 | + */ |
| 74 | + int count() const; |
| 75 | + |
| 76 | + /** Returns calculated sum of values |
| 77 | + */ |
| 78 | + double sum() const; |
| 79 | + |
| 80 | + /** Returns calculated mean of values |
| 81 | + */ |
| 82 | + double mean() const; |
| 83 | + |
| 84 | + /** Returns calculated median of values. This is only calculated if Statistic::Median has |
| 85 | + * been specified in the constructor or via setStatistics. |
| 86 | + */ |
| 87 | + double median() const; |
| 88 | + |
| 89 | + /** Returns calculated minimum from values. |
| 90 | + */ |
| 91 | + double min() const; |
| 92 | + |
| 93 | + /** Returns calculated maximum from values. |
| 94 | + */ |
| 95 | + double max() const; |
| 96 | + |
| 97 | + /** Returns calculated range (difference between maximum and minimum values). |
| 98 | + */ |
| 99 | + double range() const; |
| 100 | + |
| 101 | + /** Returns population standard deviation. This is only calculated if Statistic::StDev has |
| 102 | + * been specified in the constructor or via setStatistics. |
| 103 | + * @see sampleStDev |
| 104 | + */ |
| 105 | + double stDev() const; |
| 106 | + |
| 107 | + /** Returns sample standard deviation. This is only calculated if Statistic::StDev has |
| 108 | + * been specified in the constructor or via setStatistics. |
| 109 | + * @see stDev |
| 110 | + */ |
| 111 | + double sampleStDev() const; |
| 112 | + |
| 113 | + /** Returns variety of values. The variety is the count of unique values from the list. |
| 114 | + * This is only calculated if Statistic::Variety has been specified in the constructor |
| 115 | + * or via setStatistics. |
| 116 | + */ |
| 117 | + int variety() const; |
| 118 | + |
| 119 | + /** Returns minority of values. The minority is the value with least occurances in the list |
| 120 | + * This is only calculated if Statistic::Minority has been specified in the constructor |
| 121 | + * or via setStatistics. |
| 122 | + * @see majority |
| 123 | + */ |
| 124 | + double minority() const; |
| 125 | + |
| 126 | + /** Returns majority of values. The majority is the value with most occurances in the list |
| 127 | + * This is only calculated if Statistic::Majority has been specified in the constructor |
| 128 | + * or via setStatistics. |
| 129 | + * @see minority |
| 130 | + */ |
| 131 | + double majority() const; |
| 132 | + |
| 133 | + /** Returns the first quartile of the values. The quartile is calculated using the |
| 134 | + * "Tukey's hinges" method. |
| 135 | + * @see thirdQuartile |
| 136 | + * @see interQuartileRange |
| 137 | + */ |
| 138 | + double firstQuartile() const; |
| 139 | + |
| 140 | + /** Returns the third quartile of the values. The quartile is calculated using the |
| 141 | + * "Tukey's hinges" method. |
| 142 | + * @see firstQuartile |
| 143 | + * @see interQuartileRange |
| 144 | + */ |
| 145 | + double thirdQuartile() const; |
| 146 | + |
| 147 | + /** Returns the inter quartile range of the values. The quartiles are calculated using the |
| 148 | + * "Tukey's hinges" method. |
| 149 | + * @see firstQuartile |
| 150 | + * @see thirdQuartile |
| 151 | + */ |
| 152 | + double interQuartileRange() const; |
| 153 | + |
| 154 | +}; |
| 155 | + |
| 156 | +QFlags<QgsStatisticalSummary::Statistic> operator|(QgsStatisticalSummary::Statistic f1, QFlags<QgsStatisticalSummary::Statistic> f2); |
| 157 | + |
0 commit comments