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;
}
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();
}
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;
}
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());
}
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());
}
Aggregations