'Aggregate values down to the second and store as:
"dogstream": [(metric, timestamp, value, {key: val})]
If there are many values per second for a metric, take the median'

def _aggregate(self, values):

    output = []
    values.sort(key=point_sorter)
    for ((timestamp, metric, host_name, device_name), val_attrs) in groupby(values, key=point_sorter):
        attributes = {}
        vals = []
        for (_metric, _timestamp, v, a) in val_attrs:
            try:
                v = float(v)
                vals.append(v)
                attributes.update(a)
            except Exception:
                self.logger.debug('Could    not    convert    %s    into    a    float', v)
        if (len(vals) == 1):
            val = vals[0]
        elif (len(vals) > 1):
            val = vals[(-1)]
        else:
            continue
        metric_type = str(attributes.get('metric_type', '')).lower()
        if (metric_type == 'gauge'):
            val = float(val)
        elif (metric_type == 'counter'):
            val = sum(vals)
        output.append((metric, timestamp, val, attributes))
    if output:
        return {'dogstream': output}
    else:
        return {}
