Search in sources :

Example 86 with BaseDimensionalObject

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

the class AnalyticsServiceReportingRateTest method verifyNullValueIsZeroForReportingRate.

@Test
void verifyNullValueIsZeroForReportingRate() {
    double expectedReports = 100D;
    DataSet dataSetA = createDataSet('A');
    ReportingRate reportingRateA = new ReportingRate(dataSetA);
    reportingRateA.setMetric(ReportingRateMetric.REPORTING_RATE);
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate()));
    OrganisationUnit ou = new OrganisationUnit("aaaa");
    DataQueryParams params = DataQueryParams.newBuilder().withOrganisationUnit(ou).withDataElements(newArrayList(reportingRateA)).withIgnoreLimit(true).withFilters(singletonList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods))).build();
    initMock(params);
    when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS), eq(0))).thenReturn(// NO
    CompletableFuture.completedFuture(null));
    // VALUES
    Map<String, Object> reportingRate = new HashMap<>();
    reportingRate.put(dataSetA.getUid() + "-" + ou.getUid(), expectedReports);
    when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS_TARGET), eq(0))).thenReturn(CompletableFuture.completedFuture(reportingRate));
    Grid grid = target.getAggregatedDataValueGrid(params);
    assertEquals(0D, getValueFromGrid(grid.getRows(), makeKey(dataSetA, ReportingRateMetric.REPORTING_RATE)).get(), 0);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) HashMap(java.util.HashMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Example 87 with BaseDimensionalObject

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

the class AnalyticsServiceReportingRateTest method verifyNullTargetIsNullForReportingRate.

@Test
void verifyNullTargetIsNullForReportingRate() {
    DataSet dataSetA = createDataSet('A');
    ReportingRate reportingRateA = new ReportingRate(dataSetA);
    reportingRateA.setMetric(ReportingRateMetric.REPORTING_RATE);
    List<DimensionalItemObject> periods = new ArrayList<>();
    periods.add(new MonthlyPeriodType().createPeriod(new DateTime(2014, 1, 1, 0, 0).toDate()));
    OrganisationUnit ou = new OrganisationUnit("aaaa");
    DataQueryParams params = DataQueryParams.newBuilder().withOrganisationUnit(ou).withDataElements(newArrayList(reportingRateA)).withIgnoreLimit(true).withFilters(singletonList(new BaseDimensionalObject("pe", DimensionType.PERIOD, periods))).build();
    initMock(params);
    Map<String, Object> actualReports = new HashMap<>();
    actualReports.put(dataSetA.getUid() + "-" + ou.getUid(), 500D);
    when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS), eq(0))).thenReturn(CompletableFuture.completedFuture(actualReports));
    when(analyticsManager.getAggregatedDataValues(any(DataQueryParams.class), eq(AnalyticsTableType.COMPLETENESS_TARGET), eq(0))).thenReturn(// NO
    CompletableFuture.completedFuture(null));
    // TARGET
    // RETURNED
    Grid grid = target.getAggregatedDataValueGrid(params);
    assertNull(getValueFromGrid(grid.getRows(), makeKey(dataSetA, ReportingRateMetric.REPORTING_RATE)).orElse(null));
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) ReportingRate(org.hisp.dhis.common.ReportingRate) HashMap(java.util.HashMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Grid(org.hisp.dhis.common.Grid) ArrayList(java.util.ArrayList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) DateTime(org.joda.time.DateTime) DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) MonthlyPeriodType(org.hisp.dhis.period.MonthlyPeriodType) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test)

Example 88 with BaseDimensionalObject

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

the class JdbcAnalyticsManagerTest method createParams.

