← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19388: Event analytics, impl support for getting aggregate values for data dimensions (as opposed to dat...

 

------------------------------------------------------------
revno: 19388
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-06-13 23:26:59 +0200
message:
  Event analytics, impl support for getting aggregate values for data dimensions (as opposed to data dimension items)
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java
  dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.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/event/EventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-06-13 16:56:08 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java	2015-06-13 21:26:59 +0000
@@ -69,13 +69,14 @@
      * @param limit the max limit of records to return.
      * @param outputType the event output type.
      * @param collapseDataDimensions collapse data dimensions into a single dimension.
+     * @param aggregateData return aggregated data values for data dimensions instead of items.
      * @param displayProperty the display property to use for meta-data.
      * @param format the i18n format.
      */
     EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, 
         Set<String> dimension, Set<String> filter, String value, AggregationType aggregationType, 
         boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, boolean showHierarchy, SortOrder sortOrder, Integer limit, 
-        EventOutputType outputType, boolean collapseDataDimensions, DisplayProperty displayProperty, I18nFormat format );
+        EventOutputType outputType, boolean collapseDataDimensions, boolean aggregateData, DisplayProperty displayProperty, I18nFormat format );
 
     /**
      * Used for event query.

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2015-06-13 17:43:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventQueryParams.java	2015-06-13 21:26:59 +0000
@@ -93,11 +93,7 @@
     
     private boolean coordinatesOnly;
 
-    // -------------------------------------------------------------------------
-    // Transient properties
-    // -------------------------------------------------------------------------
-
-    private boolean aggregateQuery;
+    private boolean aggregateData;
     
     // -------------------------------------------------------------------------
     // Constructors
@@ -138,7 +134,7 @@
         params.outputType = this.outputType;
         params.collapseDataDimensions = this.collapseDataDimensions;
         params.coordinatesOnly = this.coordinatesOnly;
-        params.aggregateQuery = this.aggregateQuery;
+        params.aggregateData = this.aggregateData;
         
         params.periodType = this.periodType;
         
@@ -348,14 +344,6 @@
         return SortOrder.ASC.equals( sortOrder ) ? -1 : SortOrder.DESC.equals( sortOrder ) ? 1 : 0;
     }
     
-    /**
-     * Indicates whether this query is aggregate as opposed to event-based.
-     */
-    public boolean isAggregateQuery()
-    {
-        return aggregateQuery;
-    }
-    
     public String toString()
     {
         return "[" +
@@ -557,8 +545,13 @@
         this.coordinatesOnly = coordinatesOnly;
     }
 
-    public void setAggregateQuery( boolean aggregateQuery )
-    {
-        this.aggregateQuery = aggregateQuery;
+    public boolean isAggregateData()
+    {
+        return aggregateData;
+    }
+
+    public void setAggregateData( boolean aggregateData )
+    {
+        this.aggregateData = aggregateData;
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-06-13 17:43:20 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java	2015-06-13 21:26:59 +0000
@@ -183,7 +183,7 @@
             grid.addHeader( new GridHeader( dimension.getDimension(), dimension.getDisplayName(), String.class.getName(), false, true ) );
         }
 
-        if ( params.isCollapseDataDimensions() )
+        if ( params.isCollapseDataDimensions() || params.isAggregateData() )
         {
             grid.addHeader( new GridHeader( DimensionalObject.DATA_COLLAPSED_DIM_ID, DataQueryParams.DISPLAY_NAME_DATA_X, String.class.getName(), false, true ) );
         }
@@ -371,7 +371,8 @@
     @Override
     public EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate,
         Set<String> dimension, Set<String> filter, String value, AggregationType aggregationType, boolean skipMeta, boolean skipRounding, boolean hierarchyMeta, 
-        boolean showHierarchy, SortOrder sortOrder, Integer limit, EventOutputType outputType, boolean collapseDataDimensions, DisplayProperty displayProperty, I18nFormat format )
+        boolean showHierarchy, SortOrder sortOrder, Integer limit, EventOutputType outputType, boolean collapseDataDimensions, 
+        boolean aggregateData, DisplayProperty displayProperty, I18nFormat format )
     {
         EventQueryParams params = getFromUrl( program, stage, startDate, endDate, dimension, filter, null, null, null,
             skipMeta, hierarchyMeta, false, displayProperty, null, null, format );
@@ -384,7 +385,7 @@
         params.setLimit( limit );
         params.setOutputType( MoreObjects.firstNonNull( outputType, EventOutputType.EVENT ) );
         params.setCollapseDataDimensions( collapseDataDimensions );
-        params.setAggregateQuery( true );
+        params.setAggregateData( aggregateData );
 
         return params;
     }
