dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #41969
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21431: Analytics. Impl analytics support for using program indicators, program data elements and program...
------------------------------------------------------------
revno: 21431
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2015-12-12 14:24:38 +0100
message:
Analytics. Impl analytics support for using program indicators, program data elements and program attributes in aggregate indicators. These can be used in combination with aggregate data elements. This allows for indicators where e.g. the numerator is collected as aggregate data, such as population, and the numerator is collected as events, such as inpatient cases.
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-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.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 2015-12-10 09:51:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-12-12 13:24:38 +0000
@@ -1003,20 +1003,22 @@
// -------------------------------------------------------------------------
/**
- * Populates a mapping of permutation keys and mappings of data element operands
+ * Creates a mapping of permutation keys and mappings of data element operands
* and values based on the given mapping of dimension option keys and
* aggregated values. The data element dimension will be at index 0 and the
* category option combo dimension will be at index 1, if category option
* combinations is enabled.
*
- * @param permutationMap the map to populate with permutations.
* @param aggregatedDataMap the aggregated data map.
* @param cocEnabled indicates whether the given aggregated data map includes
* a category option combination dimension.
+ * @return a mapping of permutation keys and mappings of data element operands
+ * and values.
*/
- public static void putPermutationDimensionalItemValueMap( MapMap<String, DimensionalItemObject, Double> permutationMap,
- Map<String, Double> aggregatedDataMap, boolean cocEnabled )
+ public static MapMap<String, DimensionalItemObject, Double> getPermutationDimensionalItemValueMap( Map<String, Double> aggregatedDataMap )
{
+ MapMap<String, DimensionalItemObject, Double> permutationMap = new MapMap<>();
+
for ( String key : aggregatedDataMap.keySet() )
{
List<String> keys = Lists.newArrayList( key.split( DIMENSION_SEP ) );
@@ -1033,6 +1035,8 @@
permutationMap.putEntry( permKey, dimItemObject, value );
}
+
+ return permutationMap;
}
/**
=== 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 2015-12-10 11:32:45 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-12-12 13:24:38 +0000
@@ -41,7 +41,6 @@
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.IdentifiableObjectUtils.getLocalPeriodIdentifiers;
-import static org.hisp.dhis.common.DimensionalObjectUtils.asList;
import static org.hisp.dhis.common.DimensionalObjectUtils.asTypedList;
import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap;
import static org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap;
@@ -87,7 +86,6 @@
import org.hisp.dhis.common.Grid;
import org.hisp.dhis.common.GridHeader;
import org.hisp.dhis.common.IdentifiableObjectUtils;
-import org.hisp.dhis.common.MapMap;
import org.hisp.dhis.common.NameableObjectUtils;
import org.hisp.dhis.commons.collection.ListUtils;
import org.hisp.dhis.commons.util.DebugUtils;
@@ -872,72 +870,38 @@
*/
private Map<String, Map<DimensionalItemObject, Double>> getPermutationDimensionalItemValueMap( DataQueryParams params )
{
- Map<String, Double> aggregatedDataTotalsMap = getAggregatedDataValueMapTotals( params );
- Map<String, Double> aggregatedDataOptionCombosMap = getAggregatedDataValueMapOptionCombos( params );
-
- MapMap<String, DimensionalItemObject, Double> permOperandValueMap = new MapMap<>();
-
- DataQueryParams.putPermutationDimensionalItemValueMap( permOperandValueMap, aggregatedDataTotalsMap, false );
- DataQueryParams.putPermutationDimensionalItemValueMap( permOperandValueMap, aggregatedDataOptionCombosMap, true );
-
- return permOperandValueMap;
- }
-
- /**
- * Returns a mapping of dimension keys and aggregated values for the data
- * element totals part of the indicators in the given query.
- *
- * @param params the data query parameters.
- * @return a mapping of dimension keys and aggregated values.
- */
- private Map<String, Double> getAggregatedDataValueMapTotals( DataQueryParams params )
- {
- List<Indicator> indicators = asTypedList( params.getIndicators() );
- List<DimensionalItemObject> dataElements = asList( expressionService.getDataElementTotalsInIndicators( indicators ) );
-
- if ( !dataElements.isEmpty() )
- {
- DataQueryParams dataSourceParams = params.instance().removeDimension( DATA_X_DIM_ID );
-
- dataSourceParams.getDimensions().add( DX_INDEX, new BaseDimensionalObject(
- DATA_X_DIM_ID, DimensionType.DATA_X, dataElements ) );
-
- return getAggregatedDataValueMap( dataSourceParams );
- }
-
- return new HashMap<>();
- }
-
- /**
- * Returns a mapping of dimension keys and aggregated values for the data
- * elements with category option combinations part of the indicators in the
- * given query.
- *
- * @param params the data query parameters.
- * @return a mapping of dimension keys and aggregated values.
- */
- private Map<String, Double> getAggregatedDataValueMapOptionCombos( DataQueryParams params )
- {
- List<Indicator> indicators = asTypedList( params.getIndicators() );
- List<DimensionalItemObject> dataElements = asList( expressionService.getDataElementWithOptionCombosInIndicators( indicators ) );
-
- if ( !dataElements.isEmpty() )
- {
- DataQueryParams dataSourceParams = params.instance().removeDimension( DATA_X_DIM_ID );
-
- dataSourceParams.getDimensions().add( DataQueryParams.DX_INDEX, new BaseDimensionalObject(
- DATA_X_DIM_ID, DimensionType.DATA_X, dataElements ) );
- dataSourceParams.getDimensions().add( DataQueryParams.CO_INDEX, new BaseDimensionalObject(
- CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<>() ) );
-
- Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams );
-
- return AnalyticsUtils.convertDxToOperand( aggregatedDataMap );
- }
-
- return new HashMap<>();
- }
-
+ List<Indicator> indicators = asTypedList( params.getIndicators() );
+
+ Map<String, Double> valueMap = getAggregatedDataValueMap( params, indicators );
+
+ return DataQueryParams.getPermutationDimensionalItemValueMap( valueMap );
+ }
+
+ /**
+ * Returns a mapping between dimension items and values for the given data
+ * query and list of indicators. The dimensional items part of the indicator
+ * numerators and denominators are used as dimensional item for the aggregated
+ * values being retrieved.
+ *
+ * @param params the query.
+ * @param indicators the list of indicators.
+ * @return a dimensional items to aggregate values map.
+ */
+ private Map<String, Double> getAggregatedDataValueMap( DataQueryParams params, List<Indicator> indicators )
+ {
+ List<DimensionalItemObject> items = Lists.newArrayList( expressionService.getDimensionalItemObjectsInIndicators( indicators ) );
+
+ DimensionalObject dimension = new BaseDimensionalObject( DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, null, DISPLAY_NAME_DATA_X, items );
+
+ DataQueryParams dataSourceParams = params.instance();
+ dataSourceParams.removeDimension( DimensionalObject.DATA_X_DIM_ID );
+ dataSourceParams.addDimension( dimension );
+
+ Grid grid = getAggregatedDataValueGridInternal( dataSourceParams );
+
+ return grid.getAsMap( grid.getWidth() - 1, DimensionalObject.DIMENSION_SEP );
+ }
+
/**
* Returns a mapping between identifiers and names for the given dimensional
* objects.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2015-12-10 09:51:53 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2015-12-12 13:24:38 +0000
@@ -254,9 +254,7 @@
aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 7d );
aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 8d );
- MapMap<String, DimensionalItemObject, Double> permutationMap = new MapMap<>();
-
- DataQueryParams.putPermutationDimensionalItemValueMap( permutationMap, aggregatedDataMap, true );
+ MapMap<String, DimensionalItemObject, Double> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap( aggregatedDataMap );
assertNotNull( permutationMap );
@@ -313,10 +311,8 @@
aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", 7d );
aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", 8d );
- MapMap<String, DimensionalItemObject, Double> permutationMap = new MapMap<>();
-
- DataQueryParams.putPermutationDimensionalItemValueMap( permutationMap, aggregatedDataMap, false );
-
+ MapMap<String, DimensionalItemObject, Double> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap( aggregatedDataMap );
+
assertNotNull( permutationMap );
String ouAM1Key = ouA.getUid() + DIMENSION_SEP + "200101";
@@ -362,22 +358,18 @@
@Test
public void testGetPermutationDimensionalItemValueMap()
{
- Map<String, Double> aggregatedTotalsDataMap = new HashMap<>();
- aggregatedTotalsDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 1d );
- aggregatedTotalsDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 2d );
- aggregatedTotalsDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 3d );
- aggregatedTotalsDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 4d );
-
- Map<String, Double> aggregatedCocDataMap = new HashMap<>();
- aggregatedCocDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 5d );
- aggregatedCocDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 6d );
- aggregatedCocDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 7d );
- aggregatedCocDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 8d );
-
- MapMap<String, DimensionalItemObject, Double> permutationMap = new MapMap<>();
-
- DataQueryParams.putPermutationDimensionalItemValueMap( permutationMap, aggregatedTotalsDataMap, false );
- DataQueryParams.putPermutationDimensionalItemValueMap( permutationMap, aggregatedCocDataMap, true );
+ Map<String, Double> aggregatedDataMap = new HashMap<>();
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 1d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 2d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 3d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 4d );
+
+ aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 5d );
+ aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 6d );
+ aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 7d );
+ aggregatedDataMap.put( deB.getUid() + COMPOSITE_DIM_OBJECT_PLAIN_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 8d );
+
+ MapMap<String, DimensionalItemObject, Double> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap( aggregatedDataMap );
assertNotNull( permutationMap );