dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #31571
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16109: Impl method EventAnalyticsService.getAggregatedEventDataMappping
------------------------------------------------------------
revno: 16109
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-07-13 00:07:01 +0200
message:
Impl method EventAnalyticsService.getAggregatedEventDataMappping
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java
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/data/DefaultEventAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java
dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml
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/test/java/org/hisp/dhis/system/grid/GridTest.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-api/src/main/java/org/hisp/dhis/common/Grid.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/Grid.java 2014-07-12 22:07:01 +0000
@@ -299,6 +299,13 @@
Grid substituteMetaData( int columnIndex, Map<Object, Object> metaDataMap );
/**
+ * Returns indexes of the meta grid headers.
+ *
+ * @return List of indexes of meta headers.
+ */
+ List<Integer> getMetaColumnIndexes();
+
+ /**
* Adds a set of headers based on the column names of the given SQL result set.
*
* @param rs the result set.
=== 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 2014-07-12 21:07:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/EventAnalyticsService.java 2014-07-12 22:07:01 +0000
@@ -28,13 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.Map;
import java.util.Set;
import org.hisp.dhis.analytics.SortOrder;
import org.hisp.dhis.common.BaseAnalyticalObject;
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.i18n.I18nFormat;
-import org.hisp.dhis.program.Program;
/**
* @author Lars Helge Overland
@@ -45,6 +45,10 @@
Grid getAggregatedEventData( EventQueryParams params );
+ Map<String, Double> getAggregatedEventDataMappping( EventQueryParams params );
+
+ Map<String, Double> getAggregatedEventDataMappping( BaseAnalyticalObject object, I18nFormat format );
+
Grid getEvents( EventQueryParams params );
/**
@@ -60,5 +64,5 @@
EventQueryParams getFromUrl( String program, String stage, String startDate, String endDate, Set<String> dimension, Set<String> filter,
String ouMode, Set<String> asc, Set<String> desc, boolean skipMeta, boolean hierarchyMeta, boolean coordinatesOnly, Integer page, Integer pageSize, I18nFormat format );
- EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, Program program, I18nFormat format );
+ EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, I18nFormat format );
}
=== 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 2014-07-12 17:11:38 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/event/data/DefaultEventAnalyticsService.java 2014-07-12 22:07:01 +0000
@@ -30,6 +30,7 @@
import static org.hisp.dhis.analytics.AnalyticsService.NAMES_META_KEY;
import static org.hisp.dhis.analytics.AnalyticsService.OU_HIERARCHY_KEY;
+import static org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP;
import static org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID;
import static org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID;
import static org.hisp.dhis.common.DimensionalObjectUtils.getDimensionFromParam;
@@ -46,6 +47,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.analytics.AnalyticsSecurityManager;
import org.hisp.dhis.analytics.AnalyticsService;
import org.hisp.dhis.analytics.SortOrder;
@@ -158,7 +160,7 @@
grid.addHeader( new GridHeader( item.getItem().getUid(), item.getItem().getName(), item.getTypeAsString(), false, true ) );
}
- grid.addHeader( new GridHeader( "value", "Value" ) );
+ grid.addHeader( new GridHeader( "value", "Value", Double.class.getName(), false, false ) );
// ---------------------------------------------------------------------
// Data
@@ -215,6 +217,32 @@
return grid;
}
+
+ public Map<String, Double> getAggregatedEventDataMappping( EventQueryParams params )
+ {
+ Map<String, Double> map = new HashMap<>();
+
+ Grid grid = getAggregatedEventData( params );
+
+ List<Integer> metaIndexes = grid.getMetaColumnIndexes();
+ int valueIndex = grid.getWidth() - 1;
+
+ for ( List<Object> row : grid.getRows() )
+ {
+ String key = StringUtils.join( ListUtils.getAtIndexes( row, metaIndexes ), DIMENSION_SEP );
+ Double value = (Double) row.get( valueIndex );
+ map.put( key, value );
+ }
+
+ return map;
+ }
+
+ public Map<String, Double> getAggregatedEventDataMappping( BaseAnalyticalObject object, I18nFormat format )
+ {
+ EventQueryParams params = getFromAnalyticalObject( object, format );
+
+ return getAggregatedEventDataMappping( params );
+ }
public Grid getEvents( EventQueryParams params )
{
@@ -314,7 +342,7 @@
return params;
}
- public EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, Program program, I18nFormat format )
+ public EventQueryParams getFromAnalyticalObject( BaseAnalyticalObject object, I18nFormat format )
{
EventQueryParams params = new EventQueryParams();
@@ -335,7 +363,7 @@
}
else
{
- params.getItems().add( getQueryItem( dimension.getDimension(), program ) );
+ params.getItems().add( getQueryItem( dimension.getDimension() ) );
}
}
@@ -350,7 +378,7 @@
}
else
{
- params.getItemFilters().add( getQueryItem( filter.getDimension(), program ) );
+ params.getItemFilters().add( getQueryItem( filter.getDimension() ) );
}
}
}
@@ -410,7 +438,7 @@
}
else
{
- params.getItems().add( getQueryItem( dim, pr ) );
+ params.getItems().add( getQueryItem( dim ) );
}
}
}
@@ -429,7 +457,7 @@
}
else
{
- params.getItemFilters().add( getQueryItem( dim, pr ) );
+ params.getItemFilters().add( getQueryItem( dim ) );
}
}
}
@@ -447,7 +475,7 @@
{
for ( String sort : asc )
{
- params.getAsc().add( getSortItem( sort, pr ) );
+ params.getAsc().add( getSortItem( sort ) );
}
}
@@ -455,7 +483,7 @@
{
for ( String sort : desc )
{
- params.getDesc().add( getSortItem( sort, pr ) );
+ params.getDesc().add( getSortItem( sort ) );
}
}
@@ -478,7 +506,7 @@
// Supportive methods
// -------------------------------------------------------------------------
- private QueryItem getQueryItem( String dimension, Program program )
+ private QueryItem getQueryItem( String dimension )
{
String[] split = dimension.split( DimensionalObjectUtils.DIMENSION_NAME_SEP );
@@ -487,7 +515,7 @@
throw new IllegalQueryException( "Query item or filter is invalid: " + dimension );
}
- QueryItem queryItem = getQueryItem( program, split[0] );
+ QueryItem queryItem = getQuryItemFromUid( split[0] );
if ( split.length > 1 ) // Filters specified
{
@@ -562,9 +590,9 @@
return map;
}
- private String getSortItem( String item, Program program )
+ private String getSortItem( String item )
{
- if ( !SORTABLE_ITEMS.contains( item.toLowerCase() ) && getQueryItem( program, item ) == null )
+ if ( !SORTABLE_ITEMS.contains( item.toLowerCase() ) && getQueryItem( item ) == null )
{
throw new IllegalQueryException( "Descending sort item is invalid: " + item );
}
@@ -574,18 +602,18 @@
return item;
}
- private QueryItem getQueryItem( Program program, String item )
+ private QueryItem getQuryItemFromUid( String item )
{
DataElement de = dataElementService.getDataElement( item );
- if ( de != null && program.getAllDataElements().contains( de ) )
+ if ( de != null ) //TODO check if part of program
{
return new QueryItem( de, de.isNumericType() );
}
TrackedEntityAttribute at = attributeService.getTrackedEntityAttribute( item );
- if ( at != null && program.getTrackedEntityAttributes().contains( at ) )
+ if ( at != null )
{
return new QueryItem( at, at.isNumericType() );
}
=== 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 2014-07-12 21:07:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/event/data/EventAnalyticsServiceTest.java 2014-07-12 22:07:01 +0000
@@ -170,7 +170,7 @@
chart.getOrganisationUnits().add( ouA );
chart.getOrganisationUnits().add( ouB );
- EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, prA, null );
+ EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, null );
assertNotNull( params );
assertEquals( 1, params.getItems().size() );
@@ -196,7 +196,7 @@
chart.getOrganisationUnits().add( ouA );
chart.getOrganisationUnits().add( ouB );
- EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, prA, null );
+ EventQueryParams params = analyticsService.getFromAnalyticalObject( chart, null );
assertNotNull( params );
assertEquals( 2, params.getItems().size() );
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-07-12 17:11:38 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java 2014-07-12 22:07:01 +0000
@@ -45,6 +45,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -55,10 +56,12 @@
import org.apache.commons.math.analysis.UnivariateRealInterpolator;
import org.apache.commons.math.stat.regression.SimpleRegression;
import org.hisp.dhis.analytics.AnalyticsService;
+import org.hisp.dhis.analytics.event.EventAnalyticsService;
import org.hisp.dhis.chart.BaseChart;
import org.hisp.dhis.chart.Chart;
import org.hisp.dhis.chart.ChartService;
import org.hisp.dhis.common.AnalyticalObjectStore;
+import org.hisp.dhis.common.AnalyticsType;
import org.hisp.dhis.common.DimensionalObject;
import org.hisp.dhis.common.NameableObject;
import org.hisp.dhis.dataelement.DataElement;
@@ -182,6 +185,13 @@
this.analyticsService = analyticsService;
}
+ private EventAnalyticsService eventAnalyticsService;
+
+ public void setEventAnalyticsService( EventAnalyticsService eventAnalyticsService )
+ {
+ this.eventAnalyticsService = eventAnalyticsService;
+ }
+
// -------------------------------------------------------------------------
// ChartService implementation
// -------------------------------------------------------------------------
@@ -714,7 +724,16 @@
private CategoryDataset[] getCategoryDataSet( BaseChart chart )
{
- Map<String, Double> valueMap = analyticsService.getAggregatedDataValueMapping( chart, chart.getFormat() );
+ Map<String, Double> valueMap = new HashMap<>();
+
+ if ( chart.isAnalyticsType( AnalyticsType.AGGREGATE ) )
+ {
+ valueMap = analyticsService.getAggregatedDataValueMapping( chart, chart.getFormat() );
+ }
+ else if ( chart.isAnalyticsType( AnalyticsType.EVENT ) )
+ {
+ valueMap = eventAnalyticsService.getAggregatedEventDataMappping( chart, chart.getFormat() );
+ }
DefaultCategoryDataset regularDataSet = new DefaultCategoryDataset();
DefaultCategoryDataset regressionDataSet = new DefaultCategoryDataset();
=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2014-07-11 21:22:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/resources/META-INF/dhis/beans.xml 2014-07-12 22:07:01 +0000
@@ -53,6 +53,7 @@
<property name="currentUserService" ref="org.hisp.dhis.user.CurrentUserService" />
<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
<property name="analyticsService" ref="org.hisp.dhis.analytics.AnalyticsService" />
+ <property name="eventAnalyticsService" ref="org.hisp.dhis.analytics.event.EventAnalyticsService" />
</bean>
<!-- Document -->
=== 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 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java 2014-07-12 22:07:01 +0000
@@ -656,7 +656,24 @@
return this;
}
-
+
+ public List<Integer> getMetaColumnIndexes()
+ {
+ List<Integer> indexes = new ArrayList<>();
+
+ for ( int i = 0; i < headers.size(); i++ )
+ {
+ GridHeader header = headers.get( i );
+
+ if ( header != null && header.isMeta() )
+ {
+ indexes.add( i );
+ }
+ }
+
+ return indexes;
+ }
+
// -------------------------------------------------------------------------
// JRDataSource implementation
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/grid/GridTest.java 2014-07-12 22:07:01 +0000
@@ -560,6 +560,16 @@
}
@Test
+ public void testGetMetaColumnIndexes()
+ {
+ List<Integer> expected = new ArrayList<>();
+ expected.add( 0 );
+ expected.add( 1 );
+
+ assertEquals( expected, gridA.getMetaColumnIndexes() );
+ }
+
+ @Test
public void testJRDataSource() throws Exception
{
assertTrue( gridA.next() );