← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 10133: Analytics, fixed bug in calculation of total no of dimension item permutiations

 

------------------------------------------------------------
revno: 10133
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-03-11 09:24:17 +0100
message:
  Analytics, fixed bug in calculation of total no of dimension item permutiations
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.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-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-03-10 16:13:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-03-11 08:24:17 +0000
@@ -28,7 +28,10 @@
  */
 
 import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT_DISAGGREGATION;
-import static org.hisp.dhis.analytics.DimensionType.*;
+import static org.hisp.dhis.analytics.DimensionType.DATASET;
+import static org.hisp.dhis.analytics.DimensionType.ORGANISATIONUNIT;
+import static org.hisp.dhis.analytics.DimensionType.ORGANISATIONUNIT_GROUPSET;
+import static org.hisp.dhis.system.util.CollectionUtils.emptyIfNull;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -43,12 +46,12 @@
 import org.apache.commons.lang.StringUtils;
 import org.hisp.dhis.common.CombinationGenerator;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.CollectionUtils;
-import org.hisp.dhis.common.ListMap;
 import org.hisp.dhis.system.util.ListUtils;
 import org.hisp.dhis.system.util.MapMap;
 import org.hisp.dhis.system.util.MathUtils;
@@ -72,7 +75,7 @@
     public static final List<String> DATA_DIMS = Arrays.asList( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID );
     public static final List<String> FIXED_DIMS = Arrays.asList( DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
     
-    public static final int MAX_DIM_OPT_PERM = 5000;
+    public static final int MAX_DIM_OPT_PERM = 10000;
     
     private static final List<DimensionType> COMPLETENESS_DIMENSION_TYPES = Arrays.asList( DATASET, ORGANISATIONUNIT, ORGANISATIONUNIT_GROUPSET );
     
@@ -359,15 +362,28 @@
     }
     
     /**
-     * Returns the number of dimension option permutations.
+     * Returns the number of dimension option permutations. Merges the three data
+     * dimensions into one prior to the calculation.
      */
     public int getNumberOfDimensionOptionPermutations()
     {
         int total = 1;
         
-        for ( Dimension dim : dimensions )
+        DataQueryParams query = new DataQueryParams( this );
+        
+        query.getDimensions().add( new Dimension( DATA_X_DIM_ID ) );
+        
+        query.getDimension( DATA_X_DIM_ID ).getItems().addAll( emptyIfNull( query.getDimensionOptions( INDICATOR_DIM_ID ) ) );
+        query.getDimension( DATA_X_DIM_ID ).getItems().addAll( emptyIfNull( query.getDimensionOptions( DATAELEMENT_DIM_ID ) ) );
+        query.getDimension( DATA_X_DIM_ID ).getItems().addAll( emptyIfNull( query.getDimensionOptions( DATASET_DIM_ID ) ) );
+        
+        query.removeDimension( INDICATOR_DIM_ID );
+        query.removeDimension( DATAELEMENT_DIM_ID );
+        query.removeDimension( DATASET_DIM_ID );
+        
+        for ( Dimension dim : query.getDimensions() )
         {
-            total *= dim.getItems().size();
+            total *= Math.max( dim.getItems().size(), 1 );
         }
         
         return total;

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-03-10 16:13:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-03-11 08:24:17 +0000
@@ -109,7 +109,7 @@
         
         if ( params.getNumberOfDimensionOptionPermutations() > MAX_DIM_OPT_PERM )
         {
-            violation = "Table exceeds max number of cells: " + MAX_DIM_OPT_PERM;
+            violation = "Table exceeds max number of cells: " + MAX_DIM_OPT_PERM + " (" + params.getNumberOfDimensionOptionPermutations() + ")";
         }
         
         if ( !params.getDuplicateDimensions().isEmpty() )

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2013-03-10 16:13:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java	2013-03-11 08:24:17 +0000
@@ -314,6 +314,29 @@
             assertEquals( PERIOD_DIM_ID, permutation.get( 1 ).getDimension() );
         }
     }
+
+    /**
+     * First, combines data elements and data sets into one data dimension and 
+     * returns (2 + 3) * 3 * 2 = 30. Second, ignores any data dimension and
+     * returns 3 * 2 = 6.
+     */
+    @Test
+    public void testGetNumberOfDimensionOptionPermutations()
+    {
+        DataQueryParams params = new DataQueryParams();
+        params.setDataElements( getList( deA, deB ) );
+        params.setDataSets( getList( dsA, dsB, dsC ) );
+        params.setOrganisationUnits( getList( ouA, ouB, ouC ) );
+        params.setPeriods( getList( createPeriod( "2000Q1" ), createPeriod( "2000Q2" ) ) );
+        
+        assertEquals( 30, params.getNumberOfDimensionOptionPermutations() );
+
+        params = new DataQueryParams();
+        params.setOrganisationUnits( getList( ouA, ouB, ouC ) );
+        params.setPeriods( getList( createPeriod( "2000Q1" ), createPeriod( "2000Q2" ) ) );
+
+        assertEquals( 6, params.getNumberOfDimensionOptionPermutations() );
+    }
     
     @Test
     public void testGetDataPeriodAggregationPeriodMap()