Search in sources :

Example 1 with DimensionType

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

the class ReportJsonFactory method encodeRestrictions.

public JsonArray encodeRestrictions(Map<DimensionType, Set<Integer>> restrictions) {
    JsonArray jsonRestrictions = new JsonArray();
    for (Entry<DimensionType, Set<Integer>> entry : restrictions.entrySet()) {
        JsonObject jsonEntry = new JsonObject();
        jsonEntry.addProperty("type", entry.getKey().toString());
        Set<Integer> set = entry.getValue();
        JsonArray jsonSet = new JsonArray();
        for (Integer val : set) {
            jsonSet.add(new JsonPrimitive(val));
        }
        jsonEntry.add("set", jsonSet);
        jsonRestrictions.add(jsonEntry);
    }
    return jsonRestrictions;
}
Also used : JsonArray(com.google.gson.JsonArray) DimensionType(org.activityinfo.shared.report.model.DimensionType) HashSet(java.util.HashSet) Set(java.util.Set) JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject)

Example 2 with DimensionType

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

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

the class BaseGenerator method generateFilterDescriptions.

protected List<FilterDescription> generateFilterDescriptions(Filter filter, Set<DimensionType> excludeDims, User user) {
    List<FilterDescription> list = new ArrayList<FilterDescription>();
    Set<DimensionType> filterDims = filter.getRestrictedDimensions();
    filterDims.removeAll(excludeDims);
    for (DimensionType type : filterDims) {
        DimensionLabels labels = dispatcher.execute(new GetDimensionLabels(type, filter.getRestrictions(type)));
        list.add(new FilterDescription(type, labels.getLabels()));
    }
    return list;
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) FilterDescription(org.activityinfo.shared.report.content.FilterDescription) ArrayList(java.util.ArrayList) GetDimensionLabels(org.activityinfo.shared.command.GetDimensionLabels) DimensionLabels(org.activityinfo.shared.command.GetDimensionLabels.DimensionLabels)

Example 4 with DimensionType

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

the class MapGenerator method generate.

@Override
public void generate(User user, MapReportElement element, Filter inheritedFilter, DateRange dateRange) {
    Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
    Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
    MapContent content = new MapContent();
    content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
    Map<Integer, Indicator> indicators = queryIndicators(element);
    // Set up layer generators
    List<LayerGenerator> layerGenerators = new ArrayList<LayerGenerator>();
    for (MapLayer layer : element.getLayers()) {
        if (layer.isVisible()) {
            LayerGenerator layerGtor = createGenerator(layer, indicators);
            layerGtor.query(getDispatcher(), effectiveFilter);
            layerGenerators.add(layerGtor);
        }
    }
    // FIRST PASS: calculate extents and margins
    int width = element.getWidth();
    int height = element.getHeight();
    AiLatLng center;
    int zoom;
    Extents extents = Extents.emptyExtents();
    Margins margins = new Margins(0);
    for (LayerGenerator layerGtor : layerGenerators) {
        extents.grow(layerGtor.calculateExtents());
        margins.grow(layerGtor.calculateMargins());
    }
    content.setExtents(extents);
    if (element.getCenter() == null) {
        // Now we're ready to calculate the zoom level
        // and the projection
        zoom = TileMath.zoomLevelForExtents(extents, width, height);
        center = extents.center();
    } else {
        center = element.getCenter();
        zoom = element.getZoomLevel();
    }
    content.setCenter(center);
    // Retrieve the basemap and clamp zoom level
    BaseMap baseMap = findBaseMap(element, indicators.values());
    if (zoom < baseMap.getMinZoom()) {
        zoom = baseMap.getMinZoom();
    }
    if (zoom > baseMap.getMaxZoom()) {
        zoom = baseMap.getMaxZoom();
    }
    if (zoom > element.getMaximumZoomLevel()) {
        zoom = element.getMaximumZoomLevel();
    }
    TiledMap map = new TiledMap(width, height, center, zoom);
    content.setBaseMap(baseMap);
    content.setZoomLevel(zoom);
    if (baseMap == null) {
        baseMap = TileBaseMap.createNullMap(element.getBaseMapId());
        LOGGER.log(Level.SEVERE, "Could not find base map id=" + element.getBaseMapId());
    }
    // Generate the actual content
    for (LayerGenerator layerGtor : layerGenerators) {
        layerGtor.generate(map, content);
    }
    content.setIndicators(toDTOs(indicators.values()));
    element.setContent(content);
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) MapContent(org.activityinfo.shared.report.content.MapContent) PiechartMapLayer(org.activityinfo.shared.report.model.layers.PiechartMapLayer) BubbleMapLayer(org.activityinfo.shared.report.model.layers.BubbleMapLayer) MapLayer(org.activityinfo.shared.report.model.layers.MapLayer) PolygonMapLayer(org.activityinfo.shared.report.model.layers.PolygonMapLayer) IconMapLayer(org.activityinfo.shared.report.model.layers.IconMapLayer) ArrayList(java.util.ArrayList) Extents(org.activityinfo.shared.util.mapping.Extents) Indicator(org.activityinfo.server.database.hibernate.entity.Indicator) GoogleBaseMap(org.activityinfo.shared.map.GoogleBaseMap) BaseMap(org.activityinfo.shared.map.BaseMap) TileBaseMap(org.activityinfo.shared.map.TileBaseMap) BubbleLayerGenerator(org.activityinfo.server.report.generator.map.BubbleLayerGenerator) PolygonLayerGenerator(org.activityinfo.server.report.generator.map.PolygonLayerGenerator) PiechartLayerGenerator(org.activityinfo.server.report.generator.map.PiechartLayerGenerator) IconLayerGenerator(org.activityinfo.server.report.generator.map.IconLayerGenerator) LayerGenerator(org.activityinfo.server.report.generator.map.LayerGenerator) Filter(org.activityinfo.shared.command.Filter) AiLatLng(org.activityinfo.shared.report.content.AiLatLng) Margins(org.activityinfo.server.report.generator.map.Margins) TiledMap(org.activityinfo.server.report.generator.map.TiledMap)

