dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #36909
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18878: Analytics, using fixed dimension indexes when getting aggregated data for indicators
------------------------------------------------------------
revno: 18878
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-04-10 12:38:22 +0200
message:
Analytics, using fixed dimension indexes when getting aggregated data for indicators
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
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.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-04-10 08:32:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2015-04-10 10:38:22 +0000
@@ -97,6 +97,9 @@
public static final String DISPLAY_NAME_PROGRAM_INDICATOR = "Program indicator";
public static final String DISPLAY_NAME_LONGITUDE = "Longitude";
public static final String DISPLAY_NAME_LATITUDE = "Latitude";
+
+ public static final int DE_IN_INDEX = 0;
+ public static final int CO_IN_INDEX = 1;
public static final List<String> DATA_DIMS = Arrays.asList( INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATAELEMENT_OPERAND_ID, DATASET_DIM_ID );
public static final List<String> FIXED_DIMS = Arrays.asList( DATA_X_DIM_ID, INDICATOR_DIM_ID, DATAELEMENT_DIM_ID, DATASET_DIM_ID, PERIOD_DIM_ID, ORGUNIT_DIM_ID );
@@ -941,10 +944,10 @@
/**
* Returns 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.
+ * aggregated values. The data element dimension will be at index 0 and the
+ * category option combo dimension will be at index 1.
*/
- public static Map<String, Map<DataElementOperand, Double>> getPermutationOperandValueMap(
- Map<String, Double> aggregatedDataMap, DataQueryParams params )
+ public static Map<String, Map<DataElementOperand, Double>> getPermutationOperandValueMap( Map<String, Double> aggregatedDataMap )
{
MapMap<String, DataElementOperand, Double> valueMap = new MapMap<>();
@@ -952,15 +955,12 @@
{
List<String> keys = new ArrayList<>( Arrays.asList( key.split( DIMENSION_SEP ) ) );
- int deInx = params.getDataElementDimensionIndex();
- int cocInx = params.getCategoryOptionComboDimensionIndex();
-
- String de = keys.get( deInx );
- String coc = cocInx != -1 ? keys.get( cocInx ) : null;
+ String de = keys.get( DE_IN_INDEX );
+ String coc = keys.get( CO_IN_INDEX );
DataElementOperand operand = new DataElementOperand( de, coc );
- ListUtils.removeAll( keys, deInx, cocInx );
+ ListUtils.removeAll( keys, DE_IN_INDEX, CO_IN_INDEX );
String permKey = StringUtils.join( keys, DIMENSION_SEP );
=== 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-04-10 08:32:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2015-04-10 10:38:22 +0000
@@ -298,7 +298,7 @@
List<List<DimensionItem>> dimensionItemPermutations = params.getDimensionItemPermutations();
- Map<String, Map<DataElementOperand, Double>> permutationOperandValueMap = getPermutationOperandValueMap( params, indicatorIndex );
+ Map<String, Map<DataElementOperand, Double>> permutationOperandValueMap = getPermutationOperandValueMap( params );
Map<String, Double> constantMap = constantService.getConstantMap();
@@ -1222,15 +1222,14 @@
* aggregated values.
*
* @param params the data query parameters.
- * @param indicatorIndex the indicator dimension index for the given parameters.
*/
- private Map<String, Map<DataElementOperand, Double>> getPermutationOperandValueMap( DataQueryParams params, int indicatorIndex )
+ private Map<String, Map<DataElementOperand, Double>> getPermutationOperandValueMap( DataQueryParams params )
{
- DataQueryParams dataSourceParams = getQueryIndicatorsReplacedByDataElements( params, indicatorIndex );
+ DataQueryParams dataSourceParams = getQueryIndicatorsReplacedByDataElements( params );
Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams );
- return DataQueryParams.getPermutationOperandValueMap( aggregatedDataMap, dataSourceParams );
+ return DataQueryParams.getPermutationOperandValueMap( aggregatedDataMap );
}
/**
@@ -1241,15 +1240,17 @@
* @param indicatorIndex the index of the indicator dimension in the given query.
* @return the data query parameters.
*/
- private DataQueryParams getQueryIndicatorsReplacedByDataElements( DataQueryParams params, int indicatorIndex )
+ private DataQueryParams getQueryIndicatorsReplacedByDataElements( DataQueryParams params )
{
- DataQueryParams dataSourceParams = params.instance().removeDimensions( DATAELEMENT_DIM_ID, DATASET_DIM_ID );
-
- List<Indicator> indicators = asTypedList( dataSourceParams.getIndicators() );
+ List<Indicator> indicators = asTypedList( params.getIndicators() );
List<NameableObject> dataElements = asList( expressionService.getDataElementsInIndicators( indicators ) );
- dataSourceParams.getDimensions().set( indicatorIndex, new BaseDimensionalObject( DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) );
- dataSourceParams.enableCategoryOptionCombos();
+ DataQueryParams dataSourceParams = params.instance().removeDimensions( DATAELEMENT_DIM_ID, DATASET_DIM_ID, INDICATOR_DIM_ID );
+
+ dataSourceParams.getDimensions().add( DataQueryParams.DE_IN_INDEX, new BaseDimensionalObject(
+ DATAELEMENT_DIM_ID, DimensionType.DATAELEMENT, dataElements ) );
+ dataSourceParams.getDimensions().add( DataQueryParams.CO_IN_INDEX, new BaseDimensionalObject(
+ CATEGORYOPTIONCOMBO_DIM_ID, DimensionType.CATEGORY_OPTION_COMBO, new ArrayList<NameableObject>() ) );
return dataSourceParams;
}
=== 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-04-09 19:08:39 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/test/java/org/hisp/dhis/analytics/data/QueryPlannerTest.java 2015-04-10 10:38:22 +0000
@@ -249,6 +249,10 @@
assertEquals( pesB, paramsB.getPeriods() );
}
+ /**
+ * Data element dimension must be at index 0 and category option combo
+ * dimension must be at index 1 in map.
+ */
@Test
public void testGetPermutationOperandValueMap()
{
@@ -259,16 +263,16 @@
params.enableCategoryOptionCombos();
Map<String, Double> aggregatedDataMap = new HashMap<>();
- aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1" + DIMENSION_SEP + coc.getUid(), 1d );
- aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2" + DIMENSION_SEP + coc.getUid(), 2d );
- aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1" + DIMENSION_SEP + coc.getUid(), 3d );
- aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2" + DIMENSION_SEP + coc.getUid(), 4d );
- aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1" + DIMENSION_SEP + coc.getUid(), 5d );
- aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2" + DIMENSION_SEP + coc.getUid(), 6d );
- aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1" + DIMENSION_SEP + coc.getUid(), 7d );
- aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2" + DIMENSION_SEP + coc.getUid(), 8d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 1d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 2d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 3d );
+ aggregatedDataMap.put( deA.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 4d );
+ aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", 5d );
+ aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", 6d );
+ aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", 7d );
+ aggregatedDataMap.put( deB.getUid() + DIMENSION_SEP + coc.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", 8d );
- Map<String, Map<DataElementOperand, Double>> permutationMap = DataQueryParams.getPermutationOperandValueMap( aggregatedDataMap, params );
+ Map<String, Map<DataElementOperand, Double>> permutationMap = DataQueryParams.getPermutationOperandValueMap( aggregatedDataMap );
assertNotNull( permutationMap );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2015-04-08 15:29:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2015-04-10 10:38:22 +0000
@@ -108,7 +108,6 @@
@SuppressWarnings( "unchecked" )
public Collection<OrganisationUnit> getByCodes( Collection<String> codes )
{
-
if ( codes == null || codes.isEmpty() )
{
return new ArrayList<>();