Search in sources :

Example 56 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlNoPeriodsAllowAllPeriods.

@Test
public void testGetFromUrlNoPeriodsAllowAllPeriods() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getUid() + ";" + deB.getUid() + ";" + deC.getUid() + ";" + deD.getUid());
    dimensionParams.add("pe");
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, null, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, true, null);
    assertEquals(0, params.getPeriods().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 57 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlPeriodOrder.

@Test
public void testGetFromUrlPeriodOrder() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getUid() + ";" + deB.getUid() + ";" + deC.getUid() + ";" + deD.getUid());
    dimensionParams.add("pe:2013;2012Q4;2012S2");
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getUid());
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, filterParams, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, false, null);
    List<DimensionalItemObject> periods = params.getPeriods();
    assertEquals(3, periods.size());
    assertEquals("2013", periods.get(0).getUid());
    assertEquals("2012Q4", periods.get(1).getUid());
    assertEquals("2012S2", periods.get(2).getUid());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 58 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlWithCodeB.

@Test
public void testGetFromUrlWithCodeB() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getCode() + ";" + deB.getCode() + ";" + inA.getCode());
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getCode());
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, filterParams, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, IdScheme.CODE, false, null, null, null, false, null);
    assertEquals(2, params.getDataElements().size());
    assertEquals(1, params.getIndicators().size());
    assertEquals(1, params.getFilterOrganisationUnits().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 59 with DataQueryParams

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

the class DataQueryServiceTest method testGetFromUrlRelativePeriods.

@Test
public void testGetFromUrlRelativePeriods() {
    Set<String> dimensionParams = new HashSet<>();
    dimensionParams.add("dx:" + deA.getDimensionItem() + ";" + deB.getDimensionItem() + ";" + deC.getDimensionItem() + ";" + deD.getDimensionItem());
    dimensionParams.add("pe:LAST_12_MONTHS");
    Set<String> filterParams = new HashSet<>();
    filterParams.add("ou:" + ouA.getDimensionItem() + ";" + ouB.getDimensionItem());
    DataQueryParams params = dataQueryService.getFromUrl(dimensionParams, filterParams, null, null, null, null, null, false, false, false, false, false, false, false, false, false, false, null, null, null, false, null, null, null, false, null);
    assertEquals(4, params.getDataElements().size());
    assertEquals(12, params.getPeriods().size());
    assertEquals(2, params.getFilterOrganisationUnits().size());
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 60 with DataQueryParams

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

the class DefaultAnalyticsService method addReportingRates.

/**
     * Adds reporting rates to the given grid based on the given data query
     * parameters and reporting rate metric.
     *
     * @param params the {@link DataQueryParams}.
     * @param grid the grid.
     * @param metric the reporting rate metric.
     */
private void addReportingRates(DataQueryParams params, Grid grid, ReportingRateMetric metric) {
    if (!params.getReportingRates().isEmpty() && !params.isSkipData()) {
        if (!COMPLETENESS_DIMENSION_TYPES.containsAll(params.getDimensionTypes())) {
            return;
        }
        DataQueryParams targetParams = DataQueryParams.newBuilder(params).withSkipPartitioning(true).withTimely(false).withRestrictByOrgUnitOpeningClosedDate(true).withRestrictByCategoryOptionStartEndDate(true).withAggregationType(AggregationType.SUM).build();
        Map<String, Double> targetMap = getAggregatedCompletenessTargetMap(targetParams);
        Map<String, Double> dataMap = metric != EXPECTED_REPORTS ? getAggregatedCompletenessValueMap(params) : new HashMap<>();
        Integer periodIndex = params.getPeriodDimensionIndex();
        Integer dataSetIndex = DataQueryParams.DX_INDEX;
        Map<String, PeriodType> dsPtMap = params.getDataSetPeriodTypeMap();
        PeriodType filterPeriodType = params.getFilterPeriodType();
        for (Map.Entry<String, Double> entry : targetMap.entrySet()) {
            List<String> dataRow = Lists.newArrayList(entry.getKey().split(DIMENSION_SEP));
            Double target = entry.getValue();
            Double actual = dataMap.get(entry.getKey());
            if (target != null && (actual != null || metric == EXPECTED_REPORTS)) {
                // ---------------------------------------------------------
                // Multiply target value by number of periods in time span
                // ---------------------------------------------------------
                PeriodType queryPt = filterPeriodType != null ? filterPeriodType : getPeriodTypeFromIsoString(dataRow.get(periodIndex));
                PeriodType dataSetPt = dsPtMap.get(dataRow.get(dataSetIndex));
                target = target * queryPt.getPeriodSpan(dataSetPt);
                // ---------------------------------------------------------
                // Calculate reporting rate and replace data set with rate
                // ---------------------------------------------------------
                Double value = 0d;
                if (EXPECTED_REPORTS == metric) {
                    value = target;
                } else if (ACTUAL_REPORTS == metric || ACTUAL_REPORTS_ON_TIME == metric) {
                    value = actual;
                } else if (// REPORTING_RATE or REPORTING_RATE_ON_TIME
                !MathUtils.isZero(target)) {
                    value = (actual * PERCENT) / target;
                }
                String reportingRate = DimensionalObjectUtils.getDimensionItem(dataRow.get(DX_INDEX), metric);
                dataRow.set(DX_INDEX, reportingRate);
                grid.addRow().addValues(dataRow.toArray()).addValue(params.isSkipRounding() ? value : MathUtils.getRounded(value));
                if (params.isIncludeNumDen()) {
                    grid.addValue(actual).addValue(target).addValue(PERCENT);
                }
            }
        }
    }
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) PeriodType(org.hisp.dhis.period.PeriodType) PeriodType.getPeriodTypeFromIsoString(org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) OrganisationUnit.getParentGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap) HashMap(java.util.HashMap) OrganisationUnit.getParentNameGraphMap(org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)

Aggregations

DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)81 Test (org.junit.Test)52 DhisSpringTest (org.hisp.dhis.DhisSpringTest)51 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)24 QueryPlannerParams (org.hisp.dhis.analytics.QueryPlannerParams)22 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)19 DataQueryGroups (org.hisp.dhis.analytics.DataQueryGroups)17 ArrayList (java.util.ArrayList)16 DimensionalObject (org.hisp.dhis.common.DimensionalObject)15 HashSet (java.util.HashSet)14 LinkedHashSet (java.util.LinkedHashSet)13 HashMap (java.util.HashMap)7 PeriodType.getPeriodTypeFromIsoString (org.hisp.dhis.period.PeriodType.getPeriodTypeFromIsoString)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 List (java.util.List)6 Map (java.util.Map)6 OrganisationUnit.getParentGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentGraphMap)6 OrganisationUnit.getParentNameGraphMap (org.hisp.dhis.organisationunit.OrganisationUnit.getParentNameGraphMap)6 EventQueryParams (org.hisp.dhis.analytics.event.EventQueryParams)5 Grid (org.hisp.dhis.common.Grid)5