← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9620: Analytics, impl support for boolean average aggregation

 

------------------------------------------------------------
revno: 9620
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2013-01-27 16:20:01 +0200
message:
  Analytics, impl support for boolean average aggregation
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java
  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-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/JdbcAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsManagerTest.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/AggregationType.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java	2013-01-18 14:18:49 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java	2013-01-27 14:20:01 +0000
@@ -29,5 +29,5 @@
 
 public enum AggregationType
 {
-    SUM, AVERAGE_AGGREGATION, AVERAGE_DISAGGREGATION, COUNT_AGGREGATION
+    SUM, AVERAGE_INT_AGGREGATION, AVERAGE_INT_DISAGGREGATION, AVERAGE_BOOL, COUNT
 }

=== 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-01-26 08:20:27 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-01-27 14:20:01 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.analytics.AggregationType.AVERAGE_DISAGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT_DISAGGREGATION;
 
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -303,7 +303,7 @@
      */
     public void replaceAggregationPeriodsWithDataPeriods( ListMap<IdentifiableObject, IdentifiableObject> dataPeriodAggregationPeriodMap )
     {
-        if ( isAggregationType( AVERAGE_DISAGGREGATION ) &&  dataPeriodType != null )
+        if ( isAggregationType( AVERAGE_INT_DISAGGREGATION ) &&  dataPeriodType != null )
         {
             this.periodType = this.dataPeriodType.getName();
             

=== 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-01-27 11:43:58 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-01-27 14:20:01 +0000
@@ -151,7 +151,7 @@
             Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, ANALYTICS_TABLE_NAME );
 
             Map<String, Map<DataElementOperand, Double>> permutationOperandValueMap = dataSourceParams.getPermutationOperandValueMap( aggregatedDataMap );
-
+            
             List<List<DimensionOption>> dimensionOptionPermutations = dataSourceParams.getDimensionOptionPermutations();
 
             Map<String, Double> constantMap = constantService.getConstantMap();
@@ -163,7 +163,7 @@
                     String permKey = DimensionOption.asOptionKey( options );
 
                     Map<DataElementOperand, Double> valueMap = permutationOperandValueMap.get( permKey );
-
+                    
                     if ( valueMap != null )
                     {
                         Period period = (Period) DimensionOption.getPeriodOption( options );
@@ -217,7 +217,7 @@
             dataSourceParams.removeDimension( INDICATOR_DIM_ID );
             dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
             dataSourceParams.setCategories( false );
-            dataSourceParams.setAggregationType( AggregationType.COUNT_AGGREGATION );
+            dataSourceParams.setAggregationType( AggregationType.COUNT );
 
             Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, COMPLETENESS_TABLE_NAME );
 

=== 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-01-22 07:59:25 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java	2013-01-27 14:20:01 +0000
@@ -27,7 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.analytics.AggregationType.AVERAGE_DISAGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.*;
 import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
 import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
 import static org.hisp.dhis.analytics.DataQueryParams.*;
@@ -97,7 +97,7 @@
                     
                     for ( DataQueryParams byAggregationType : groupedByAggregationType )
                     {
-                        if ( AVERAGE_DISAGGREGATION.equals( byAggregationType.getAggregationType() ) )
+                        if ( AVERAGE_INT_DISAGGREGATION.equals( byAggregationType.getAggregationType() ) )
                         {
                             List<DataQueryParams> groupedByDataPeriodType = groupByDataPeriodType( byAggregationType );
                             
@@ -465,19 +465,26 @@
             
             if ( AGGREGATION_OPERATOR_SUM.equals( dataElement.getAggregationOperator() ) )
             {
-                map.putValue( AggregationType.SUM, element );
+                map.putValue( SUM, element );
             }
             else if ( AGGREGATION_OPERATOR_AVERAGE.equals( dataElement.getAggregationOperator() ) )
             {
-                PeriodType dataPeriodType = dataElement.getPeriodType();
-                
-                if ( dataPeriodType == null || aggregationPeriodType.getFrequencyOrder() >= dataPeriodType.getFrequencyOrder() )
+                if ( DataElement.VALUE_TYPE_BOOL.equals( dataElement.getType() ) )
                 {
-                    map.putValue( AggregationType.AVERAGE_AGGREGATION, element );
+                    map.putValue( AVERAGE_BOOL, element );
                 }
                 else
                 {
-                    map.putValue( AggregationType.AVERAGE_DISAGGREGATION, element );
+                    PeriodType dataPeriodType = dataElement.getPeriodType();
+                    
+                    if ( dataPeriodType == null || aggregationPeriodType.getFrequencyOrder() >= dataPeriodType.getFrequencyOrder() )
+                    {
+                        map.putValue( AVERAGE_INT_AGGREGATION, element );
+                    }
+                    else
+                    {
+                        map.putValue( AVERAGE_INT_DISAGGREGATION, element );
+                    }
                 }
             }
         }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2013-01-27 11:43:58 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java	2013-01-27 14:20:01 +0000
@@ -27,9 +27,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.analytics.AggregationType.AVERAGE_AGGREGATION;
-import static org.hisp.dhis.analytics.AggregationType.AVERAGE_DISAGGREGATION;
-import static org.hisp.dhis.analytics.AggregationType.COUNT_AGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT_AGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.AVERAGE_BOOL;
+import static org.hisp.dhis.analytics.AggregationType.AVERAGE_INT_DISAGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.COUNT;
 import static org.hisp.dhis.analytics.DataQueryParams.DIMENSION_SEP;
 import static org.hisp.dhis.analytics.DataQueryParams.VALUE_ID;
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
@@ -74,7 +75,7 @@
     //TODO optimize when all options in dimensions are selected
     
     private static final Log log = LogFactory.getLog( JdbcAnalyticsManager.class );
-    
+        
     @Autowired
     private JdbcTemplate jdbcTemplate;
     
@@ -87,7 +88,7 @@
     {
         ListMap<IdentifiableObject, IdentifiableObject> dataPeriodAggregationPeriodMap = params.getDataPeriodAggregationPeriodMap();
         params.replaceAggregationPeriodsWithDataPeriods( dataPeriodAggregationPeriodMap );
-
+        
         params.populateDimensionNames();
         
         List<Dimension> selectDimensions = params.getSelectDimensions();
@@ -99,15 +100,19 @@
         
         String sql = "select " + getCommaDelimitedString( selectDimensions ) + ", ";
         
-        if ( params.isAggregationType( AVERAGE_AGGREGATION ) )
+        if ( params.isAggregationType( AVERAGE_INT_AGGREGATION ) )
         {
             sql += "sum(daysxvalue) / " + days;
         }
-        else if ( params.isAggregationType( COUNT_AGGREGATION ) )
+        else if ( params.isAggregationType( AVERAGE_BOOL ) )
+        {
+            sql += "sum(daysxvalue) / sum(daysno)";
+        }
+        else if ( params.isAggregationType( COUNT ) )
         {
             sql += "count(value)";
         }
-        else
+        else // SUM, AVERAGE_DISAGGREGATION and undefined //TODO
         {
             sql += "sum(value)";
         }
@@ -155,7 +160,7 @@
 
     public void replaceDataPeriodsWithAggregationPeriods( Map<String, Double> dataValueMap, DataQueryParams params, ListMap<IdentifiableObject, IdentifiableObject> dataPeriodAggregationPeriodMap )
     {
-        if ( params.isAggregationType( AVERAGE_DISAGGREGATION ) )
+        if ( params.isAggregationType( AVERAGE_INT_DISAGGREGATION ) )
         {
             int periodIndex = params.getPeriodDimensionIndex();
             

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsManagerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsManagerTest.java	2013-01-16 18:19:17 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/AnalyticsManagerTest.java	2013-01-27 14:20:01 +0000
@@ -61,7 +61,7 @@
         params.setPeriods( getList( y2012 ) );
         params.setOrganisationUnits( getList( createOrganisationUnit( 'A' ) ) );
         params.setDataPeriodType( new YearlyPeriodType() );
-        params.setAggregationType( AggregationType.AVERAGE_DISAGGREGATION );
+        params.setAggregationType( AggregationType.AVERAGE_INT_DISAGGREGATION );
         
         Map<String, Double> dataValueMap = new HashMap<String, Double>();
         dataValueMap.put( BASE_UID + "A-2012-" + BASE_UID + "A", 1d );