private DataQueryParams createParams(AggregationType aggregationType) {
    DataElement deA = createDataElement('A', ValueType.INTEGER, aggregationType);
    OrganisationUnit ouA = createOrganisationUnit('A');
    Period peA = PeriodType.getPeriodFromIsoString("201501");
    return DataQueryParams.newBuilder().withDataType(DataType.NUMERIC).withTableName("analytics").withAggregationType(AnalyticsAggregationType.fromAggregationType(aggregationType)).addDimension(new BaseDimensionalObject(DATA_X_DIM_ID, DimensionType.DATA_X, getList(deA))).addFilter(new BaseDimensionalObject(ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, getList(ouA))).addDimension(new BaseDimensionalObject(PERIOD_DIM_ID, DimensionType.PERIOD, getList(peA))).build();
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) DhisConvenienceTest.createDataElement(org.hisp.dhis.DhisConvenienceTest.createDataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisConvenienceTest.createOrganisationUnit(org.hisp.dhis.DhisConvenienceTest.createOrganisationUnit) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Period(org.hisp.dhis.period.Period)

Example 89 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyASingleDataElementAsFilterRetainAggregationTypeAndAggregationDataType.

@Test
void verifyASingleDataElementAsFilterRetainAggregationTypeAndAggregationDataType() {
    // DataQueryParams with **one** DataElement as filter
    DataQueryParams queryParams = createDataQueryParams(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', ValueType.INTEGER, AggregationType.MAX))));
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    assertTrue(dataQueryParam.getAggregationType().isAggregationType(AggregationType.MAX));
    // Expect the datatype = NUMERIC (which will allow the SQL generator to
    // pick-up
    // the proper SQL function)
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(DataType.NUMERIC));
    assertThat(dataQueryParam.getPeriods(), hasSize(1));
    assertThat(dataQueryParam.getFilterDataElements(), hasSize(1));
    assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Example 90 with BaseDimensionalObject

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

the class QueryPlannerGroupByAggregationTypeTest method verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType.

@Test
void verifyMultipleDataElementAsFilterHavingDifferentAggTypeRetainAggregationType() {
    // DataQueryParams with **two** DataElement as filter
    // Both have DataType NUMERIC but different AggregationType
    // Aggregation type is overridden (COUNT)
    DataQueryParams queryParams = createDataQueryParamsWithAggregationType(new BaseDimensionalObject("dx", DimensionType.DATA_X, DISPLAY_NAME_DATA_X, "display name", Lists.newArrayList(createDataElement('A', new CategoryCombo()), createDataElement('B', ValueType.INTEGER, AggregationType.COUNT))), AnalyticsAggregationType.COUNT);
    DataQueryGroups dataQueryGroups = subject.planQuery(queryParams, QueryPlannerParams.newBuilder().withTableType(AnalyticsTableType.DATA_VALUE).build());
    assertThat(dataQueryGroups.getAllQueries(), hasSize(1));
    DataQueryParams dataQueryParam = dataQueryGroups.getAllQueries().get(0);
    // Aggregation type defaults to SUM
    assertDefaultAggregationType(dataQueryParam);
    assertThat(dataQueryParam.getAggregationType().getDataType(), is(nullValue()));
    assertThat(dataQueryParam.getPeriods(), hasSize(1));
    assertThat(dataQueryParam.getFilterDataElements(), hasSize(2));
    assertThat(dataQueryParam.getFilterOrganisationUnits(), hasSize(1));
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) CategoryCombo(org.hisp.dhis.category.CategoryCombo) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DataQueryGroups(org.hisp.dhis.analytics.DataQueryGroups) Test(org.junit.jupiter.api.Test)

Aggregations

BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)108 Test (org.junit.jupiter.api.Test)77 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)69 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)31 DhisSpringTest (org.hisp.dhis.DhisSpringTest)26 DimensionalObject (org.hisp.dhis.common.DimensionalObject)22 ArrayList (java.util.ArrayList)21 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)18 Grid (org.hisp.dhis.common.Grid)17 HashMap (java.util.HashMap)14 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)14 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)13 CategoryCombo (org.hisp.dhis.category.CategoryCombo)11 DataElement (org.hisp.dhis.dataelement.DataElement)11 Test (org.junit.Test)11 Map (java.util.Map)9 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)9 Period (org.hisp.dhis.period.Period)9 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)8 QueryItem (org.hisp.dhis.common.QueryItem)8