QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsdatetimestatisticalsummary.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatetimestatisticalsummary.h
3  -------------------------------
4  Date : May 2016
5  Copyright : (C) 2016 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 QGSDATETIMESTATISTICALSUMMARY_H
17 #define QGSDATETIMESTATISTICALSUMMARY_H
18 
19 #include "qgis.h"
20 #include "qgsinterval.h"
21 #include <QSet>
22 #include <QDateTime>
23 #include <QVariantList>
24 
25 /***************************************************************************
26  * This class is considered CRITICAL and any change MUST be accompanied with
27  * full unit tests in test_qgsdatetimestatisticalsummary.py.
28  * See details in QEP #17
29  ****************************************************************************/
30 
44 {
45  public:
46 
48  enum Statistic
49  {
50  Count = 1,
51  CountDistinct = 2,
52  CountMissing = 4,
53  Min = 8,
54  Max = 16,
55  Range = 32,
56  All = Count | CountDistinct | CountMissing | Min | Max | Range,
57  };
58  Q_DECLARE_FLAGS( Statistics, Statistic )
59 
60 
63  QgsDateTimeStatisticalSummary( const QgsDateTimeStatisticalSummary::Statistics& stats = All );
64 
69  Statistics statistics() const { return mStatistics; }
70 
76  void setStatistics( const Statistics& stats ) { mStatistics = stats; }
77 
80  void reset();
81 
87  void calculate( const QVariantList& values );
88 
101  void addValue( const QVariant& value );
102 
107  void finalize();
108 
113  QVariant statistic( Statistic stat ) const;
114 
117  int count() const { return mCount; }
118 
121  int countDistinct() const { return mValues.count(); }
122 
125  QSet< QDateTime > distinctValues() const { return mValues; }
126 
129  int countMissing() const { return mCountMissing; }
130 
133  QDateTime min() const { return mMin; }
134 
137  QDateTime max() const { return mMax; }
138 
141  QgsInterval range() const { return mMax - mMin; }
142 
146  static QString displayName( Statistic statistic );
147 
148  private:
149 
150  Statistics mStatistics;
151 
152  int mCount;
153  QSet< QDateTime > mValues;
154  int mCountMissing;
155  QDateTime mMin;
156  QDateTime mMax;
157 
158  void testDateTime( const QDateTime& dateTime );
159 };
160 
161 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDateTimeStatisticalSummary::Statistics )
162 
163 #endif // QGSDATETIMESTATISTICALSUMMARY_H
int count() const
Returns the calculated count of values.
int countMissing() const
Returns the number of missing (null) datetime values.
QDateTime min() const
Returns the minimum (earliest) non-null datetime value.
void setStatistics(const Statistics &stats)
Sets flags which specify which statistics will be calculated.
Calculator for summary statistics and aggregates for a list of datetimes.
QSet< QDateTime > distinctValues() const
Returns the set of distinct datetime values.
QDateTime max() const
Returns the maximum (latest) non-null datetime value.
Statistic
Enumeration of flags that specify statistics to be calculated.
A representation of the interval between two datetime values.
Definition: qgsinterval.h:34
Statistics statistics() const
Returns flags which specify which statistics will be calculated.
QgsInterval range() const
Returns the range (interval between earliest and latest non-null datetime values).
int countDistinct() const
Returns the number of distinct datetime values.