use of org.hisp.dhis.util.Timer in project dhis2-core by dhis2.
the class DefaultAnalyticsService method getAggregatedValueMap.
/**
* Generates a mapping between a dimension key and the aggregated value. The
* dimension key is a concatenation of the identifiers of the dimension items
* separated by "-".
*
* @param params the {@link DataQueryParams}.
* @param tableName the table name to use for the query.
* @param queryGroupers the list of additional query groupers to use for
* query planning, use empty list for none.
* @return a mapping between a dimension key and aggregated values.
*/
private Map<String, Object> getAggregatedValueMap(DataQueryParams params, String tableName, List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers) {
queryPlanner.validateMaintenanceMode();
int optimalQueries = MathUtils.getWithin(getProcessNo(), 1, MAX_QUERIES);
int maxLimit = params.isIgnoreLimit() ? 0 : (Integer) systemSettingManager.getSystemSetting(SettingKey.ANALYTICS_MAX_LIMIT);
Timer timer = new Timer().start().disablePrint();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(optimalQueries).withTableName(tableName).withQueryGroupers(queryGroupers).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
timer.getSplitTime("Planned analytics query, got: " + queryGroups.getLargestGroupSize() + " for optimal: " + optimalQueries);
Map<String, Object> map = new HashMap<>();
for (List<DataQueryParams> queries : queryGroups.getSequentialQueries()) {
List<Future<Map<String, Object>>> futures = new ArrayList<>();
for (DataQueryParams query : queries) {
futures.add(analyticsManager.getAggregatedDataValues(query, maxLimit));
}
for (Future<Map<String, Object>> future : futures) {
try {
Map<String, Object> taskValues = future.get();
if (taskValues != null) {
map.putAll(taskValues);
}
} catch (Exception ex) {
log.error(DebugUtils.getStackTrace(ex));
log.error(DebugUtils.getStackTrace(ex.getCause()));
throw new RuntimeException("Error during execution of aggregation query task", ex);
}
}
}
timer.getTime("Got analytics values");
return map;
}
use of org.hisp.dhis.util.Timer in project dhis2-core by dhis2.
the class AuditRepositoryTest method testAuditInsert200k.
@Test
@Disabled
void testAuditInsert200k() {
List<Audit> audits = new ArrayList<>();
IntStream.rangeClosed(1, 200_000).forEach(n -> {
String uid = CodeGenerator.generateUid();
String code = CodeGenerator.generateUid();
Audit audit = Audit.builder().auditType(AuditType.CREATE).auditScope(AuditScope.AGGREGATE).createdAt(LocalDateTime.of(2000, 1, 1, 0, 0)).createdBy("test-user").klass(DataElement.class.getName()).uid(uid).code(code).data("{}").build();
audits.add(audit);
});
Timer timer = new Timer().start();
audits.forEach(audit -> auditRepository.save(audit));
System.err.println("Single Insert: " + timer.getTimeInS() + "s");
assertEquals(200_000, auditRepository.count(AuditQuery.builder().build()));
}
use of org.hisp.dhis.util.Timer in project dhis2-core by dhis2.
the class DefaultEnrollmentAnalyticsService method addEventData.
@Override
protected long addEventData(Grid grid, EventQueryParams params) {
Timer timer = new Timer().start().disablePrint();
params = queryPlanner.planEnrollmentQuery(params);
timer.getSplitTime("Planned event query, got partitions: " + params.getPartitions());
long count = 0;
if (params.isPaging()) {
count += enrollmentAnalyticsManager.getEnrollmentCount(params);
}
enrollmentAnalyticsManager.getEnrollments(params, grid, queryValidator.getMaxLimit());
timer.getTime("Got enrollments " + grid.getHeight());
return count;
}
use of org.hisp.dhis.util.Timer in project dhis2-core by dhis2.
the class DataHandler method getAggregatedValueMap.
/**
* Generates a mapping between a dimension key and the aggregated value. The
* dimension key is a concatenation of the identifiers of the dimension
* items separated by "-".
*
* @param params the {@link DataQueryParams}.
* @param tableType the {@link AnalyticsTableType}.
* @param queryGroupers the list of additional query groupers to use for
* query planning, use empty list for none.
* @return a mapping between a dimension key and aggregated values.
*/
private Map<String, Object> getAggregatedValueMap(DataQueryParams params, AnalyticsTableType tableType, List<Function<DataQueryParams, List<DataQueryParams>>> queryGroupers) {
queryValidator.validateMaintenanceMode();
int optimalQueries = getWithin(getProcessNo(), 1, MAX_QUERIES);
int maxLimit = params.isIgnoreLimit() ? 0 : systemSettingManager.getIntSetting(ANALYTICS_MAX_LIMIT);
Timer timer = new Timer().start().disablePrint();
QueryPlannerParams plannerParams = QueryPlannerParams.newBuilder().withOptimalQueries(optimalQueries).withTableType(tableType).withQueryGroupers(queryGroupers).build();
DataQueryGroups queryGroups = queryPlanner.planQuery(params, plannerParams);
timer.getSplitTime("Planned analytics query, got: " + queryGroups.getLargestGroupSize() + " for optimal: " + optimalQueries);
Map<String, Object> map = new HashMap<>();
for (List<DataQueryParams> queries : queryGroups.getSequentialQueries()) {
executeQueries(tableType, maxLimit, map, queries);
}
timer.getTime("Got analytics values");
return map;
}
use of org.hisp.dhis.util.Timer in project dhis2-core by dhis2.
the class DefaultEventAnalyticsService method getAggregatedEventDataGrid.
private Grid getAggregatedEventDataGrid(EventQueryParams params) {
params.removeProgramIndicatorItems();
Grid grid = new ListGrid();
int maxLimit = queryValidator.getMaxLimit();
if (!params.isSkipData() || params.analyzeOnly()) {
if (params.isCollapseDataDimensions() || params.isAggregateData()) {
grid.addHeader(new GridHeader(DimensionalObject.DATA_COLLAPSED_DIM_ID, DataQueryParams.DISPLAY_NAME_DATA_X, ValueType.TEXT, false, true));
} else {
for (QueryItem item : params.getItems()) {
grid.addHeader(new GridHeader(item.getItem().getUid(), item.getItem().getDisplayProperty(params.getDisplayProperty()), item.getValueType(), false, true, item.getOptionSet(), item.getLegendSet()));
}
}
for (DimensionalObject dimension : params.getDimensions()) {
grid.addHeader(new GridHeader(dimension.getDimension(), dimension.getDisplayProperty(params.getDisplayProperty()), TEXT, false, true));
}
grid.addHeader(new GridHeader(VALUE_ID, VALUE_HEADER_NAME, NUMBER, false, false));
if (params.isIncludeNumDen()) {
grid.addHeader(new GridHeader(NUMERATOR_ID, NUMERATOR_HEADER_NAME, NUMBER, false, false)).addHeader(new GridHeader(DENOMINATOR_ID, DENOMINATOR_HEADER_NAME, NUMBER, false, false)).addHeader(new GridHeader(FACTOR_ID, FACTOR_HEADER_NAME, NUMBER, false, false)).addHeader(new GridHeader(MULTIPLIER_ID, MULTIPLIER_HEADER_NAME, NUMBER, false, false)).addHeader(new GridHeader(DIVISOR_ID, DIVISOR_HEADER_NAME, NUMBER, false, false));
}
// -----------------------------------------------------------------
// Data
// -----------------------------------------------------------------
Timer timer = new Timer().start().disablePrint();
List<EventQueryParams> queries = queryPlanner.planAggregateQuery(params);
timer.getSplitTime("Planned event query, got partitions: " + params.getPartitions());
for (EventQueryParams query : queries) {
if (query.hasEnrollmentProgramIndicatorDimension()) {
enrollmentAnalyticsManager.getAggregatedEventData(query, grid, maxLimit);
} else {
eventAnalyticsManager.getAggregatedEventData(query, grid, maxLimit);
}
}
timer.getTime("Got aggregated events");
if (maxLimit > 0 && grid.getHeight() > maxLimit) {
throwIllegalQueryEx(ErrorCode.E7128, maxLimit);
}
if (params.hasSortOrder() && grid.getHeight() > 0) {
grid.sortGrid(1, params.getSortOrderAsInt());
}
if (params.hasLimit() && grid.getHeight() > params.getLimit()) {
grid.limitGrid(params.getLimit());
}
}
maybeApplyIdScheme(params, grid);
// ---------------------------------------------------------------------
// Meta-data
// ---------------------------------------------------------------------
addMetadata(params, grid);
return grid;
}
Aggregations