Skip to content

Commit

Permalink
Fix basicstatisticsforfields tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 9d18fe1)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 69c1bdf commit 048e9c6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 32 deletions.
Expand Up @@ -1115,7 +1115,7 @@ tests:
rules:
- 'Analyzed field: date_time'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 2014-11-30T14:30:02'
- 'Maximum value: 2016-11-30T14:29:22'
- 'NULL \(missing\) values: 1'
Expand All @@ -1134,7 +1134,7 @@ tests:
rules:
- 'Analyzed field: date'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 2014-11-30T00:00:00'
- 'Maximum value: 2016-11-30T00:00:00'
- 'NULL \(missing\) values: 1'
Expand All @@ -1153,7 +1153,7 @@ tests:
rules:
- 'Analyzed field: time'
- 'Count: 4'
- 'Unique values: 3'
- 'Unique values: 4'
- 'Minimum value: 03:29:40'
- 'Maximum value: 15:29:22'
- 'NULL \(missing\) values: 1'
Expand Down
50 changes: 22 additions & 28 deletions src/core/qgsdatetimestatisticalsummary.cpp
Expand Up @@ -58,36 +58,30 @@ void QgsDateTimeStatisticalSummary::calculate( const QVariantList &values )

void QgsDateTimeStatisticalSummary::addValue( const QVariant &value )
{
if ( value.isNull() )

if ( value.type() == QVariant::DateTime )
{
mCountMissing++;
mCount++;
testDateTime( value.toDateTime(), value.isNull() );
}
else
else if ( value.type() == QVariant::Date )
{
if ( value.type() == QVariant::DateTime )
{
testDateTime( value.toDateTime() );
}
else if ( value.type() == QVariant::Date )
{
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime() );
}
else //not a date
{
mCountMissing++;
mCount++;
}
QDate date = value.toDate();
testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
: QDateTime(), value.isNull() );
}
else if ( value.type() == QVariant::Time )
{
mIsTimes = true;
QTime time = value.toTime();
testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
: QDateTime(), value.isNull() );
}
else //not a date
{
mCountMissing++;
mCount++;
}

// QTime?
}

Expand All @@ -97,11 +91,11 @@ void QgsDateTimeStatisticalSummary::finalize()
//if statistics are implemented which require a post-calculation step
}

void QgsDateTimeStatisticalSummary::testDateTime( const QDateTime &dateTime )
void QgsDateTimeStatisticalSummary::testDateTime( const QDateTime &dateTime, bool isNull )
{
mCount++;

if ( !dateTime.isValid() )
if ( !dateTime.isValid() || isNull )
mCountMissing++;

if ( mStatistics & CountDistinct )
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdatetimestatisticalsummary.h
Expand Up @@ -174,7 +174,7 @@ class CORE_EXPORT QgsDateTimeStatisticalSummary
QDateTime mMax;
bool mIsTimes;

void testDateTime( const QDateTime &dateTime );
void testDateTime( const QDateTime &dateTime, bool isNull );
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDateTimeStatisticalSummary::Statistics )
Expand Down

0 comments on commit 048e9c6

Please sign in to comment.