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);
}
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));
}
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();
}
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));
}
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));
}
Aggregations