use of org.activityinfo.server.database.hibernate.entity.Indicator 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);
// Generate the actual content
for (LayerGenerator layerGtor : layerGenerators) {
layerGtor.generate(map, content);
}
content.setIndicators(toDTOs(indicators.values()));
element.setContent(content);
}
use of org.activityinfo.server.database.hibernate.entity.Indicator in project activityinfo by bedatadriven.
the class PointLayerGenerator method queryFor.
private GetSites queryFor(Filter effectiveFilter, PointMapLayer layer) {
Filter layerFilter = new Filter(effectiveFilter, layer.getFilter());
boolean allMonthly = true;
for (int id : layer.getIndicatorIds()) {
Indicator indicator = indicators.get(id);
if (indicator.getAggregation() == IndicatorDTO.AGGREGATE_SITE_COUNT) {
layerFilter.addRestriction(DimensionType.Activity, indicator.getActivity().getId());
} else {
layerFilter.addRestriction(DimensionType.Indicator, indicator.getId());
}
if (allMonthly) {
allMonthly = indicator.getActivity().getReportingFrequency() == ActivityFormDTO.REPORT_MONTHLY;
}
}
layerFilter.addRestriction(DimensionType.Indicator, physicalIndicators(layer));
GetSites query = new GetSites();
query.setFilter(layerFilter);
query.setFetchAttributes(false);
query.setFetchAdminEntities(true);
query.setFetchAllIndicators(false);
query.setFetchIndicators(physicalIndicators(layer));
if (allMonthly) {
query.setFetchAllReportingPeriods(true);
query.setFetchLinks(false);
}
return query;
}
use of org.activityinfo.server.database.hibernate.entity.Indicator in project activityinfo by bedatadriven.
the class PiechartMapLayerGeneratorTest method testSomething.
@Test
public void testSomething() {
SiteDTO siteData = new SiteDTO();
siteData.setId(42);
siteData.setX(15.0);
siteData.setY(0.0);
siteData.setIndicatorValue(1, 50.0);
siteData.setIndicatorValue(2, 10.0);
siteData.setIndicatorValue(3, 20.0);
siteData.setIndicatorValue(4, 40.0);
PiechartMapLayer pcml = new PiechartMapLayer();
pcml.setMinRadius(10);
pcml.setMaxRadius(50);
pcml.addIndicatorId(1);
pcml.addIndicatorId(2);
pcml.addIndicatorId(3);
pcml.addIndicatorId(4);
pcml.setClustering(new NoClustering());
TiledMap map = new TiledMap(500, 600, new AiLatLng(15.0, 0.0), 6);
Map<Integer, Indicator> indicators = Maps.newHashMap();
indicators.put(1, new Indicator());
indicators.put(2, new Indicator());
indicators.put(3, new Indicator());
indicators.put(4, new Indicator());
PiechartLayerGenerator gen = new PiechartLayerGenerator(pcml, indicators);
gen.setSites(Arrays.asList(siteData));
MapContent mc = new MapContent();
gen.generate(map, mc);
assertThat(mc.getMarkers().size(), equalTo(1));
assertThat(((PieMapMarker) mc.getMarkers().get(0)).getSlices().size(), equalTo(4));
}
use of org.activityinfo.server.database.hibernate.entity.Indicator in project activityinfo by bedatadriven.
the class PivotChartGenerator method composeYAxisTitle.
/**
* @param element
* @return The value axis title, if specified explicitly, otherwise the
* units of the first indicator referenced
*/
protected String composeYAxisTitle(PivotChartReportElement element) {
if (element.getValueAxisTitle() != null) {
return element.getValueAxisTitle();
}
if (element.getIndicators() == null || element.getIndicators().size() <= 0) {
return "[Empty]";
}
int indicatorId = element.getIndicators().iterator().next();
Indicator indicator = indicatorDAO.findById(indicatorId);
return indicator != null ? indicator.getUnits() : "[Empty]";
}
use of org.activityinfo.server.database.hibernate.entity.Indicator in project activityinfo by bedatadriven.
the class MapGenerator method toDTOs.
private Set<IndicatorDTO> toDTOs(Collection<Indicator> indicators) {
Set<IndicatorDTO> indicatorDTOs = new HashSet<IndicatorDTO>();
for (Indicator indicator : indicators) {
IndicatorDTO indicatorDTO = new IndicatorDTO();
indicatorDTO.setId(indicator.getId());
indicatorDTO.setName(indicator.getName());
indicatorDTO.setType(FormFieldType.valueOf(indicator.getType()));
indicatorDTO.setExpression(indicator.getExpression());
indicatorDTO.setRelevanceExpression(indicator.getRelevanceExpression());
indicatorDTOs.add(indicatorDTO);
}
return indicatorDTOs;
}
Aggregations