class_docstr: This wrapper will keep track of cumulative rewards and episode lengths.
  
  At the end of an episode, the statistics of the episode will be added to ``info``
  using the key ``episode``. If using a vectorized environment also the key
  ``_episode`` is used which indicates whether the env at the respective index has
  the episode statistics.
  
  After the completion of an episode, ``info`` will look like this::
  
      >>> info = {
      ...     ...
      ...     "episode": {
      ...         "r": "<cumulative reward>",
      ...         "l": "<episode length>",
      ...         "t": "<elapsed time since instantiation of wrapper>"
      ...     },
      ... }
  
  For a vectorized environments the output will be in the form of::
  
      >>> infos = {
      ...     ...
      ...     "episode": {
      ...         "r": "<array of cumulative reward>",
      ...         "l": "<array of episode length>",
      ...         "t": "<array of elapsed time since instantiation of wrapper>"
      ...     },
      ...     "_episode": "<boolean array of length num-envs>"
      ... }
  
  Moreover, the most recent rewards and episode lengths are stored in buffers that can be accessed via
  :attr:`wrapped_env.return_queue` and :attr:`wrapped_env.length_queue` respectively.
  
  Attributes:
      return_queue: The cumulative rewards of the last ``deque_size``-many episodes
      length_queue: The lengths of the last ``deque_size``-many episodes
docstr: This wrapper will keep track of cumulative rewards and episode lengths.
  
  Args:
      env (Env): The environment to apply the wrapper
      deque_size: The size of the buffers :attr:`return_queue` and :attr:`length_queue`
docstr_tok: ["This","wrapper","will","keep","track","of","cumulative","rewards","and","episode","lengths",".","Args",":","env","(","Env",")",":","The","environment","to","apply","the","wrapper","deque_size",":","The","size","of","the","buffers",":","attr",":","`","return_queue","`","and",":","attr",":","`","length_queue","`"]
code: def __init__(self, env: gym.Env, deque_size: int = 100):
      """This wrapper will keep track of cumulative rewards and episode lengths.
  
      Args:
          env (Env): The environment to apply the wrapper
          deque_size: The size of the buffers :attr:`return_queue` and :attr:`length_queue`
      """
      super().__init__(env)
      self.num_envs = getattr(env, "num_envs", 1)
      self.t0 = time.perf_counter()
      self.episode_count = 0
      self.episode_returns: Optional[np.ndarray] = None
      self.episode_lengths: Optional[np.ndarray] = None
      self.return_queue = deque(maxlen=deque_size)
      self.length_queue = deque(maxlen=deque_size)
      self.is_vector_env = getattr(env, "is_vector_env", False)
  
file_path: gym/gym/wrappers/record_episode_statistics.py
imports: import time
  from collections import deque
  from typing import Optional
  import numpy
  import gym
label_desc: Use image node_id 1 to create a new RecordEpisodeStatistics object from inherited base classes: gym with example: obj = RecordEpisodeStatistics(env, deque_size)