Search in sources :

Example 31 with Dimension

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

the class ChartRendererJC method computePaints.

private Paint[] computePaints(List<PivotTableData.Axis> categories) {
    Paint[] paints = getDefaultPaints(categories.size());
    Dimension dim = categories.get(0).getDimension();
    if (dim == null) {
        return paints;
    }
    for (int i = 0; i != categories.size(); ++i) {
        CategoryProperties props = dim.getCategories().get(categories.get(i).getCategory());
        if (props != null && props.getColor() != null) {
            paints[i] = new Color(props.getColor());
        }
    }
    return paints;
}
Also used : CategoryProperties(org.activityinfo.shared.report.model.CategoryProperties) Color(com.google.code.appengine.awt.Color) Paint(com.google.code.appengine.awt.Paint) Dimension(org.activityinfo.shared.report.model.Dimension) Paint(com.google.code.appengine.awt.Paint)

Example 32 with Dimension

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

the class GetPartnersDimensionHandler method execute.

@Override
public void execute(GetPartnersDimension cmd, ExecutionContext context, final AsyncCallback<PartnerResult> callback) {
    // if the filter doesn't contain any activity, database or indicator values, just return an empty list
    if (!cmd.getFilter().isRestricted(DimensionType.Database) && !cmd.getFilter().isRestricted(DimensionType.Activity) && !cmd.getFilter().isRestricted(DimensionType.Indicator)) {
        callback.onSuccess(new PartnerResult());
        return;
    }
    final Dimension dimension = new Dimension(DimensionType.Partner);
    PivotSites query = new PivotSites();
    query.setFilter(cmd.getFilter());
    query.setDimensions(dimension);
    query.setValueType(ValueType.DIMENSION);
    context.execute(query, new AsyncCallback<PivotSites.PivotResult>() {

        @Override
        public void onSuccess(PivotSites.PivotResult result) {
            Set<PartnerDTO> partners = new HashSet<PartnerDTO>();
            for (Bucket bucket : result.getBuckets()) {
                EntityCategory category = (EntityCategory) bucket.getCategory(dimension);
                if (category == null) {
                    Log.debug("Partner is null: " + bucket.toString());
                } else {
                    PartnerDTO partner = new PartnerDTO();
                    partner.setId(category.getId());
                    partner.setName(category.getLabel());
                    partners.add(partner);
                }
            }
            // sort partners by name (fallback on id)
            List<PartnerDTO> list = new ArrayList<PartnerDTO>(partners);
            Collections.sort(list, new Comparator<PartnerDTO>() {

                @Override
                public int compare(PartnerDTO p1, PartnerDTO p2) {
                    int result = p1.getName().compareToIgnoreCase(p2.getName());
                    if (result != 0) {
                        return result;
                    } else {
                        return ((Integer) p1.getId()).compareTo(p2.getId());
                    }
                }
            });
            callback.onSuccess(new PartnerResult(list));
        }

        @Override
        public void onFailure(Throwable caught) {
            callback.onFailure(caught);
        }
    });
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) PartnerDTO(org.activityinfo.shared.dto.PartnerDTO) Dimension(org.activityinfo.shared.report.model.Dimension) GetPartnersDimension(org.activityinfo.shared.command.GetPartnersDimension) Comparator(java.util.Comparator) PivotSites(org.activityinfo.shared.command.PivotSites) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) List(java.util.List) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) PartnerResult(org.activityinfo.shared.command.result.PartnerResult)

Example 33 with Dimension

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

the class PivotQuery method addDimensionBundlers.

