Search in sources :

Example 1 with AnalyticsManager

use of org.hisp.dhis.analytics.AnalyticsManager in project dhis2-core by dhis2.

the class AnalyticsManagerTest method testReplaceDataPeriodsWithAggregationPeriods.

@Test
void testReplaceDataPeriodsWithAggregationPeriods() {
    AnalyticsManager analyticsManager = new JdbcAnalyticsManager(queryPlanner, jdbcTemplate, executionPlanStore);
    Period y2012 = createPeriod("2012");
    AnalyticsAggregationType aggregationType = new AnalyticsAggregationType(AggregationType.SUM, AggregationType.AVERAGE, DataType.NUMERIC, true);
    DataQueryParams params = DataQueryParams.newBuilder().withDataElements(getList(createDataElement('A'), createDataElement('B'))).withPeriods(getList(y2012)).withOrganisationUnits(getList(createOrganisationUnit('A'))).withDataPeriodType(new YearlyPeriodType()).withAggregationType(aggregationType).build();
    Map<String, Object> dataValueMap = new HashMap<>();
    dataValueMap.put(BASE_UID + "A-2012-" + BASE_UID + "A", 1d);
    dataValueMap.put(BASE_UID + "B-2012-" + BASE_UID + "A", 1d);
    ListMap<DimensionalItemObject, DimensionalItemObject> dataPeriodAggregationPeriodMap = new ListMap<>();
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q1"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q2"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q3"));
    dataPeriodAggregationPeriodMap.putValue(y2012, createPeriod("2012Q4"));
    analyticsManager.replaceDataPeriodsWithAggregationPeriods(dataValueMap, params, dataPeriodAggregationPeriodMap);
    assertEquals(8, dataValueMap.size());
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q1-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q2-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q3-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "A-2012Q4-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q1-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q2-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q3-" + BASE_UID + "A"));
    assertTrue(dataValueMap.keySet().contains(BASE_UID + "B-2012Q4-" + BASE_UID + "A"));
}
Also used : HashMap(java.util.HashMap) Period(org.hisp.dhis.period.Period) YearlyPeriodType(org.hisp.dhis.period.YearlyPeriodType) ListMap(org.hisp.dhis.common.ListMap) AnalyticsAggregationType(org.hisp.dhis.analytics.AnalyticsAggregationType) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) AnalyticsManager(org.hisp.dhis.analytics.AnalyticsManager) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DhisConvenienceTest(org.hisp.dhis.DhisConvenienceTest)

Aggregations

HashMap (java.util.HashMap)1 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)1 AnalyticsAggregationType (org.hisp.dhis.analytics.AnalyticsAggregationType)1 AnalyticsManager (org.hisp.dhis.analytics.AnalyticsManager)1 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)1 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)1 ListMap (org.hisp.dhis.common.ListMap)1 Period (org.hisp.dhis.period.Period)1 YearlyPeriodType (org.hisp.dhis.period.YearlyPeriodType)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1