Skip to content
Permalink
Browse files

Fix basicstatisticsforfields tests

(cherry picked from commit 9d18fe1)
  • Loading branch information
elpaso authored and nyalldawson committed Feb 19, 2021
1 parent 69c1bdf commit 048e9c64ec3dc14c691fb5994670d47c4011a87e
@@ -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'
@@ -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'
@@ -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'
@@ -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?
}

@@ -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 )
@@ -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 )

0 comments on commit 048e9c6

Please sign in to comment.