Search in sources :

Example 1 with AdminDimension

use of org.activityinfo.legacy.shared.reports.model.AdminDimension 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, "Location.LocationId", "Location.Name");
        } else if (dimension.getType() == DimensionType.Site) {
            addEntityDimension(dimension, baseTable.getDimensionIdColumn(DimensionType.Site), "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 (dateDim.getUnit() == DateUnit.DAY) {
                String dateAlias = appendDimColumn("date", baseTable.getDateCompleteColumn());
                bundlers.add(new DayBundler(dimension, dateAlias));
            }
        } 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 : 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) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) AttributeGroupDimension(org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension) DateDimension(org.activityinfo.legacy.shared.reports.model.DateDimension)

Example 2 with AdminDimension

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

the class PolygonLayerGenerator method queryBuckets.

private void queryBuckets(DispatcherSync dispatcher, Filter layerFilter) {
    PivotSites query = new PivotSites();
    query.setFilter(layerFilter);
    AdminDimension adminDimension = new AdminDimension(layer.getAdminLevelId());
    query.setDimensions(adminDimension);
    MagnitudeScaleBuilder scaleBuilder = new MagnitudeScaleBuilder(layer);
    this.pivotResult = query.isTooBroad() ? new PivotResult() : dispatcher.execute(query);
    for (Bucket bucket : pivotResult.getBuckets()) {
        EntityCategory category = (EntityCategory) bucket.getCategory(adminDimension);
        if (category != null) {
            int adminEntityId = category.getId();
            AdminMarker polygon = overlay.getPolygon(adminEntityId);
            if (polygon != null) {
                polygon.setValue(bucket.doubleValue());
                scaleBuilder.addValue(bucket.doubleValue());
            }
        }
    }
    colorScale = scaleBuilder.build();
}
Also used : PivotSites(org.activityinfo.legacy.shared.command.PivotSites) PivotResult(org.activityinfo.legacy.shared.command.PivotSites.PivotResult) Bucket(org.activityinfo.legacy.shared.command.result.Bucket) AdminMarker(org.activityinfo.legacy.shared.reports.content.AdminMarker) AdminDimension(org.activityinfo.legacy.shared.reports.model.AdminDimension) EntityCategory(org.activityinfo.legacy.shared.reports.content.EntityCategory)

Example 3 with AdminDimension

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

Aggregations

AdminDimension (org.activityinfo.legacy.shared.reports.model.AdminDimension)3 PivotSites (org.activityinfo.legacy.shared.command.PivotSites)2 Bucket (org.activityinfo.legacy.shared.command.result.Bucket)2 Dimension (org.activityinfo.legacy.shared.reports.model.Dimension)2 ArrayList (java.util.ArrayList)1 PivotResult (org.activityinfo.legacy.shared.command.PivotSites.PivotResult)1 AdminMarker (org.activityinfo.legacy.shared.reports.content.AdminMarker)1 EntityCategory (org.activityinfo.legacy.shared.reports.content.EntityCategory)1 PivotTableData (org.activityinfo.legacy.shared.reports.content.PivotTableData)1 AttributeGroupDimension (org.activityinfo.legacy.shared.reports.model.AttributeGroupDimension)1 DateDimension (org.activityinfo.legacy.shared.reports.model.DateDimension)1 PivotTableReportElement (org.activityinfo.legacy.shared.reports.model.PivotTableReportElement)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1 User (org.activityinfo.server.database.hibernate.entity.User)1 Test (org.junit.Test)1