'Aggregate values from events
@param period: the period
@param events: the events'

def aggregate(self, period, events):

    values = []
    append = values.append
    method = self.method
    base = self.base_column
    if (method == 'cumulate'):
        slope = self.slope_column
        duration = period.duration
        for event in events:
            if (event.start == None):
                continue
            if base:
                base_value = event[base]
            else:
                base_value = None
            if slope:
                slope_value = event[slope]
            else:
                slope_value = None
            if (base_value is None):
                if ((not slope) or (slope_value is None)):
                    continue
                else:
                    base_value = 0
            elif (type(base_value) is list):
                try:
                    base_value = sum(base_value)
                except (TypeError, ValueError):
                    continue
            if (slope_value is None):
                if ((not base) or (base_value is None)):
                    continue
                else:
                    slope_value = 0
            elif (type(slope_value) is list):
                try:
                    slope_value = sum(slope_value)
                except (TypeError, ValueError):
                    continue
            interval = self.interval
            if (slope_value and interval):
                event_duration = duration(event, interval)
            else:
                event_duration = 1
            append((base_value, slope_value, event_duration))
        result = self.compute(values)
    elif base:
        for event in events:
            value = event[base]
            if (value is None):
                continue
            elif (type(value) is list):
                values.extend([v for v in value if (v is not None)])
            else:
                values.append(value)
        if (method == 'count'):
            result = len(values)
        else:
            result = self.compute(values)
    else:
        result = None
    return result
