'Group and aggregate the events in this period
@param facts: list of facts to aggregate'

def aggregate(self, facts):

    self._reset()
    rows = self.rows = {}
    cols = self.cols = {}
    matrix = self.matrix = {}
    totals = []
    if (not isinstance(facts, (list, tuple))):
        facts = [facts]
    if any(((fact.method == 'cumulate') for fact in facts)):
        self.group(cumulative=True)
    else:
        self.group()
    for fact in facts:
        method = fact.method
        if (method == 'cumulate'):
            events = dict(self.pevents)
            events.update(self.cevents)
            cumulative = True
        else:
            events = self.cevents
            cumulative = False
        fact_aggregate = fact.aggregate
        aggregate = (lambda items: fact_aggregate(self, items))
        for (key, event_sets) in self._rows.items():
            event_ids = event_sets[0]
            if cumulative:
                event_ids |= event_sets[1]
            items = [events[event_id] for event_id in event_ids]
            if (key not in rows):
                rows[key] = [aggregate(items)]
            else:
                rows[key].append(aggregate(items))
        for (key, event_sets) in self._cols.items():
            event_ids = event_sets[0]
            if cumulative:
                event_ids |= event_sets[1]
            items = [events[event_id] for event_id in event_ids]
            if (key not in cols):
                cols[key] = [aggregate(items)]
            else:
                cols[key].append(aggregate(items))
        for (key, event_sets) in self._matrix.items():
            event_ids = event_sets[0]
            if cumulative:
                event_ids |= event_sets[1]
            items = [events[event_id] for event_id in event_ids]
            if (key not in matrix):
                matrix[key] = [aggregate(items)]
            else:
                matrix[key].append(aggregate(items))
        totals.append(aggregate(events.values()))
    self.totals = totals
    return totals
