Search in sources :

Example 1 with AdminDimension

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

the class ReportJsonFactory method encodeDimensionList.

public JsonArray encodeDimensionList(List<Dimension> dims) {
    JsonArray jsonDims = new JsonArray();
    for (int i = 0; i < dims.size(); i++) {
        JsonObject jsonDim = new JsonObject();
        DimensionType type = dims.get(i).getType();
        if (type.equals(DimensionType.Date)) {
            DateDimension dim = (DateDimension) dims.get(i);
            jsonDim.addProperty("type", dim.getType().toString());
            jsonDim.addProperty("dateUnit", dim.getUnit().toString());
            if (dim.getColor() != null) {
                jsonDim.addProperty("color", dim.getColor());
            }
            if (!dim.getCategories().isEmpty()) {
                jsonDim.add("categories", encodeCategories(dim.getCategories()));
            }
        } else if (type.equals(DimensionType.AdminLevel)) {
            AdminDimension dim = (AdminDimension) dims.get(i);
            jsonDim.addProperty("type", dim.getType().toString());
            jsonDim.addProperty("level", dim.getLevelId());
            if (dim.getColor() != null) {
                jsonDim.addProperty("color", dim.getColor());
            }
            if (!dim.getCategories().isEmpty()) {
                jsonDim.add("categories", encodeCategories(dim.getCategories()));
            }
        } else {
            Dimension dim = dims.get(i);
            jsonDim.addProperty("type", dim.getType().toString());
            if (dim.getColor() != null) {
                jsonDim.addProperty("color", dim.getColor());
            }
            if (!dim.getCategories().isEmpty()) {
                jsonDim.add("categories", encodeCategories(dim.getCategories()));
            }
        }
        jsonDims.add(jsonDim);
    }
    return jsonDims;
}
Also used : JsonArray(com.google.gson.JsonArray) DimensionType(org.activityinfo.shared.report.model.DimensionType) 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 2 with AdminDimension

use of org.activityinfo.shared.report.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 = 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.shared.command.PivotSites) Bucket(org.activityinfo.shared.command.result.Bucket) AdminMarker(org.activityinfo.shared.report.content.AdminMarker) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory)

Example 3 with AdminDimension

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

the class ReportSerializerTest method createDimensionList.

private List<Dimension> createDimensionList() {
    List dims = Lists.newArrayList();
    AdminDimension dim1 = new AdminDimension("admin level", 0);
    dims.add(dim1);
    return dims;
}
Also used : List(java.util.List) AdminDimension(org.activityinfo.shared.report.model.AdminDimension)

Example 4 with AdminDimension

use of org.activityinfo.shared.report.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, null, 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.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) PivotTableData(org.activityinfo.shared.report.content.PivotTableData) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 5 with AdminDimension

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

the class JaxbParseTest method testDimensions.

@Test
public void testDimensions() throws Throwable {
    Report report = parseXml("dimensions.xml");
    dumpXml(report);
    Assert.assertEquals("element count", 1, report.getElements().size());
    Assert.assertTrue("is pivotTable", report.getElements().get(0) instanceof PivotTableReportElement);
    PivotTableReportElement table = report.getElement(0);
    Assert.assertEquals("dimension count", 2, table.getRowDimensions().size());
    Assert.assertEquals("indicator type", DimensionType.Indicator, table.getRowDimensions().get(0).getType());
    Assert.assertTrue("admin subclass", table.getRowDimensions().get(1) instanceof AdminDimension);
    Assert.assertEquals("level is 91", 91, ((AdminDimension) table.getRowDimensions().get(1)).getLevelId());
}
Also used : Report(org.activityinfo.shared.report.model.Report) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) Test(org.junit.Test)

Aggregations

AdminDimension (org.activityinfo.shared.report.model.AdminDimension)10 Dimension (org.activityinfo.shared.report.model.Dimension)7 DateDimension (org.activityinfo.shared.report.model.DateDimension)6 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)3 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)3 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 PivotSites (org.activityinfo.shared.command.PivotSites)2 Bucket (org.activityinfo.shared.command.result.Bucket)2 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)2 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)2 Report (org.activityinfo.shared.report.model.Report)2 Before (org.junit.Before)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 List (java.util.List)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1 User (org.activityinfo.server.database.hibernate.entity.User)1 DummyPivotTableData (org.activityinfo.server.report.DummyPivotTableData)1