'Handle a sample, converting if necessary.'

def handle_sample(self, s):

    LOG.debug('handling    sample    %s', s)
    key = (s.name + s.resource_id)
    prev = self.cache.get(key)
    timestamp = timeutils.parse_isotime(s.timestamp)
    self.cache[key] = (s.volume, timestamp, s.monotonic_time)
    if prev:
        prev_volume = prev[0]
        prev_timestamp = prev[1]
        prev_monotonic_time = prev[2]
        if ((prev_monotonic_time is not None) and (s.monotonic_time is not None)):
            time_delta = (s.monotonic_time - prev_monotonic_time)
        else:
            time_delta = timeutils.delta_seconds(prev_timestamp, timestamp)
        if (time_delta < 0):
            LOG.warning(_('dropping    out    of    time    order    sample:    %s'), (s,))
            self.cache[key] = prev
            return None
        volume_delta = ((s.volume - prev_volume) if ((prev_volume <= s.volume) or (s.type != sample.TYPE_CUMULATIVE)) else s.volume)
        rate_of_change = (((1.0 * volume_delta) / time_delta) if time_delta else 0.0)
        s = self._convert(s, rate_of_change)
        LOG.debug('converted    to:    %s', s)
    else:
        LOG.warning(_('dropping    sample    with    no    predecessor:    %s'), (s,))
        s = None
    return s