private void addDimensionBundlers() {
    /* Now add any other dimensions */
    for (Dimension dimension : dimensions) {
        if (dimension == null) {
            Log.error("NULL dimension provided to pivot query: dimensions = " + dimensions);
        } else if (dimension.getType() == DimensionType.Activity) {
            addOrderedEntityDimension(dimension, "Activity.ActivityId", "Activity.Name", "Activity.SortOrder");
        } else if (dimension.getType() == DimensionType.ActivityCategory) {
            addSimpleDimension(dimension, "Activity.Category");
        } else if (dimension.getType() == DimensionType.Database) {
            addEntityDimension(dimension, "Activity.DatabaseId", "UserDatabase.Name");
        } else if (dimension.getType() == DimensionType.Partner) {
            addEntityDimension(dimension, "Partner.PartnerId", "Partner.Name");
        } else if (dimension.getType() == DimensionType.Project) {
            addEntityDimension(dimension, "Project.ProjectId", "Project.Name");
        } else if (dimension.getType() == DimensionType.Location) {
            addEntityDimension(dimension, "Site.LocationId", "Location.Name");
        } else if (dimension.getType() == DimensionType.Indicator) {
            addOrderedEntityDimension(dimension, "Indicator.IndicatorId", "Indicator.Name", "Indicator.SortOrder");
        } else if (dimension.getType() == DimensionType.IndicatorCategory) {
            addSimpleDimension(dimension, "Indicator.Category");
        } else if (dimension instanceof DateDimension) {
            DateDimension dateDim = (DateDimension) dimension;
            if (dateDim.getUnit() == DateUnit.YEAR) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new YearBundler(dimension, yearAlias));
            } else if (dateDim.getUnit() == DateUnit.MONTH) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                String monthAlias = appendDimColumn("month", dialect.monthFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new MonthBundler(dimension, yearAlias, monthAlias));
            } else if (dateDim.getUnit() == DateUnit.QUARTER) {
                String yearAlias = appendDimColumn("year", dialect.yearFunction(baseTable.getDateCompleteColumn()));
                String quarterAlias = appendDimColumn("quarter", dialect.quarterFunction(baseTable.getDateCompleteColumn()));
                bundlers.add(new QuarterBundler(dimension, yearAlias, quarterAlias));
            } else if (dateDim.getUnit() == DateUnit.WEEK_MON) {
                // http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_week
                if (dialect.isMySql()) {
                    String weekAlias = appendDimColumn("yearweek", "YEARWEEK(" + baseTable.getDateCompleteColumn() + ", 3)");
                    bundlers.add(new MySqlYearWeekBundler(dimension, weekAlias));
                }
            // TODO: sqlite
            }
        } else if (dimension instanceof AdminDimension) {
            AdminDimension adminDim = (AdminDimension) dimension;
            String tableAlias = "AdminLevel" + adminDim.getLevelId();
            query.from(new StringBuilder(" LEFT JOIN " + "(SELECT L.LocationId, E.AdminEntityId, E.Name " + "FROM locationadminlink L " + "LEFT JOIN adminentity E ON (L.AdminEntityId=E.AdminEntityID) " + "WHERE E.AdminLevelId=").append(adminDim.getLevelId()).append(") AS ").append(tableAlias).append(" ON (").append(baseTable.getDimensionIdColumn(DimensionType.Location)).append(" =").append(tableAlias).append(".LocationId)").toString());
            addEntityDimension(dimension, tableAlias + ".AdminEntityId", tableAlias + ".Name");
        } else if (dimension.getType() == DimensionType.Attribute) {
            addEntityDimension(dimension, "AttributeValue.AttributeId", "Attribute.Name");
        } else if (dimension.getType() == DimensionType.AttributeGroup) {
            if (dimension instanceof AttributeGroupDimension) {
                // specific attributegroup
                defineAttributeDimension((AttributeGroupDimension) dimension);
            } else {
                // pivot on attributegroups
                addEntityDimension(dimension, "Attribute.AttributeGroupId", "AttributeGroup.name");
            }
        }
    }
}
Also used : MonthBundler(org.activityinfo.shared.command.handler.pivot.bundler.MonthBundler) MySqlYearWeekBundler(org.activityinfo.shared.command.handler.pivot.bundler.MySqlYearWeekBundler) QuarterBundler(org.activityinfo.shared.command.handler.pivot.bundler.QuarterBundler) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) YearBundler(org.activityinfo.shared.command.handler.pivot.bundler.YearBundler) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension)

Example 34 with Dimension

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

the class PivotTableDataBuilder method build.

public PivotTableData build(PivotReportElement<?> element, List<Dimension> rowDims, List<Dimension> colDims, List<Bucket> buckets) {
    PivotTableData table = new PivotTableData();
    Map<Dimension, Comparator<PivotTableData.Axis>> comparators = createComparators(element.allDimensions());
    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.shared.report.content.PivotTableData) Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) CategoryComparator(org.activityinfo.shared.command.handler.pivot.order.CategoryComparator) Comparator(java.util.Comparator) DefinedCategoryComparator(org.activityinfo.shared.command.handler.pivot.order.DefinedCategoryComparator)

Example 35 with Dimension

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

the class DimensionAdapter method unmarshal.

@Override
public Dimension unmarshal(DimensionElement element) {
    Dimension dim = createDim(element);
    for (CategoryElement category : element.categories) {
        CategoryProperties props = new CategoryProperties();
        props.setLabel(category.label);
        if (category.color != null) {
            props.setColor(decodeColor(category.color));
        }
        EntityCategory entityCategory = new EntityCategory(Integer.parseInt(category.name));
        dim.getCategories().put(entityCategory, props);
        dim.getOrdering().add(entityCategory);
    }
    return dim;
}
Also used : CategoryProperties(org.activityinfo.shared.report.model.CategoryProperties) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Aggregations

Dimension (org.activityinfo.shared.report.model.Dimension)46 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)31 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)29 DateDimension (org.activityinfo.shared.report.model.DateDimension)28 Test (org.junit.Test)23 Bucket (org.activityinfo.shared.command.result.Bucket)11 OnDataSet (org.activityinfo.server.database.OnDataSet)10 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)10 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)9 ArrayList (java.util.ArrayList)6 PivotSites (org.activityinfo.shared.command.PivotSites)6 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)4 Comparator (java.util.Comparator)3 DispatcherSync (org.activityinfo.server.command.DispatcherSync)3 User (org.activityinfo.server.database.hibernate.entity.User)3 DimensionCategory (org.activityinfo.shared.report.content.DimensionCategory)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 JsonObject (com.google.gson.JsonObject)2 List (java.util.List)2 ReportChangeEvent (org.activityinfo.client.page.report.ReportChangeEvent)2