use of org.activityinfo.legacy.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotSitesHandlerTest method testIndicatorOrder.
@Test
public void testIndicatorOrder() {
withIndicatorAsDimension();
filter.addRestriction(DimensionType.Indicator, 1);
filter.addRestriction(DimensionType.Indicator, 2);
execute();
assertEquals(2, buckets.size());
Bucket indicator1 = findBucketsByCategory(buckets, indicatorDim, new EntityCategory(1)).get(0);
Bucket indicator2 = findBucketsByCategory(buckets, indicatorDim, new EntityCategory(2)).get(0);
EntityCategory cat1 = (EntityCategory) indicator1.getCategory(indicatorDim);
EntityCategory cat2 = (EntityCategory) indicator2.getCategory(indicatorDim);
assertEquals(2, cat1.getSortOrder().intValue());
assertEquals(OWNER_USER_ID, cat2.getSortOrder().intValue());
}
use of org.activityinfo.legacy.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotTableGeneratorTest method test2x2.
@Test
public void test2x2() {
// test input data: user
User user = new User();
user.setLocale("fr");
// test input data: PivotTableElement
PivotTableReportElement element = new PivotTableReportElement();
AdminDimension provinceDim = new AdminDimension(1);
element.addRowDimension(provinceDim);
Dimension partnerDim = new Dimension(DimensionType.Partner);
element.addColDimension(partnerDim);
// test input data: aggregated results
List<Bucket> buckets = new ArrayList<Bucket>();
buckets.add(newBucket(433, category(provinceDim, 2, "Sud Kivu"), category(partnerDim, 1, "IRC")));
buckets.add(newBucket(1032, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 2, "Solidarites")));
buckets.add(newBucket(310, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 1, "IRC")));
buckets.add(newBucket(926, category(provinceDim, 1, "Nord Kivu"), category(partnerDim, 3, "AVSI")));
// collaborator : PivotDAO
DispatcherSync dispatcher = createMock(DispatcherSync.class);
expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
replay(dispatcher);
// CLASS UNDER TEST!!
PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
generator.generate(user, element, dummyFilter(), null);
Assert.assertNotNull("element content", element.getContent());
PivotTableData data = element.getContent().getData();
Assert.assertEquals("rows", 2, data.getRootRow().getChildCount());
Assert.assertEquals("rows sorted", "Nord Kivu", data.getRootRow().getChildren().get(0).getLabel());
Assert.assertEquals("cols", 3, data.getRootColumn().getChildCount());
}
use of org.activityinfo.legacy.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class OldPivotSitesHandler method execute.
@Override
public void execute(PivotSites command, ExecutionContext context, final AsyncCallback<PivotResult> callback) {
LOGGER.fine("Pivoting: " + command);
if (command.getFilter() == null || filterIsToBroad(command.getFilter())) {
Log.error("Filter is to broad: " + command.getFilter());
PivotResult emptyResult = new PivotResult();
emptyResult.setBuckets(Lists.<Bucket>newArrayList());
callback.onSuccess(emptyResult);
return;
}
final PivotQueryContext queryContext = new PivotQueryContext(command, context, dialect);
final List<WorkItem> workList = Lists.newArrayList();
for (BaseTable baseTable : baseTables) {
if (baseTable.accept(command)) {
workList.add(new PivotQuery(queryContext, baseTable));
}
}
if (command.getValueType() == PivotSites.ValueType.INDICATOR) {
workList.add(new ErrorLoggingWorkItem(new CalculatedIndicatorsQuery(queryContext)));
}
if (workList.isEmpty()) {
callback.onSuccess(new PivotResult(Lists.<Bucket>newArrayList()));
}
final Set<WorkItem> remaining = Sets.newHashSet(workList);
final List<Throwable> errors = Lists.newArrayList();
for (final WorkItem workItem : workList) {
workItem.execute(new AsyncCallback<Void>() {
@Override
public void onSuccess(Void voidResult) {
if (errors.isEmpty()) {
remaining.remove(workItem);
if (remaining.isEmpty()) {
try {
callback.onSuccess(new PivotResult(queryContext.getBuckets()));
} catch (Throwable e) {
callback.onFailure(e);
}
}
}
}
@Override
public void onFailure(Throwable caught) {
if (errors.isEmpty()) {
callback.onFailure(caught);
}
errors.add(caught);
}
});
}
}
use of org.activityinfo.legacy.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class CalculatedIndicatorsQuery method aggregateSites.
private void aggregateSites(SiteResult result) {
for (int i = 0; i != result.getTotalLength(); ++i) {
SiteDTO site = result.getData().get(i);
// Now loop over each value
for (EntityCategory indicator : indicatorMap.values()) {
Double value = site.getIndicatorDoubleValue(indicator.getId());
if (value != null && !Double.isNaN(value) && !Double.isInfinite(value)) {
Bucket bucket = new Bucket(value);
bucket.setAggregationMethod(indicatorAggregationMap.get(indicator.getId()));
bucket.setCategory(new Dimension(DimensionType.Target), TargetCategory.REALIZED);
if (query.isPivotedBy(DimensionType.Indicator)) {
bucket.setCategory(new Dimension(DimensionType.Indicator), indicator);
}
for (int j = 0; j != dimAccessors.size(); ++j) {
bucket.setCategory(dimAccessors.get(j).getDimension(), dimAccessors.get(j).getCategory(site));
}
queryContext.addBucket(bucket);
}
}
}
}
use of org.activityinfo.legacy.shared.command.result.Bucket in project activityinfo by bedatadriven.
the class PivotTableDataBuilder method build.
public PivotTableData build(List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
PivotTableData table = new PivotTableData();
Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(Iterables.concat(rowDims, colDims));
for (Bucket bucket : buckets) {
PivotTableData.Axis column = colDims.isEmpty() ? table.getRootColumn() : find(table.getRootColumn(), colDims.iterator(), comparators, bucket);
PivotTableData.Axis row = rowDims.isEmpty() ? table.getRootRow() : find(table.getRootRow(), rowDims.iterator(), comparators, bucket);
row.setValue(column, bucket.doubleValue());
}
return table;
}
Aggregations