private Map<Integer, Map> parseAggregations(Histogram date_agg, TileIndex tileIndex) { List<? extends Histogram.Bucket> dateBuckets = date_agg.getBuckets(); Map<Integer, Map> result = new HashMap<>(); long maxval = 0; for (Histogram.Bucket dateBucket : dateBuckets) { Histogram cluster_agg = dateBucket.getAggregations().get("yField"); List<? extends Histogram.Bucket> clusterBuckets = cluster_agg.getBuckets(); BinIndex xBinIndex = tilePyramid.rootToBin(dateBucket.getKeyAsNumber().doubleValue(), 0, tileIndex); int xBin = xBinIndex.getX(); Map<Integer,Long> intermediate = new HashMap<>(); result.put(xBin, intermediate); for( Histogram.Bucket clusterBucket : clusterBuckets) { //given the bin coordinates, see if there's any data in those bins, add values to existing bins BinIndex binIndex = tilePyramid.rootToBin(dateBucket.getKeyAsNumber().doubleValue(), clusterBucket.getKeyAsNumber().doubleValue(), tileIndex); int yBin = binIndex.getY(); if (result.containsKey(xBin) && result.get(xBin).containsKey(yBin)) { intermediate.put(yBin, (long) intermediate.get(yBin) + clusterBucket.getDocCount()); } else if (result.containsKey(xBin) && !(intermediate.containsKey(yBin))) { intermediate.put(yBin, clusterBucket.getDocCount()); } if (maxval < clusterBucket.getDocCount()){ maxval = clusterBucket.getDocCount(); } } } return result; }
private Point getBinCoordinates (double x, double y) { Point2D point = new Point2D.Double(x, y); TileIndex tile = _pyramid.rootToTile(point, _level); if (tile.getXBins() != _numXBins && tile.getYBins() != _numYBins) { tile = new TileIndex(tile.getLevel(), tile.getX(), tile.getY(), _numXBins, _numYBins); } BinIndex bin = _pyramid.rootToBin(point, tile); return new Point(tile.getX()*tile.getXBins()+bin.getX(), tile.getY()*tile.getYBins()+(tile.getYBins()-1-bin.getY())); }
@Override public List<TileAndBinIndices> getIndicesByLevel( AnnotationData<?> data, int level, TilePyramid pyramid ) { List<TileAndBinIndices> tileAndBins = new LinkedList<>(); if ( !data.isRangeBased() ) { // point annotation Double x = ( data.getX() == null ) ? 0 : data.getX(); Double y = ( data.getY() == null ) ? 0 : data.getY(); // map from x and y to tile and bin TileIndex tile = pyramid.rootToTile( x, y, level, NUM_BINS, NUM_BINS ); BinIndex bin = pyramid.rootToBin( x, y, tile ); tileAndBins.add( new TileAndBinIndices( tile, bin ) ); return tileAndBins; } else { // range annotations Double x0 = ( data.getX0() == null ) ? 0 : data.getX0(); Double y0 = ( data.getY0() == null ) ? 0 : data.getY0(); Double x1 = ( data.getX1() == null ) ? 0 : data.getX1(); Double y1 = ( data.getY1() == null ) ? 0 : data.getY1(); // bottom left TileIndex tileBL = pyramid.rootToTile(x0, y0, level, NUM_BINS, NUM_BINS); // top right TileIndex tileTR = pyramid.rootToTile( x1, y1, level, NUM_BINS, NUM_BINS ); for (int i=tileBL.getX(); i<=tileTR.getX(); i++) { for (int j=tileBL.getY(); j <= tileTR.getY(); j++) { tileAndBins.add( new TileAndBinIndices( new TileIndex(level, i, j, NUM_BINS, NUM_BINS ), RANGE_BIN ) ); } } } return tileAndBins; }