BatchWindowMax extends BatchWindowAggregate { public Datum aggregate(List<Datum> data) { if (data.isEmpty()) return new Datum(new ArrayList<>(), new ArrayRealVector(dim)); dim = data.get(0).metrics().getDimension(); RealVector results = new ArrayRealVector(dim); results.set(Double.MIN_VALUE); for (Datum d : data) { RealVector metrics = d.metrics(); for (int i = 0; i < dim; i ++) { if (timeColumn != null && i == timeColumn) continue; results.setEntry(i, Math.max(results.getEntry(i), metrics.getEntry(i))); } } return new Datum(new ArrayList<>(), results); } BatchWindowMax();  BatchWindowMax(MacroBaseConf conf); Datum aggregate(List<Datum> data);  }
@Test public void testAggregate() throws Exception { Random r = new Random(0); List<Datum> data = new ArrayList<>(); for (int i = 0; i < 10; i ++) { Datum d = new Datum(new ArrayList<>(), new ArrayRealVector(3)); d.metrics().setEntry(0, 1); if (i == 0) { d.metrics().setEntry(1, r.nextInt()); } else { d.metrics().setEntry(1, Integer.MAX_VALUE); } d.metrics().setEntry(2, i); data.add(d); } BatchWindowMax windowMax = new BatchWindowMax(); Datum max = windowMax.aggregate(data); assert(max.metrics().getEntry(0) == 1); assert(max.metrics().getEntry(1) == Integer.MAX_VALUE); assert(max.metrics().getEntry(2) == 9); MacroBaseConf conf = new MacroBaseConf().set(MacroBaseConf.TIME_COLUMN, 2); windowMax = new BatchWindowMax(conf); max = windowMax.aggregate(data); assert(max.metrics().getEntry(0) == 1); assert(max.metrics().getEntry(1) == Integer.MAX_VALUE); }