major refactoring to consolidate common aggregation functions

After adding initial support for aggregating old/past data, it was evident that
there was a lot of duplicate functionality around aggregating past and current
data. This commit introduces a new class, BaseAggregator, which contains common
functions. Aggregation has been renamed to CacheAggregator since it only works
with data out of the metrics_cache table.

This is also the initial commit for CacheIterator. The computeAggregates
function, in its previous forms, took a list of result sets as input. The
computations to be performed for past and current data is the same, but the
format of the input differed. Now the input is an Iterable so that the function
can be used with both past and current data.