Search in sources :

Example 6 with Bucket

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());
}
Also used : Bucket(org.activityinfo.legacy.shared.command.result.Bucket)

Example 7 with Bucket

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());
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) PivotTableReportElement(org.activityinfo.legacy.shared.reports.model.PivotTableReportElement) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 8 with Bucket

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);
            }
        });
    }
}
Also used : PivotResult(org.activityinfo.legacy.shared.command.PivotSites.PivotResult) Bucket(org.activityinfo.legacy.shared.command.result.Bucket)

Example 9 with Bucket

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);
            }
        }
    }
}
Also used : Bucket(org.activityinfo.legacy.shared.command.result.Bucket) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 10 with 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;
}
Also used : PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension) DefinedCategoryComparator(org.activityinfo.legacy.shared.impl.pivot.order.DefinedCategoryComparator) CategoryComparator(org.activityinfo.legacy.shared.impl.pivot.order.CategoryComparator)

Aggregations

Bucket (org.activityinfo.legacy.shared.command.result.Bucket)13 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)7 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)5 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)4 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)4 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)4 ArrayList (java.util.ArrayList)3 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)3 PivotResult (org.activityinfo.legacy.shared.command.PivotSites.PivotResult)2 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)2 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)2 DispatcherSync (org.activityinfo.server.command.DispatcherSync)2 User (org.activityinfo.server.database.hibernate.entity.User)2 Test (org.junit.Test)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)1 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)1 GetPartnersDimension (org.activityinfo.legacy.shared.command.GetPartnersDimension)1