BatchWindowAvg 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(); double[] results = new double[dim]; for (Datum d : data) { RealVector metrics = d.metrics(); for (int i = 0; i < dim; i ++) { if (timeColumn != null && i == timeColumn) continue; results[i] += metrics.getEntry(i) / data.size(); } } return new Datum(new ArrayList<>(), new ArrayRealVector(results)); } BatchWindowAvg();  BatchWindowAvg(MacroBaseConf conf); Datum aggregate(List<Datum> data);  }
@Test public void testAggregate() throws Exception { List<Datum> data = new ArrayList<>(); for (int i = 0; i < 10; i ++) { Datum d = new Datum(new ArrayList<>(), new ArrayRealVector(2)); d.metrics().setEntry(0, i); d.metrics().setEntry(1, 1); data.add(d); } BatchWindowAvg windowAvg = new BatchWindowAvg(); Datum avg = windowAvg.aggregate(data); assertEquals(avg.metrics().getEntry(0), 4.5, 1e-5); assertEquals(avg.metrics().getEntry(1), 1, 1e-5); MacroBaseConf conf = new MacroBaseConf().set(MacroBaseConf.TIME_COLUMN, 0); windowAvg = new BatchWindowAvg(conf); avg = windowAvg.aggregate(data); assert(avg.metrics().getEntry(0) == 0); assertEquals(avg.metrics().getEntry(1), 1, 1e-5); }