(self, timestamp, delay, value)
Inserts a new observation to the buffer.

    This function implicitly updates the internal "clock" of this buffer to
    the timestamp of the new observation, and the internal buffer is trimmed
    accordingly, i.e. at most `buffer_size` items whose delayed arrival time
    preceeds `timestamp` are kept.

    Args:
      timestamp: The time at which this observation was made.
      delay: The amount of delay between the time at which this observation was
        made and the time at which it is delivered.
      value: The value of this observation.

    Raises:
      ValueError: if `delay` is negative.
Inserts a new observation to the buffer.
Inserts a new observation to the buffer .
def insert(self, timestamp, delay, value):
    """Inserts a new observation to the buffer.

    This function implicitly updates the internal "clock" of this buffer to
    the timestamp of the new observation, and the internal buffer is trimmed
    accordingly, i.e. at most `buffer_size` items whose delayed arrival time
    preceeds `timestamp` are kept.

    Args:
      timestamp: The time at which this observation was made.
      delay: The amount of delay between the time at which this observation was
        made and the time at which it is delivered.
      value: The value of this observation.

    Raises:
      ValueError: if `delay` is negative.
    """
    # If using `pad_with_initial_value`, the `arrived_deque` would be empty.
    # We can now pad it with the initial value now.
    if not self._arrived_deque:
      for _ in range(self._buffer_size):
        self._arrived_deque.append(InFlightObservation(-np.inf, 0, value))

    self._update_arrived_deque(timestamp)
    new_obs = InFlightObservation(timestamp, delay, np.array(value))
    arrival = new_obs.arrival
    if delay == 0:
      # No delay, so the new observation is due for immediate delivery.
      # Add it to the arrived deque.
      self._arrived_deque.append(new_obs)
    elif delay > 0:
      if not self._pending_deque or arrival > self._pending_deque[-1].arrival:
        # New observation's arrival time is monotonic.
        # Technically, we can handle this in the general code branch below,
        # but since this is assumed to be the "typical" case, the special
        # handling here saves us from repeatedly allocating and deallocating
        # an empty temporary deque.
        self._pending_deque.append(new_obs)
      else:
        # General, out-of-order observation.
        arriving_after_new_obs = collections.deque()
        while self._pending_deque and arrival < self._pending_deque[-1].arrival:
          arriving_after_new_obs.appendleft(self._pending_deque.pop())
        self._pending_deque.append(new_obs)
        for existing_obs in arriving_after_new_obs:
          self._pending_deque.append(existing_obs)
    else:
      raise ValueError('`delay` should not be negative: '
                       'got {!r}'.format(delay))
def insert ( self , timestamp , delay , value ) : # If using `pad_with_initial_value`, the `arrived_deque` would be empty. # We can now pad it with the initial value now. if not self . _arrived_deque : for _ in range ( self . _buffer_size ) : self . _arrived_deque . append ( InFlightObservation ( - np . inf , 0 , value ) ) self . _update_arrived_deque ( timestamp ) new_obs = InFlightObservation ( timestamp , delay , np . array ( value ) ) arrival = new_obs . arrival if delay == 0 : # No delay, so the new observation is due for immediate delivery. # Add it to the arrived deque. self . _arrived_deque . append ( new_obs ) elif delay > 0 : if not self . _pending_deque or arrival > self . _pending_deque [ - 1 ] . arrival : # New observation's arrival time is monotonic. # Technically, we can handle this in the general code branch below, # but since this is assumed to be the "typical" case, the special # handling here saves us from repeatedly allocating and deallocating # an empty temporary deque. self . _pending_deque . append ( new_obs ) else : # General, out-of-order observation. arriving_after_new_obs = collections . deque ( ) while self . _pending_deque and arrival < self . _pending_deque [ - 1 ] . arrival : arriving_after_new_obs . appendleft ( self . _pending_deque . pop ( ) ) self . _pending_deque . append ( new_obs ) for existing_obs in arriving_after_new_obs : self . _pending_deque . append ( existing_obs ) else : raise ValueError ( '`delay` should not be negative: ' 'got {!r}' . format ( delay ) )