Search in sources :

Example 16 with DateDimension

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

the class PivotSitesHandlerLocalTest method targetFilter.

@Test
public void targetFilter() {
    // Pivoting: PivotSites [dimensions=[Date, Partner, Date, Target,
    // Activity, Indicator],
    // filter=AdminLevel={ 141801 }, Partner={ 130 },
    // Indicator={ 747 746 745 744 749 748 739 738 743 740 119 118 3661 125
    // 124 123 122 121 }, valueType=INDICATOR]
    withPartnerAsDimension();
    // dimensions.add(new DateDimension(DateUnit.YEAR));
    dimensions.add(new Dimension(DimensionType.Target));
    dimensions.add(new Dimension(DimensionType.Activity));
    dimensions.add(new Dimension(DimensionType.Indicator));
    filter.addRestriction(DimensionType.AdminLevel, 141801);
    filter.addRestriction(DimensionType.Partner, 130);
    filter.addRestriction(DimensionType.Indicator, 1);
    execute();
}
Also used : 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) Test(org.junit.Test)

Example 17 with DateDimension

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

the class ReportJsonFactory method decodeDimensionList.

public List<Dimension> decodeDimensionList(JsonArray dimensions) {
    Iterator<JsonElement> it = dimensions.iterator();
    List<Dimension> dimensionsList = new ArrayList<Dimension>();
    while (it.hasNext()) {
        JsonObject dim = it.next().getAsJsonObject();
        String type = dim.get("type").getAsString();
        if (type.equals(DimensionType.Date.toString())) {
            String dateUnit = dim.get("dateUnit").getAsString();
            DateDimension dimension = new DateDimension(DateUnit.valueOf(dateUnit));
            JsonElement categories = dim.get("categories");
            if (categories != null) {
                dimension.setCategories(decodeCategories(categories));
            }
            dimensionsList.add(dimension);
        } else if (type.equals(DimensionType.AdminLevel.toString())) {
            Integer level = dim.get("level").getAsInt();
            AdminDimension dimension = new AdminDimension(level);
            JsonElement categories = dim.get("categories");
            if (categories != null) {
                dimension.setCategories(decodeCategories(categories));
            }
            dimensionsList.add(dimension);
        } else {
            Dimension dimension = new Dimension(DimensionType.valueOf(dim.get("type").getAsString()));
            JsonElement color = dim.get("color");
            if (color != null) {
                dimension.setColor(color.getAsString());
            }
            JsonElement categories = dim.get("categories");
            if (categories != null) {
                dimension.setCategories(decodeCategories(categories));
            }
            dimensionsList.add(dimension);
        }
    }
    return dimensionsList;
}
Also used : JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension)

Example 18 with DateDimension

use of org.activityinfo.shared.report.model.DateDimension 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 19 with DateDimension

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

the class PivotSitesHandlerTest method testTargetPivot.

@Test
@OnDataSet("/dbunit/sites-simple-target.db.xml")
public void testTargetPivot() {
    withIndicatorAsDimension();
    dimensions.add(new DateDimension(DateUnit.YEAR));
    dimensions.add(new Dimension(DimensionType.Target));
    filter.addRestriction(DimensionType.Indicator, 1);
    filter.setDateRange(new DateRange(new LocalDate(2008, 1, 1), new LocalDate(2008, 12, 31)));
    execute();
    assertThat().thereAre(2).buckets();
}
Also used : DateRange(org.activityinfo.shared.report.model.DateRange) 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) DateDimension(org.activityinfo.shared.report.model.DateDimension) LocalDate(com.bedatadriven.rebar.time.calendar.LocalDate) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 20 with DateDimension

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

the class PivotSitesHandlerLocalTest method testYears.

/**
 * year, quarter and month functions in SqliteDialect throw java.lang.UnsupportedOperationException
 */
@Test(expected = RuntimeException.class)
public void testYears() {
    forTotalSiteCounts();
    dimensions.add(new DateDimension(DateUnit.YEAR));
    execute();
    assertThat().forYear(2008).thereIsOneBucketWithValue(1);
    assertThat().forYear(2009).thereIsOneBucketWithValue(4);
}
Also used : DateDimension(org.activityinfo.shared.report.model.DateDimension) Test(org.junit.Test)

Aggregations

DateDimension (org.activityinfo.shared.report.model.DateDimension)20 Test (org.junit.Test)15 Dimension (org.activityinfo.shared.report.model.Dimension)13 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)12 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)8 OnDataSet (org.activityinfo.server.database.OnDataSet)5 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)3 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)2 JsonObject (com.google.gson.JsonObject)2 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)2 DateUtilCalendarImpl (org.activityinfo.server.util.date.DateUtilCalendarImpl)2 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)2 PivotContent (org.activityinfo.shared.report.content.PivotContent)2 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)2 Axis (org.activityinfo.shared.report.content.PivotTableData.Axis)2 ReportContent (org.activityinfo.shared.report.content.ReportContent)2 SimpleCategory (org.activityinfo.shared.report.content.SimpleCategory)2 DateRange (org.activityinfo.shared.report.model.DateRange)2 Report (org.activityinfo.shared.report.model.Report)2 JsonArray (com.google.gson.JsonArray)1