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