Search in sources :

Example 6 with DimensionItemObjectValue

use of org.hisp.dhis.common.DimensionItemObjectValue in project dhis2-core by dhis2.

the class QueryPlannerTest method testGetPermutationDimensionalItemValueMapCocDisabled.

@Test
void testGetPermutationDimensionalItemValueMapCocDisabled() {
    MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 1d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 2d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deA, 3d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deA, 4d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 5d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 6d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200101", new DimensionItemObjectValue(deB, 7d));
    aggregatedDataMap.put(deB.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "200102", new DimensionItemObjectValue(deB, 8d));
    Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
    assertNotNull(permutationMap);
    String ouAM1Key = ouA.getUid() + DIMENSION_SEP + "200101";
    String ouAM2Key = ouA.getUid() + DIMENSION_SEP + "200102";
    String ouBM1Key = ouB.getUid() + DIMENSION_SEP + "200101";
    String ouBM2Key = ouB.getUid() + DIMENSION_SEP + "200102";
    List<DimensionItemObjectValue> ouAM1 = permutationMap.get(ouAM1Key);
    List<DimensionItemObjectValue> ouAM2 = permutationMap.get(ouAM2Key);
    List<DimensionItemObjectValue> ouBM1 = permutationMap.get(ouBM1Key);
    List<DimensionItemObjectValue> ouBM2 = permutationMap.get(ouBM2Key);
    assertEquals(2, ouAM1.size());
    assertEquals(2, ouAM2.size());
    assertEquals(2, ouBM1.size());
    assertEquals(2, ouBM2.size());
    List<DimensionItemObjectValue> ouAM1Expected = new ArrayList<>();
    ouAM1Expected.add(new DimensionItemObjectValue(deA, 1d));
    ouAM1Expected.add(new DimensionItemObjectValue(deB, 5d));
    List<DimensionItemObjectValue> ouAM2Expected = new ArrayList<>();
    ouAM2Expected.add(new DimensionItemObjectValue(deA, 2d));
    ouAM2Expected.add(new DimensionItemObjectValue(deB, 6d));
    List<DimensionItemObjectValue> ouBM1Expected = new ArrayList<>();
    ouBM1Expected.add(new DimensionItemObjectValue(deA, 3d));
    ouBM1Expected.add(new DimensionItemObjectValue(deB, 7d));
    List<DimensionItemObjectValue> ouBM2Expected = new ArrayList<>();
    ouBM2Expected.add(new DimensionItemObjectValue(deA, 4d));
    ouBM2Expected.add(new DimensionItemObjectValue(deB, 8d));
    assertCollectionsMatch(ouAM1Expected, ouAM1);
    assertCollectionsMatch(ouAM2Expected, ouAM2);
    assertCollectionsMatch(ouBM1Expected, ouBM1);
    assertCollectionsMatch(ouBM2Expected, ouBM2);
}
Also used : ArrayList(java.util.ArrayList) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with DimensionItemObjectValue

use of org.hisp.dhis.common.DimensionItemObjectValue in project dhis2-core by dhis2.

the class QueryPlannerTest method assertCollectionsMatch.

private void assertCollectionsMatch(List<DimensionItemObjectValue> collection, final List<DimensionItemObjectValue> in) {
    Function<String, Double> findValueByUid = (String uid) -> in.stream().filter(v -> v.getDimensionalItemObject().getUid().equals(uid)).findFirst().get().getValue();
    for (DimensionItemObjectValue dimensionItemObjectValue : collection) {
        final Double val = findValueByUid.apply(dimensionItemObjectValue.getDimensionalItemObject().getUid());
        assertEquals(val, dimensionItemObjectValue.getValue());
    }
}
Also used : ReportingRate(org.hisp.dhis.common.ReportingRate) Arrays(java.util.Arrays) CategoryService(org.hisp.dhis.category.CategoryService) ValueType(org.hisp.dhis.common.ValueType) COMPOSITE_DIM_OBJECT_PLAIN_SEP(org.hisp.dhis.common.DimensionalObjectUtils.COMPOSITE_DIM_OBJECT_PLAIN_SEP) DataType(org.hisp.dhis.analytics.DataType) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Autowired(org.springframework.beans.factory.annotation.Autowired) OrganisationUnitService(org.hisp.dhis.organisationunit.OrganisationUnitService) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DIMENSION_SEP(org.hisp.dhis.common.DimensionalObject.DIMENSION_SEP) Map(java.util.Map) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue) AnalyticsTableType(org.hisp.dhis.analytics.AnalyticsTableType) Period(org.hisp.dhis.period.Period) MultiValuedMap(org.apache.commons.collections4.MultiValuedMap) PERIOD_DIM_ID(org.hisp.dhis.common.DimensionalObject.PERIOD_DIM_ID) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalObject(org.hisp.dhis.common.DimensionalObject) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) CategoryCombo(org.hisp.dhis.category.CategoryCombo) DimensionItem(org.hisp.dhis.analytics.DimensionItem) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ORGUNIT_DIM_ID(org.hisp.dhis.common.DimensionalObject.ORGUNIT_DIM_ID) ListMap(org.hisp.dhis.common.ListMap) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DataElementService(org.hisp.dhis.dataelement.DataElementService) DataSet(org.hisp.dhis.dataset.DataSet) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) DateUtils.parseDate(org.hisp.dhis.util.DateUtils.parseDate) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) Function(java.util.function.Function) Program(org.hisp.dhis.program.Program) ArrayList(java.util.ArrayList) DataElement(org.hisp.dhis.dataelement.DataElement) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Lists(com.google.common.collect.Lists) QuarterlyPeriodType(org.hisp.dhis.period.QuarterlyPeriodType) IdentifiableObjectManager(org.hisp.dhis.common.IdentifiableObjectManager) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Indicator(org.hisp.dhis.indicator.Indicator) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DataElementGroupSet(org.hisp.dhis.dataelement.DataElementGroupSet) IndicatorType(org.hisp.dhis.indicator.IndicatorType) Partitions(org.hisp.dhis.analytics.Partitions) Iterator(java.util.Iterator) QueryPlanner(org.hisp.dhis.analytics.QueryPlanner) AggregationType(org.hisp.dhis.analytics.AggregationType) QueryModifiers(org.hisp.dhis.common.QueryModifiers) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) QueryPlannerParams(org.hisp.dhis.analytics.QueryPlannerParams) DhisSpringTest(org.hisp.dhis.DhisSpringTest) PeriodType(org.hisp.dhis.period.PeriodType) DataSetService(org.hisp.dhis.dataset.DataSetService) DataElementGroup(org.hisp.dhis.dataelement.DataElementGroup) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue)

