← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2078: Fixed minor bug in datamart

 

------------------------------------------------------------
revno: 2078
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Sun 2010-07-04 13:11:30 +0200
message:
  Fixed minor bug in datamart
modified:
  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/AverageIntSingleValueAggregator.java
  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/SumIntAggregator.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== 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<DataElementOperand, String> entry : crossTabValue.getValueMap().entrySet() ) // <Operand, value>
-            {
-                if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel )  )
+            if ( duration > 0 )
+            {            
+                for ( final Entry<DataElementOperand, String> entry : crossTabValue.getValueMap().entrySet() ) // <Operand, value>
                 {
-                    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<DataElementOperand, String> entry : crossTabValue.getValueMap().entrySet() ) // <Operand, value>
-            {
-                if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel )  )
+            duration = getDaysInclusive( currentStartDate, currentEndDate );
+            
+            if ( duration > 0 )
+            {            
+                for ( final Entry<DataElementOperand, String> entry : crossTabValue.getValueMap().entrySet() ) // <Operand, value>
                 {
-                    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 );