class_docstr: A monitor wrapper for Gym environments, it is used to know the episode reward, length, time and other data.
  
  :param env: (gym.Env) The environment
  :param filename: (Optional[str]) the location to save a log file, can be None for no log
  :param allow_early_resets: (bool) allows the reset of the environment before it is done
  :param reset_keywords: (tuple) extra keywords for the reset call, if extra parameters are needed at reset
  :param info_keywords: (tuple) extra information to log, from the information return of environment.step
code: def __init__(
      self,
      env: gym.Env,
      filename: Optional[str],
      allow_early_resets: bool = True,
      reset_keywords=(),
      info_keywords=(),
  ):
      super(Monitor, self).__init__(env=env)
      self.t_start = time.time()
      if filename is None:
          self.file_handler = None
          self.logger = None
      else:
          if not filename.endswith(Monitor.EXT):
              if os.path.isdir(filename):
                  filename = os.path.join(filename, Monitor.EXT)
              else:
                  filename = filename + "." + Monitor.EXT
          self.file_handler = open(filename, "wt")
          self.file_handler.write(
              "#%s\n"
              % json.dumps(
                  {
                      "t_start": self.t_start,
                      "env_id": env.spec and env.spec.id,
                  }
              )
          )
          self.logger = csv.DictWriter(
              self.file_handler,
              fieldnames=("r", "l", "t")
              + reset_keywords
              + info_keywords,
          )
          self.logger.writeheader()
          self.file_handler.flush()
  
      self.reset_keywords = reset_keywords
      self.info_keywords = info_keywords
      self.allow_early_resets = allow_early_resets
      self.rewards = None
      self.needs_reset = True
      self.episode_rewards = []
      self.episode_lengths = []
      self.episode_times = []
      self.total_steps = 0
      self.current_reset_info = {}
  
imports: import csv
  import json
  import os
  import time
  from glob import glob
  from typing import Tuple, Dict, Any, List, Optional
  import gym
  import pandas
  import numpy
label_desc: Use image node_id 1 to create a new Monitor object from inherited base classes: gym with example: obj = Monitor(env, filename, allow_early_resets, reset_keywords, info_keywords)