@@ -491,7 +492,6 @@
         params.setDisplayProperty( displayProperty );
         params.setPage( page );
         params.setPageSize( pageSize );
-        params.setAggregateQuery( false );
         
         return params;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2015-03-24 11:45:27 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventQueryPlanner.java	2015-06-13 21:26:59 +0000
@@ -114,9 +114,9 @@
             violation = "Value dimension cannot also be specified as an item or item filter";
         }
         
-        if ( params.hasAggregationType() && !params.hasValueDimension() )
+        if ( params.hasAggregationType() && !( params.hasValueDimension() || params.isAggregateData() ) )
         {
-            violation = "Value dimension must be specified when aggregation type is specified";
+            violation = "Value dimension or aggregate data must be specified when aggregation type is specified";
         }
         
         if ( !params.hasPeriods() && ( params.getStartDate() == null || params.getEndDate() == null ) )
@@ -265,7 +265,17 @@
     {
         List<EventQueryParams> queries = new ArrayList<>();
         
-        if ( params.isCollapseDataDimensions() && params.getItems() != null && !params.getItems().isEmpty() )
+        if ( params.isAggregateData() )
+        {
+            for ( QueryItem item : params.getItems() )
+            {
+                EventQueryParams query = params.instance();
+                query.getItems().clear();
+                query.setValue( item.getItem() );
+                queries.add( query );
+            }
+        }
+        else if ( params.isCollapseDataDimensions() && !params.getItems().isEmpty() )
         {
             for ( QueryItem item : params.getItems() )
             {

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-06-13 17:18:42 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/JdbcEventAnalyticsManager.java	2015-06-13 21:26:59 +0000
@@ -172,6 +172,11 @@
                 grid.addValue( gridValue );
             }
             
+            if ( params.isAggregateData() )
+            {
+                grid.addValue( params.getValue().getUid() );
+            }
+            
             if ( params.hasValueDimension() )
             {
                 double value = rowSet.getDouble( "value" );

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2015-06-01 23:57:56 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java	2015-06-13 21:26:59 +0000
@@ -182,7 +182,7 @@
         filterParams.add( "pe:201401;201402" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getOrganisationUnits().size() );
@@ -201,7 +201,7 @@
         filterParams.add( "pe:201401" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, deA.getUid(), AggregationType.AVERAGE, false, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, deA.getUid(), AggregationType.AVERAGE, false, false, false, false, null, null, null, false, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getOrganisationUnits().size() );
@@ -335,7 +335,7 @@
         filterParams.add( atA.getUid() + ":LE:5" );
         
         EventQueryParams params = analyticsService.getFromUrl( prA.getUid(), null, 
-            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, null, null );
+            null, null, dimensionParams, filterParams, null, null, false, false, false, false, null, null, null, false, false, null, null );
         
         assertEquals( prA, params.getProgram() );
         assertEquals( 1, params.getItems().size() );

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2015-04-01 08:42:16 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2015-06-13 21:26:59 +0000
@@ -862,13 +862,16 @@
     {
         Integer rowLength = null;
 
+        int rowPos = 0;
+        
         for ( List<Object> row : grid )
         {
             if ( rowLength != null && rowLength != row.size() )
             {
-                throw new IllegalStateException( "Grid rows do not have the same number of cells, previous: " + rowLength + ", this: " + row.size() );
+                throw new IllegalStateException( "Grid rows do not have the same number of cells, previous: " + rowLength + ", this: " + row.size() + ", at row: " + rowPos );
             }
 
+            rowPos++;
             rowLength = row.size();
         }
     }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-06-13 16:56:08 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/EventAnalyticsController.java	2015-06-13 21:26:59 +0000
@@ -91,16 +91,18 @@
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
         @RequestParam( required = false ) boolean showHierarchy,
+        @RequestParam( required = false ) SortOrder sortOrder,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
-        @RequestParam( required = false ) SortOrder sortOrder,
+        @RequestParam( required = false ) boolean aggregateData,
         @RequestParam( required = false ) DisplayProperty displayProperty,
         Model model,
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, 
+            collapseDataDimensions, aggregateData, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.RESPECT_SYSTEM_SETTING );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -123,16 +125,18 @@
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
         @RequestParam( required = false ) boolean showHierarchy,
+        @RequestParam( required = false ) SortOrder sortOrder,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
-        @RequestParam( required = false ) SortOrder sortOrder,
+        @RequestParam( required = false ) boolean aggregateData,
         @RequestParam( required = false ) DisplayProperty displayProperty,
         Model model,
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, 
+            collapseDataDimensions, aggregateData, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xml", false );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -153,16 +157,18 @@
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
         @RequestParam( required = false ) boolean showHierarchy,
+        @RequestParam( required = false ) SortOrder sortOrder,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
-        @RequestParam( required = false ) SortOrder sortOrder,
+        @RequestParam( required = false ) boolean aggregateData,
         @RequestParam( required = false ) DisplayProperty displayProperty,
         Model model,
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, 
+            collapseDataDimensions, aggregateData, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_EXCEL, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.xls", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -183,16 +189,18 @@
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
         @RequestParam( required = false ) boolean showHierarchy,
+        @RequestParam( required = false ) SortOrder sortOrder,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
-        @RequestParam( required = false ) SortOrder sortOrder,
+        @RequestParam( required = false ) boolean aggregateData,
         @RequestParam( required = false ) DisplayProperty displayProperty,
         Model model,
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, 
+            collapseDataDimensions, aggregateData, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_CSV, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.csv", true );
         Grid grid = analyticsService.getAggregatedEventData( params );
@@ -213,16 +221,18 @@
         @RequestParam( required = false ) boolean skipRounding,
         @RequestParam( required = false ) boolean hierarchyMeta,
         @RequestParam( required = false ) boolean showHierarchy,
+        @RequestParam( required = false ) SortOrder sortOrder,
         @RequestParam( required = false ) Integer limit,
         @RequestParam( required = false ) EventOutputType outputType,
         @RequestParam( required = false ) boolean collapseDataDimensions,
-        @RequestParam( required = false ) SortOrder sortOrder,
+        @RequestParam( required = false ) boolean aggregateData,
         @RequestParam( required = false ) DisplayProperty displayProperty,
         Model model,
         HttpServletResponse response ) throws Exception
     {
         EventQueryParams params = analyticsService.getFromUrl( program, stage, startDate, endDate, dimension, filter,
-            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, collapseDataDimensions, displayProperty, i18nManager.getI18nFormat() );
+            value, aggregationType, skipMeta, skipRounding, hierarchyMeta, showHierarchy, sortOrder, limit, outputType, 
+            collapseDataDimensions, aggregateData, displayProperty, i18nManager.getI18nFormat() );
 
         contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_HTML, CacheStrategy.RESPECT_SYSTEM_SETTING, "events.html", false );
         Grid grid = analyticsService.getAggregatedEventData( params );