Search in sources :

Example 16 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class CalculatedIndicatorsQuery method queryAttributeGroups.

private void queryAttributeGroups() {
    Set<Integer> groupIds = Sets.newHashSet();
    for (Dimension dim : query.getDimensions()) {
        if (dim instanceof AttributeGroupDimension) {
            AttributeGroupDimension groupDim = (AttributeGroupDimension) dim;
            groupIds.add(groupDim.getAttributeGroupId());
        }
    }
    SqlQuery.select().appendColumn("g.attributeGroupId", "groupId").appendColumn("g.name", "groupName").appendColumn("a.attributeId").appendColumn("a.name").appendColumn("a.sortOrder").from(Tables.ATTRIBUTE, "a").leftJoin(Tables.ATTRIBUTE_GROUP, "g").on("a.attributeGroupId=g.attributeGroupId").where("a.attributeGroupId").in(groupIds).execute(queryContext.getExecutionContext().getTransaction(), new SqlResultCallback() {

        @Override
        public void onSuccess(SqlTransaction tx, SqlResultSet results) {
            for (SqlResultSetRow row : results.getRows()) {
                int groupId = row.getInt("groupId");
                int attributeId = row.getInt("attributeId");
                int sortOrder = row.getInt("sortOrder");
                String attributeName = row.getString("name");
                attributes.put(groupId, new EntityCategory(attributeId, attributeName, sortOrder));
            }
            querySites();
        }
    });
}
Also used : SqlResultSet(com.bedatadriven.rebar.sql.client.SqlResultSet) SqlResultCallback(com.bedatadriven.rebar.sql.client.SqlResultCallback) SqlTransaction(com.bedatadriven.rebar.sql.client.SqlTransaction) 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) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) SqlResultSetRow(com.bedatadriven.rebar.sql.client.SqlResultSetRow) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 17 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension 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 18 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class PivotTableDataBuilder method find.

protected PivotTableData.Axis find(PivotTableData.Axis axis, Iterator<Dimension> dimensionIterator, Map<Dimension, Comparator<PivotTableData.Axis>> comparators, Bucket result) {
    Dimension childDimension = dimensionIterator.next();
    DimensionCategory category = result.getCategory(childDimension);
    PivotTableData.Axis child = null;
    child = axis.getChild(category);
    if (child == null) {
        String categoryLabel;
        if (category == null) {
            categoryLabel = I18N.CONSTANTS.emptyDimensionCategory();
        } else {
            categoryLabel = childDimension.getLabel(category);
            if (categoryLabel == null) {
                categoryLabel = category.getLabel();
            }
        }
        child = axis.addChild(childDimension, result.getCategory(childDimension), categoryLabel, comparators.get(childDimension));
    }
    if (dimensionIterator.hasNext()) {
        return find(child, dimensionIterator, comparators, result);
    } else {
        return child;
    }
}
Also used : DimensionCategory(org.activityinfo.legacy.shared.reports.content.DimensionCategory) PivotTableData(org.activityinfo.legacy.shared.reports.content.PivotTableData) Dimension(org.activityinfo.legacy.shared.reports.model.Dimension)

Example 19 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension 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)

Example 20 with Dimension

use of org.activityinfo.legacy.shared.reports.model.Dimension in project activityinfo by bedatadriven.

the class PivotTestResource method command.

private PivotSites command(Report model, PivotReportElement<?> element, boolean newEngine, boolean showDetails) {
    Filter effectiveFilter = new Filter(model.getFilter(), element.getFilter());
    Set<Dimension> dimensions = Sets.newHashSet();
    for (Dimension dimension : element.allDimensions()) {
        dimensions.add(dimension);
    }
    if (showDetails) {
        dimensions.add(new Dimension(DimensionType.Site));
        dimensions.add(new Dimension(DimensionType.Activity));
        dimensions.add(new Dimension(DimensionType.Database));
        dimensions.add(new Dimension(DimensionType.Indicator));
    }
    PivotSites command = new PivotSites(dimensions, effectiveFilter);
    if (newEngine) {
        return command;
    } else {
        return new OldPivotSites(command);
    }
}
Also used : Dimension(org.activityinfo.legacy.shared.reports.model.Dimension)

Aggregations

Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)26 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)11 AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)10 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)9 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)7 Test (org.junit.Test)7 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)6 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)5 ArrayList (java.util.ArrayList)3 Filter (org.activityinfo.legacy.shared.command.Filter)3 DimensionCategory (org.activityinfo.legacy.shared.reports.content.DimensionCategory)3 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)3 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)3 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)2 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)2 SqlTransaction (com.bedatadriven.rebar.sql.client.SqlTransaction)2 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)2