← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9880: Analytics, WIP completeness support

 

------------------------------------------------------------
revno: 9880
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-02-22 18:24:41 +0100
message:
  Analytics, WIP completeness support
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/DefaultAnalyticsService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.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-02-21 18:18:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-02-22 17:24:41 +0000
@@ -178,39 +178,39 @@
     }
     
     /**
-     * Creates a list of dimensions which are relevant to completeness queries.
+     * Creates a list of dimension indexes which are relevant to completeness queries.
      */
-    public List<Dimension> getCompletenessDimensions()
+    public List<Integer> getCompletenessDimensionIndexes()
     {
-        List<Dimension> list = new ArrayList<Dimension>();
+        List<Integer> indexes = new ArrayList<Integer>();
         
-        for ( Dimension dim : dimensions )
+        for ( int i = 0; i < dimensions.size(); i++ )
         {
-            if ( COMPLETENESS_DIMENSION_TYTPES.contains( dim.getType() ) )
+            if ( COMPLETENESS_DIMENSION_TYTPES.contains( dimensions.get( i ).getType() ) )
             {
-                list.add( dim );
+                indexes.add( i );
             }
         }
         
-        return list;
+        return indexes;
     }
 
     /**
-     * Creates a list of dimensions which are relevant to completeness queries.
+     * Creates a list of filter indexes which are relevant to completeness queries.
      */
-    public List<Dimension> getCompletenessFilters()
+    public List<Integer> getCompletenessFilterIndexes()
     {
-        List<Dimension> list = new ArrayList<Dimension>();
+        List<Integer> indexes = new ArrayList<Integer>();
         
-        for ( Dimension dim : filters )
+        for ( int i = 0; i < filters.size(); i++ )
         {
-            if ( COMPLETENESS_DIMENSION_TYTPES.contains( dim.getType() ) )
+            if ( COMPLETENESS_DIMENSION_TYTPES.contains( filters.get( i ).getType() ) )
             {
-                list.add( dim );
+                indexes.add( i );
             }
         }
         
-        return list;
+        return indexes;
     }
 
     /**
@@ -236,6 +236,14 @@
     {
         return getInputDimensionNamesAsList().indexOf( DATAELEMENT_DIM_ID );
     }
+    
+    /**
+     * Returns the index of the data set dimension in the dimension map.
+     */
+    public int getDataSetDimensionIndex()
+    {
+        return getInputDimensionNamesAsList().indexOf( DATASET_DIM_ID );
+    }
 
     /**
      * Returns the index of the category option combo dimension in the dimension map.

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-02-21 18:18:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-02-22 17:24:41 +0000
@@ -55,6 +55,7 @@
 import java.util.Set;
 import java.util.concurrent.Future;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.AggregationType;
@@ -92,6 +93,7 @@
 import org.hisp.dhis.period.comparator.PeriodComparator;
 import org.hisp.dhis.system.grid.ListGrid;
 import org.hisp.dhis.system.util.ConversionUtils;
+import org.hisp.dhis.system.util.ListUtils;
 import org.hisp.dhis.system.util.MathUtils;
 import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.system.util.Timer;
@@ -107,6 +109,7 @@
     
     //TODO completeness
     //TODO make sure data x dims are successive
+    //TODO max value limit, 5000?
     
     @Autowired
     private AnalyticsManager analyticsManager;
@@ -213,7 +216,7 @@
                             grid.addValues( DimensionOption.getOptionIdentifiers( row ) );
                             grid.addValue( MathUtils.getRounded( value, 1 ) );
                         }
-                    }                    
+                    }
                 }
             }
         }
@@ -252,20 +255,34 @@
             Map<String, Double> aggregatedDataMap = getAggregatedCompletenessValueMap( dataSourceParams );
 
             DataQueryParams dataTargetParams = new DataQueryParams( params );
-            dataTargetParams.setDimensions( dataTargetParams.getCompletenessDimensions() );
-            dataTargetParams.setFilters( dataTargetParams.getCompletenessFilters() );
+            dataTargetParams.setDimensions( ListUtils.getAll( dataTargetParams.getDimensions(), dataTargetParams.getCompletenessDimensionIndexes() ) );
+            dataTargetParams.setFilters( ListUtils.getAll( dataTargetParams.getFilters(), dataTargetParams.getCompletenessFilterIndexes() ) );
             dataTargetParams.setAggregationType( AggregationType.COUNT );
             dataTargetParams.setSkipPartitioning( true );
 
             Map<String, Double> targetMap = getAggregatedCompletenessTargetMap( dataTargetParams ); //TODO
             
+            Integer periodIndex = dataSourceParams.getPeriodDimensionIndex();
+            Integer dataSetIndex = dataSourceParams.getDataSetDimensionIndex();
+            
+            //TODO time aggregation for completeness, use data set period type and period.getPeriodSpan
+            
             for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
             {
                 List<String> row = new ArrayList<String>( Arrays.asList( entry.getKey().split( DIMENSION_SEP ) ) );
                 
-                grid.addRow();
-                grid.addValues( row.toArray() );
-                grid.addValue( entry.getValue() );
+                List<String> targetRow = ListUtils.getAll( row, dataTargetParams.getCompletenessDimensionIndexes() );
+                String targetKey = StringUtils.join( targetRow, DIMENSION_SEP );
+                Double target = targetMap.get( targetKey );
+                             
+                if ( target != null && entry.getValue() != null )
+                {
+                    double value = entry.getValue() / target;
+                    
+                    grid.addRow();
+                    grid.addValues( row.toArray() );
+                    grid.addValue( value );
+                }
             }
         }
 

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2013-02-12 16:05:31 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2013-02-22 17:24:41 +0000
@@ -47,23 +47,53 @@
      * @param list the list to remove elements from.
      * @param indexes the indexes for the elements to remove.
      */
-    public static <T> void removeAll( List<T> list, Integer... indexes )
+    public static <T> void removeAll( List<T> list, List<Integer> indexes )
     {
         if ( list == null || indexes == null )
         {
             return;
         }
         
-        List<Integer> inx = new ArrayList<Integer>( Arrays.asList( indexes ) );
-        Collections.sort( inx, Collections.reverseOrder() );
+        Collections.sort( indexes, Collections.reverseOrder() );
         
-        for ( Integer index : inx )
+        for ( Integer index : indexes )
         {            
             list.remove( (int) index );
         }
     }
     
     /**
+     * Removes from the given list the elements at the given indexes.
+     * 
+     * @param indexes the list to remove elements from.
+     * @param indexes the indexes for the elements to remove.
+     */
+    public static <T> void removeAll( List<T> list, Integer... indexes )
+    {
+        List<Integer> inx = new ArrayList<Integer>( Arrays.asList( indexes ) );
+        
+        removeAll( list, inx );
+    }
+    
+    /**
+     * Returns a sublist of the given list with the elements at the given indexes.
+     * 
+     * @param list the list to select from.
+     * @param indexes the indexes of the elements in the list to select.
+     */
+    public static <T> List<T> getAll( List<T> list, List<Integer> indexes )
+    {
+        List<T> elements = new ArrayList<T>();
+        
+        for ( Integer index : indexes )
+        {
+            elements.add( list.get( index ) );
+        }
+        
+        return elements;
+    }
+    
+    /**
      * Checks whether the given list contains duplicates. List entries are compared
      * using the given comparator.
      *