def aggregate(aggregationMethod, values):
  # Filter out None values
  knownValues = list(filter(lambda x: x is not None, values))
  if len(knownValues) is 0:
    return None
  # Aggregate based on method
  if aggregationMethod == 'average':
    return float(sum(knownValues)) / float(len(knownValues))
  elif aggregationMethod == 'sum':
    return float(sum(knownValues))
  elif aggregationMethod == 'last':
    return knownValues[-1]
  elif aggregationMethod == 'max':
    return max(knownValues)
  elif aggregationMethod == 'min':
    return min(knownValues)
  else:
    raise InvalidAggregationMethod("Unrecognized aggregation method %s" %
                                   aggregationMethod)