aggregate and groupBy arrays of json with sum, sumProduct and weighted average fields. (like a "flattened pivot")