=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2010-06-26 19:48:18 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2010-07-04 11:11:30 +0000 @@ -131,7 +131,8 @@ double relevantDays = 0.0; double existingValue = 0.0; double existingRelevantDays = 0.0; - + double duration = 0.0; + int dataValueLevel = 0; for ( final CrossTabDataValue crossTabValue : crossTabValues ) @@ -142,54 +143,58 @@ currentEndDate = period.getEndDate(); dataValueLevel = aggregationCache.getLevelOfOrganisationUnit( crossTabValue.getSourceId() ); + + duration = getDaysInclusive( currentStartDate, currentEndDate ); - for ( final Entry entry : crossTabValue.getValueMap().entrySet() ) // - { - if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) + if ( duration > 0 ) + { + for ( final Entry entry : crossTabValue.getValueMap().entrySet() ) // { - value = 0.0; - - try - { - value = Double.parseDouble( entry.getValue() ); - } - catch ( NumberFormatException ex ) - { - log.warn( "Value skipped, not numeric: '" + entry.getValue() + - "', for data element with id: '" + entry.getKey() + - "', for period with id: '" + crossTabValue.getPeriodId() + - "', for source with id: '" + crossTabValue.getSourceId() + "'" ); - } - - relevantDays = 0.0; - - if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 ) // Value is within period - { - relevantDays = getDaysInclusive( currentStartDate, currentEndDate ); - } - else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 ) // Value spans whole period - { - relevantDays = getDaysInclusive( startDate, endDate ); - } - else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 - && currentEndDate.compareTo( endDate ) <= 0 ) // Value spans period start - { - relevantDays = getDaysInclusive( startDate, currentEndDate ); - } - else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0 - && currentEndDate.compareTo( endDate ) >= 0 ) // Value spans period end - { - relevantDays = getDaysInclusive( currentStartDate, endDate ); - } - - value = value * relevantDays; - - existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0; - existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0; - - final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) }; - - totalSums.put( entry.getKey(), values ); + if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) + { + value = 0.0; + relevantDays = 0.0; + + try + { + value = Double.parseDouble( entry.getValue() ); + } + catch ( NumberFormatException ex ) + { + log.warn( "Value skipped, not numeric: '" + entry.getValue() + + "', for data element with id: '" + entry.getKey() + + "', for period with id: '" + crossTabValue.getPeriodId() + + "', for source with id: '" + crossTabValue.getSourceId() + "'" ); + } + + if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 ) // Value is within period + { + relevantDays = getDaysInclusive( currentStartDate, currentEndDate ); + } + else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 ) // Value spans whole period + { + relevantDays = getDaysInclusive( startDate, endDate ); + } + else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 + && currentEndDate.compareTo( endDate ) <= 0 ) // Value spans period start + { + relevantDays = getDaysInclusive( startDate, currentEndDate ); + } + else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0 + && currentEndDate.compareTo( endDate ) >= 0 ) // Value spans period end + { + relevantDays = getDaysInclusive( currentStartDate, endDate ); + } + + value = value * relevantDays; + + existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0; + existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0; + + final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) }; + + totalSums.put( entry.getKey(), values ); + } } } } === modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2010-06-26 19:48:18 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2010-07-04 11:11:30 +0000 @@ -119,6 +119,7 @@ double relevantDays = 0.0; double existingValue = 0.0; double existingRelevantDays = 0.0; + double duration = 0.0; int dataValueLevel = 0; @@ -131,37 +132,41 @@ dataValueLevel = aggregationCache.getLevelOfOrganisationUnit( crossTabValue.getSourceId() ); - for ( final Entry entry : crossTabValue.getValueMap().entrySet() ) // - { - if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) + duration = getDaysInclusive( currentStartDate, currentEndDate ); + + if ( duration > 0 ) + { + for ( final Entry entry : crossTabValue.getValueMap().entrySet() ) // { - value = 0.0; - - try - { - value = Double.parseDouble( entry.getValue() ); - } - catch ( NumberFormatException ex ) - { - log.warn( "Value skipped, not numeric: '" + entry.getValue() + - "', for data element with id: '" + entry.getKey() + - "', for period with id: '" + crossTabValue.getPeriodId() + - "', for source with id: '" + crossTabValue.getSourceId() + "'" ); - } - - relevantDays = 0.0; - - if ( currentStartDate.compareTo( endDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 ) // Value is intersecting - { - relevantDays = getDaysInclusive( startDate, endDate ); - } - - existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0; - existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0; - - final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) }; - - totalSums.put( entry.getKey(), values ); + if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) + { + value = 0.0; + relevantDays = 0.0; + + try + { + value = Double.parseDouble( entry.getValue() ); + } + catch ( NumberFormatException ex ) + { + log.warn( "Value skipped, not numeric: '" + entry.getValue() + + "', for data element with id: '" + entry.getKey() + + "', for period with id: '" + crossTabValue.getPeriodId() + + "', for source with id: '" + crossTabValue.getSourceId() + "'" ); + } + + if ( currentStartDate.compareTo( endDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 ) // Value is intersecting + { + relevantDays = getDaysInclusive( startDate, endDate ); + } + + existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0; + existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0; + + final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) }; + + totalSums.put( entry.getKey(), values ); + } } } } === modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-26 19:48:18 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-07-04 11:11:30 +0000 @@ -138,10 +138,9 @@ { if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) { - value = 0; - - relevantDays = 0; - factor = 0; + value = 0.0; + relevantDays = 0.0; + factor = 0.0; if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 ) // Value is within period { === modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-26 19:48:18 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-07-04 11:11:30 +0000 @@ -141,6 +141,10 @@ { if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) { + value = 0.0; + relevantDays = 0.0; + factor = 0.0; + try { value = Double.parseDouble( entry.getValue() ); @@ -153,9 +157,6 @@ "', for source with id: '" + crossTabValue.getSourceId() + "'" ); } - relevantDays = 0; - factor = 0; - if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 ) // Value is within period { relevantDays = getDaysInclusive( startDate, endDate );