'Reduces samples at different timestamps into interval time bins.'

def DownsampleList(self, samples, interval):

    current_bin = None
    last_sample_seen = None
    for sample in samples:
        timestamp = sample.timestamp.AsSecondsFromEpoch()
        time_bin = (timestamp - (timestamp % interval))
        if (current_bin is None):
            current_bin = time_bin
            last_sample_seen = sample
        elif ((current_bin != time_bin) and last_sample_seen):
            (yield last_sample_seen)
            current_bin = time_bin
            last_sample_seen = sample
        else:
            last_sample_seen.Average(sample)
    if last_sample_seen:
        (yield last_sample_seen)
