Search in sources :

Example 6 with DimensionalObject

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

the class DataQueryParams method getDimensionItemPermutations.

/**
     * Generates all permutations of the dimension options for this query.
     * Ignores the data and category option combo dimensions.
     */
public List<List<DimensionItem>> getDimensionItemPermutations() {
    List<DimensionItem[]> dimensionOptions = new ArrayList<>();
    for (DimensionalObject dimension : dimensions) {
        if (!DIMENSION_PERMUTATION_IGNORE_DIMS.contains(dimension.getDimension())) {
            List<DimensionItem> options = new ArrayList<>();
            for (DimensionalItemObject option : dimension.getItems()) {
                options.add(new DimensionItem(dimension.getDimension(), option));
            }
            dimensionOptions.add(options.toArray(DIM_OPT_ARR));
        }
    }
    CombinationGenerator<DimensionItem> generator = new CombinationGenerator<>(dimensionOptions.toArray(DIM_OPT_2D_ARR));
    return generator.getCombinations();
}
Also used : DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 7 with DimensionalObject

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

the class DataQueryParams method retainDataDimension.

/**
     * Retains only dimensions of the given data dimension item type.
     */
private DataQueryParams retainDataDimension(DataDimensionItemType itemType) {
    DimensionalObject dimension = getDimensionOrFilter(DATA_X_DIM_ID);
    List<DimensionalItemObject> items = AnalyticsUtils.getByDataDimensionItemType(itemType, dimension.getItems());
    dimension.getItems().clear();
    dimension.getItems().addAll(items);
    return this;
}
Also used : DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 8 with DimensionalObject

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

the class DataQueryParams method getDuplicateDimensions.

/**
     * Returns a list of dimensions which occur more than once, not including
     * the first duplicate.
     */
public List<DimensionalObject> getDuplicateDimensions() {
    Set<DimensionalObject> dims = new HashSet<>();
    List<DimensionalObject> duplicates = new ArrayList<>();
    for (DimensionalObject dim : dimensions) {
        if (!dims.add(dim)) {
            duplicates.add(dim);
        }
    }
    return duplicates;
}
Also used : DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 9 with DimensionalObject

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

the class DataQueryParams method retainDataDimensionReportingRates.

/**
     * Retains only dimensions of type reporting rates and the given reporting
     * rate metric.
     * 
     * @param metric the reporting rate metric.
     */
private DataQueryParams retainDataDimensionReportingRates(ReportingRateMetric metric) {
    DimensionalObject dimension = getDimensionOrFilter(DATA_X_DIM_ID);
    List<ReportingRate> items = DimensionalObjectUtils.asTypedList(AnalyticsUtils.getByDataDimensionItemType(DataDimensionItemType.REPORTING_RATE, dimension.getItems()));
    items = items.stream().filter(r -> metric == r.getMetric()).collect(Collectors.toList());
    dimension.getItems().clear();
    dimension.getItems().addAll(items);
    return this;
}
Also used : DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Example 10 with DimensionalObject

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

the class DefaultQueryPlanner method groupByPeriodType.

/**
     * If periods appear as dimensions in the given query; groups the query into
     * sub queries based on the period type of the periods. Sets the period type
     * name on each query. If periods appear as filters; replaces the period filter
     * with one filter for each period type. Sets the dimension names and filter
     * names respectively.
     */
@Override
public List<DataQueryParams> groupByPeriodType(DataQueryParams params) {
    List<DataQueryParams> queries = new ArrayList<>();
    if (params.isSkipPartitioning()) {
        queries.add(params);
    } else if (!params.getPeriods().isEmpty()) {
        ListMap<String, DimensionalItemObject> periodTypePeriodMap = PartitionUtils.getPeriodTypePeriodMap(params.getPeriods());
        for (String periodType : periodTypePeriodMap.keySet()) {
            DataQueryParams query = DataQueryParams.newBuilder(params).addOrSetDimensionOptions(PERIOD_DIM_ID, DimensionType.PERIOD, periodType.toLowerCase(), periodTypePeriodMap.get(periodType)).withPeriodType(periodType).build();
            queries.add(query);
        }
    } else if (!params.getFilterPeriods().isEmpty()) {
        DimensionalObject filter = params.getFilter(PERIOD_DIM_ID);
        ListMap<String, DimensionalItemObject> periodTypePeriodMap = PartitionUtils.getPeriodTypePeriodMap(filter.getItems());
        DataQueryParams.Builder query = DataQueryParams.newBuilder(params).removeFilter(PERIOD_DIM_ID).withPeriodType(// Using first period type
        periodTypePeriodMap.keySet().iterator().next());
        for (String periodType : periodTypePeriodMap.keySet()) {
            query.addFilter(new BaseDimensionalObject(filter.getDimension(), filter.getDimensionType(), periodType.toLowerCase(), filter.getDisplayName(), periodTypePeriodMap.get(periodType)));
        }
        queries.add(query.build());
    } else {
        queries.add(DataQueryParams.newBuilder(params).build());
        return queries;
    }
    if (queries.size() > 1) {
        log.debug(String.format("Split on period type: %d", queries.size()));
    }
    return queries;
}
Also used : DataQueryParams(org.hisp.dhis.analytics.DataQueryParams) DimensionalItemObject(org.hisp.dhis.common.DimensionalItemObject) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) ArrayList(java.util.ArrayList) ListMap(org.hisp.dhis.common.ListMap) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) DimensionalObject(org.hisp.dhis.common.DimensionalObject)

Aggregations

DimensionalObject (org.hisp.dhis.common.DimensionalObject)44 ArrayList (java.util.ArrayList)14 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)14 DimensionalItemObject (org.hisp.dhis.common.DimensionalItemObject)13 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)11 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)10 Test (org.junit.Test)8 List (java.util.List)6 DhisConvenienceTest (org.hisp.dhis.DhisConvenienceTest)5 Grid (org.hisp.dhis.common.Grid)5 DataElement (org.hisp.dhis.dataelement.DataElement)5 Period (org.hisp.dhis.period.Period)5 DateUtils.getMediumDateString (org.hisp.dhis.system.util.DateUtils.getMediumDateString)5 Calendar (org.hisp.dhis.calendar.Calendar)4 User (org.hisp.dhis.user.User)4 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)3 DataSet (org.hisp.dhis.dataset.DataSet)3 Indicator (org.hisp.dhis.indicator.Indicator)3 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)3 ListGrid (org.hisp.dhis.system.grid.ListGrid)3