28 : mStatistics( stats )
46 mMin = std::numeric_limits<double>::max();
47 mMax = -std::numeric_limits<double>::max();
74 Q_FOREACH (
double value, values )
86 mMin = std::min( mMin, value );
87 mMax = std::max( mMax, value );
90 mValueCount.insert( value, mValueCount.value( value, 0 ) + 1 );
92 if ( mRequiresAllValueStorage )
98 bool convertOk =
false;
99 if ( !value.isValid() || value.isNull() )
103 double val = value.toDouble( &convertOk );
115 mMin = std::numeric_limits<double>::quiet_NaN();
116 mMax = std::numeric_limits<double>::quiet_NaN();
117 mMean = std::numeric_limits<double>::quiet_NaN();
118 mMedian = std::numeric_limits<double>::quiet_NaN();
119 mStdev = std::numeric_limits<double>::quiet_NaN();
120 mSampleStdev = std::numeric_limits<double>::quiet_NaN();
121 mMinority = std::numeric_limits<double>::quiet_NaN();
122 mMajority = std::numeric_limits<double>::quiet_NaN();
123 mFirstQuartile = std::numeric_limits<double>::quiet_NaN();
124 mThirdQuartile = std::numeric_limits<double>::quiet_NaN();
128 mMean = mSum / mCount;
132 double sumSquared = 0;
133 Q_FOREACH (
double value, mValues )
135 double diff = value - mMean;
136 sumSquared += diff * diff;
138 mStdev = std::pow( sumSquared / mValues.count(), 0.5 );
139 mSampleStdev = std::pow( sumSquared / ( mValues.count() - 1 ), 0.5 );
147 std::sort( mValues.begin(), mValues.end() );
148 bool even = ( mCount % 2 ) < 1;
151 mMedian = ( mValues[mCount / 2 - 1] + mValues[mCount / 2] ) / 2.0;
155 mMedian = mValues[( mCount + 1 ) / 2 - 1];
160 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
162 if ( ( mCount % 2 ) < 1 )
164 int halfCount = mCount / 2;
165 bool even = ( halfCount % 2 ) < 1;
168 mFirstQuartile = ( mValues[halfCount / 2 - 1] + mValues[halfCount / 2] ) / 2.0;
172 mFirstQuartile = mValues[( halfCount + 1 ) / 2 - 1];
177 int halfCount = mCount / 2 + 1;
178 bool even = ( halfCount % 2 ) < 1;
181 mFirstQuartile = ( mValues[halfCount / 2 - 1] + mValues[halfCount / 2] ) / 2.0;
185 mFirstQuartile = mValues[( halfCount + 1 ) / 2 - 1];
191 || mStatistics & QgsStatisticalSummary::InterQuartileRange )
193 if ( ( mCount % 2 ) < 1 )
195 int halfCount = mCount / 2;
196 bool even = ( halfCount % 2 ) < 1;
199 mThirdQuartile = ( mValues[ halfCount + halfCount / 2 - 1] + mValues[ halfCount + halfCount / 2] ) / 2.0;
203 mThirdQuartile = mValues[( halfCount + 1 ) / 2 - 1 + halfCount ];
208 int halfCount = mCount / 2 + 1;
209 bool even = ( halfCount % 2 ) < 1;
212 mThirdQuartile = ( mValues[ halfCount + halfCount / 2 - 2 ] + mValues[ halfCount + halfCount / 2 - 1 ] ) / 2.0;
216 mThirdQuartile = mValues[( halfCount + 1 ) / 2 - 2 + halfCount ];
223 QList<int> valueCounts = mValueCount.values();
224 std::sort( valueCounts.begin(), valueCounts.end() );
227 mMinority = mValueCount.key( valueCounts.first() );
229 if ( mStatistics & QgsStatisticalSummary::Majority )
231 mMajority = mValueCount.key( valueCounts.last() );
272 return mValueCount.count();
274 return mFirstQuartile;
276 return mThirdQuartile;
278 return mThirdQuartile - mFirstQuartile;
290 return QObject::tr(
"Count" );
292 return QObject::tr(
"Count (missing)" );
294 return QObject::tr(
"Sum" );
296 return QObject::tr(
"Mean" );
298 return QObject::tr(
"Median" );
300 return QObject::tr(
"St dev (pop)" );
302 return QObject::tr(
"St dev (sample)" );
304 return QObject::tr(
"Minimum" );
306 return QObject::tr(
"Maximum" );
308 return QObject::tr(
"Range" );
310 return QObject::tr(
"Minority" );
312 return QObject::tr(
"Majority" );
314 return QObject::tr(
"Variety" );
316 return QObject::tr(
"Q1" );
318 return QObject::tr(
"Q3" );
320 return QObject::tr(
"IQR" );
void reset()
Resets the calculated values.
Statistic
Enumeration of flags that specify statistics to be calculated.
Variety (count of distinct) values.
void finalize()
Must be called after adding all values with addValues() and before retrieving any calculated statisti...
void addVariant(const QVariant &value)
Adds a single value to the statistics calculation.
Sample standard deviation of values.
Number of missing (null) values.
double statistic(QgsStatisticalSummary::Statistic stat) const
Returns the value of a specified statistic.
Inter quartile range (IQR)
QgsStatisticalSummary(QgsStatisticalSummary::Statistics stats=QgsStatisticalSummary::All)
Constructor for QgsStatisticalSummary.
static QString displayName(QgsStatisticalSummary::Statistic statistic)
Returns the friendly display name for a statistic.
void setStatistics(QgsStatisticalSummary::Statistics stats)
Sets flags which specify which statistics will be calculated.
void calculate(const QList< double > &values)
Calculates summary statistics for a list of values.
Standard deviation of values.
Range of values (max - min)
void addValue(double value)
Adds a single value to the statistics calculation.