private void finalizeHierarchicalAggregateEntity(HierarchicalAggregateEntity entity){ for(GroupbyBucket.Function f : entity.getTmpValues()){ entity.getValues().add(f.result()); } for(HierarchicalAggregateEntity child : entity.getChildren().values()){ finalizeHierarchicalAggregateEntity(child); } entity.setTmpValues(null); }
/** * sort aggregated results with sort options * * @param result * @param sortOptions * @return */ public static HierarchicalAggregateEntity sort(HierarchicalAggregateEntity result, List<SortOption> sortOptions){ SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> tmp = sortByValue(result, sortOptions); result.setSortedList(tmp); result.setChildren(null); for(Map.Entry<String, HierarchicalAggregateEntity> entry : tmp){ sort(entry.getValue(), sortOptions); } return result; }
public void accumulate(TaggedLogAPIEntity entity) throws Exception{ List<Double> preAggregatedValues = createPreAggregatedValues(entity); // aggregate to root first addDatapoint(root, preAggregatedValues); // go through hierarchical tree HierarchicalAggregateEntity current = root; int i = 0; for(String groupbyField : groupbyFields){ // determine groupbyFieldValue from tag or fields String groupbyFieldValue = determineGroupbyFieldValue(entity, groupbyField, i); SortedMap<String, HierarchicalAggregateEntity> children = current.getChildren(); if(children.get(groupbyFieldValue) == null){ HierarchicalAggregateEntity tmp = new HierarchicalAggregateEntity(); children.put(groupbyFieldValue, tmp); } children.get(groupbyFieldValue).setKey(groupbyFieldValue); addDatapoint(children.get(groupbyFieldValue), preAggregatedValues); current = children.get(groupbyFieldValue); } }
private static SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortByValue(HierarchicalAggregateEntity entity, List<SortOption> sortOptions) { SortedSet<Map.Entry<String, HierarchicalAggregateEntity>> sortedEntries = new TreeSet<Map.Entry<String, HierarchicalAggregateEntity>>(new MapEntryComparator(sortOptions)); sortedEntries.addAll(entity.getChildren().entrySet()); return sortedEntries; }
private void addDatapoint(HierarchicalAggregateEntity entity, List<Double> values){ List<GroupbyBucket.Function> functions = entity.getTmpValues(); // initialize list of function if(functions.isEmpty()){ for(AggregateFunctionType type : aggregateFunctionTypes){ functions.add(GroupbyBucket._functionFactories.get(type.name()).createFunction()); } } int functionIndex = 0; for(Double v : values){ functions.get(functionIndex).run(v); functionIndex++; } }