Example 5 with DimensionType

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

the class TableGenerator method generate.

@Override
public void generate(User user, TableElement element, Filter inheritedFilter, DateRange dateRange) {
    Filter filter = GeneratorUtils.resolveElementFilter(element, dateRange);
    Filter effectiveFilter = inheritedFilter == null ? filter : new Filter(inheritedFilter, filter);
    TableContent content = new TableContent();
    content.setFilterDescriptions(generateFilterDescriptions(filter, Collections.<DimensionType>emptySet(), user));
    TableData data = generateData(element, effectiveFilter);
    content.setData(data);
    if (element.getMap() != null) {
        mapGenerator.generate(user, element.getMap(), effectiveFilter, dateRange);
        Map<Integer, String> siteLabels = element.getMap().getContent().siteLabelMap();
        for (SiteDTO row : data.getRows()) {
            row.set("map", siteLabels.get(row.getId()));
        }
    }
    element.setContent(content);
}
Also used : DimensionType(org.activityinfo.shared.report.model.DimensionType) Filter(org.activityinfo.shared.command.Filter) SiteDTO(org.activityinfo.shared.dto.SiteDTO) TableData(org.activityinfo.shared.report.content.TableData) TableContent(org.activityinfo.shared.report.content.TableContent)

Aggregations

DimensionType (org.activityinfo.shared.report.model.DimensionType)17 Filter (org.activityinfo.shared.command.Filter)5 ArrayList (java.util.ArrayList)4 SqlQuery (com.bedatadriven.rebar.sql.client.query.SqlQuery)2 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 Set (java.util.Set)2 FilterDescription (org.activityinfo.shared.report.content.FilterDescription)2 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 LocalDate (com.bedatadriven.rebar.time.calendar.LocalDate)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Indicator (org.activityinfo.server.database.hibernate.entity.Indicator)1 BubbleLayerGenerator (org.activityinfo.server.report.generator.map.BubbleLayerGenerator)1 IconLayerGenerator (org.activityinfo.server.report.generator.map.IconLayerGenerator)1 LayerGenerator (org.activityinfo.server.report.generator.map.LayerGenerator)1 Margins (org.activityinfo.server.report.generator.map.Margins)1