Example 8 with DimensionItemObjectValue

use of org.hisp.dhis.common.DimensionItemObjectValue in project dhis2-core by dhis2.

the class QueryPlannerTest method testGetPermutationDimensionalItemValueMap.

@Test
void testGetPermutationDimensionalItemValueMap() {
    MultiValuedMap<String, DimensionItemObjectValue> aggregatedDataMap = new ArrayListValuedHashMap<>();
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 1d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouA.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 2d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q1", new DimensionItemObjectValue(deA, 3d));
    aggregatedDataMap.put(deA.getUid() + DIMENSION_SEP + ouB.getUid() + DIMENSION_SEP + "2000Q2", new DimensionItemObjectValue(deA, 4d));
    aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q1"), new DimensionItemObjectValue(deB, 5d));
    aggregatedDataMap.put(makeKey(deB, coc, ouA, "2000Q2"), new DimensionItemObjectValue(deB, 6d));
    aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q1"), new DimensionItemObjectValue(deB, 7d));
    aggregatedDataMap.put(makeKey(deB, coc, ouB, "2000Q2"), new DimensionItemObjectValue(deB, 8d));
    Map<String, List<DimensionItemObjectValue>> permutationMap = DataQueryParams.getPermutationDimensionalItemValueMap(aggregatedDataMap);
    assertNotNull(permutationMap);
    String ouAQ1Key = ouA.getUid() + DIMENSION_SEP + "2000Q1";
    String ouAQ2Key = ouA.getUid() + DIMENSION_SEP + "2000Q2";
    String ouBQ1Key = ouB.getUid() + DIMENSION_SEP + "2000Q1";
    String ouBQ2Key = ouB.getUid() + DIMENSION_SEP + "2000Q2";
    List<DimensionItemObjectValue> ouAQ1 = permutationMap.get(ouAQ1Key);
    List<DimensionItemObjectValue> ouAQ2 = permutationMap.get(ouAQ2Key);
    List<DimensionItemObjectValue> ouBQ1 = permutationMap.get(ouBQ1Key);
    List<DimensionItemObjectValue> ouBQ2 = permutationMap.get(ouBQ2Key);
    assertEquals(2, ouAQ1.size());
    assertEquals(2, ouAQ2.size());
    assertEquals(2, ouBQ1.size());
    assertEquals(2, ouBQ2.size());
    List<DimensionItemObjectValue> ouAQ1Expected = new ArrayList<>();
    ouAQ1Expected.add(new DimensionItemObjectValue(deA, 1d));
    ouAQ1Expected.add(new DimensionItemObjectValue(deB, 5d));
    List<DimensionItemObjectValue> ouAQ2Expected = new ArrayList<>();
    ouAQ2Expected.add(new DimensionItemObjectValue(deA, 2d));
    ouAQ2Expected.add(new DimensionItemObjectValue(deB, 6d));
    List<DimensionItemObjectValue> ouBQ1Expected = new ArrayList<>();
    ouBQ1Expected.add(new DimensionItemObjectValue(deA, 3d));
    ouBQ1Expected.add(new DimensionItemObjectValue(deB, 7d));
    List<DimensionItemObjectValue> ouBQ2Expected = new ArrayList<>();
    ouBQ2Expected.add(new DimensionItemObjectValue(deA, 4d));
    ouBQ2Expected.add(new DimensionItemObjectValue(deB, 8d));
    assertCollectionsMatch(ouAQ1Expected, ouAQ1);
    assertCollectionsMatch(ouAQ2Expected, ouAQ2);
    assertCollectionsMatch(ouBQ1Expected, ouBQ1);
    assertCollectionsMatch(ouBQ2Expected, ouBQ2);
}
Also used : ArrayList(java.util.ArrayList) DimensionItemObjectValue(org.hisp.dhis.common.DimensionItemObjectValue) List(java.util.List) ArrayList(java.util.ArrayList) DimensionalObjectUtils.getList(org.hisp.dhis.common.DimensionalObjectUtils.getList) ArrayListValuedHashMap(org.apache.commons.collections4.multimap.ArrayListValuedHashMap) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

DimensionItemObjectValue (org.hisp.dhis.common.DimensionItemObjectValue)8 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ArrayListValuedHashMap (org.apache.commons.collections4.multimap.ArrayListValuedHashMap)5 DimensionalObjectUtils.getList (org.hisp.dhis.common.DimensionalObjectUtils.getList)5 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 Test (org.junit.jupiter.api.Test)4 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)3 DimensionalObject (org.hisp.dhis.common.DimensionalObject)3 HashMap (java.util.HashMap)2 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)2 AnalyticsUtils.getRoundedValueObject (org.hisp.dhis.analytics.util.AnalyticsUtils.getRoundedValueObject)2 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)2 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 Arrays (java.util.Arrays)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1