← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11027: Analytics, fixed bug with reporting rates calculation

 

------------------------------------------------------------
revno: 11027
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-05-27 21:21:48 +0200
message:
  Analytics, fixed bug with reporting rates calculation
modified:
  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/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-26 14:06:51 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-05-27 19:21:48 +0000
@@ -274,7 +274,11 @@
         // ---------------------------------------------------------------------
 
         if ( params.getDataSets() != null )
-        {            
+        {
+            // -----------------------------------------------------------------
+            // Get complete data set registrations
+            // -----------------------------------------------------------------
+
             DataQueryParams dataSourceParams = new DataQueryParams( params );
             dataSourceParams.removeDimension( INDICATOR_DIM_ID );
             dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
@@ -282,40 +286,49 @@
 
             Map<String, Double> aggregatedDataMap = getAggregatedCompletenessValueMap( dataSourceParams );
 
-            DataQueryParams dataTargetParams = new DataQueryParams( params );
-            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 );
-            
-            Map<String, PeriodType> dsPtMap = dataSourceParams.getDataSetPeriodTypeMap();
-            
+            // -----------------------------------------------------------------
+            // Get completeness targets
+            // -----------------------------------------------------------------
+
+            List<Integer> completenessDimIndexes = dataSourceParams.getCompletenessDimensionIndexes();
+            List<Integer> completenessFilterIndexes = dataSourceParams.getCompletenessFilterIndexes();
+            
+            DataQueryParams targetParams = new DataQueryParams( dataSourceParams );
+
+            targetParams.setDimensions( ListUtils.getAtIndexes( targetParams.getDimensions(), completenessDimIndexes ) );
+            targetParams.setFilters( ListUtils.getAtIndexes( targetParams.getFilters(), completenessFilterIndexes ) );
+            targetParams.setSkipPartitioning( true );
+
+            Map<String, Double> targetMap = getAggregatedCompletenessTargetMap( targetParams );
+
             Integer periodIndex = dataSourceParams.getPeriodDimensionIndex();
             Integer dataSetIndex = dataSourceParams.getDataSetDimensionIndex();
-            
-            List<Integer> completenessDimIndexes = dataTargetParams.getCompletenessDimensionIndexes();
-            
+
+            Map<String, PeriodType> dsPtMap = dataSourceParams.getDataSetPeriodTypeMap();
+
+            // -----------------------------------------------------------------
+            // Join data maps, calculate completeness and add to grid
+            // -----------------------------------------------------------------
+
             for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
             {
-                List<String> row = new ArrayList<String>( Arrays.asList( entry.getKey().split( DIMENSION_SEP ) ) );
+                List<String> dataRow = new ArrayList<String>( Arrays.asList( entry.getKey().split( DIMENSION_SEP ) ) );
                 
-                List<String> targetRow = ListUtils.getAll( row, completenessDimIndexes );
+                List<String> targetRow = ListUtils.getAtIndexes( dataRow, completenessDimIndexes );
                 String targetKey = StringUtils.join( targetRow, DIMENSION_SEP );
                 Double target = targetMap.get( targetKey );
                              
                 if ( target != null && entry.getValue() != null )
                 {
-                    PeriodType queryPt = PeriodType.getPeriodTypeFromIsoString( row.get( periodIndex ) );
-                    PeriodType dataPt = dsPtMap.get( row.get( dataSetIndex ) );
+                    PeriodType queryPt = PeriodType.getPeriodTypeFromIsoString( dataRow.get( periodIndex ) );
+                    PeriodType dataPt = dsPtMap.get( dataRow.get( dataSetIndex ) );
                     
                     target = target * queryPt.getPeriodSpan( dataPt );
                     
                     double value = entry.getValue() * PERCENT / target;
                     
                     grid.addRow();
-                    grid.addValues( row.toArray() );
+                    grid.addValues( dataRow.toArray() );
                     grid.addValue( MathUtils.getRounded( value, 1 ) );
                 }
             }

=== 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-22 17:24:41 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ListUtils.java	2013-05-27 19:21:48 +0000
@@ -81,7 +81,7 @@
      * @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 )
+    public static <T> List<T> getAtIndexes( List<T> list, List<Integer> indexes )
     {
         List<T> elements = new ArrayList<T>();