@Override public DataTable getTimeBasedReport(String executionID, int resolution) { String reportNodeClass = "step.artefacts.collection.CallFunctionReportNode"; DataTable t = new DataTable(); final double normalizationFactor = (1.0*resolution)/1000; collection.aggregate("{$match:{executionID:'"+executionID+"',_class:'"+reportNodeClass+"'}}"). and("{$group:{_id:{time:{$subtract:[\"$executionTime\",{$mod:[\"$executionTime\","+resolution+"]}]}},value:{$sum:1}}}"). and("{$sort:{\"_id\":1}}").map(new ResultHandler<TableRow>() { @Override public TableRow map(DBObject result) { Date date = new Date((long) ((DBObject)result.get("_id")).get("time")); double value = new Double((Integer) result.get("value"))/normalizationFactor; TableRow r = new TableRow(date, value); return r; } }).forEach(row->t.addRow(row)); return t; }