text: import numpy as np
  import csv
  import matplotlib
  import matplotlib.pyplot
  import matplotlib.font_manager
  matplotlib.pyplot.rcParams["font.family"] = "Times New Roman"
  matplotlib.pyplot.rcParams['font.size'] = 20
  
  
  class PlotTrainingTimeTraffic(object):
      # Plot the training measures: training time and traffic generated during the learning process
      def __init__(self):
          pass
  
      def run(self, path=0):
          times = [[], [], []]
          traffic = [[], [], []]
  
          starter = "path" + str(path)
          output_dir = "./"
  
          file_algo = ["sarsa", "sarsa_lambda", "qlearning"]
  
          for index, fa in enumerate(file_algo):
              with open(starter + "_" + fa + ".csv", 'r') as csv_file:
                  reader = csv.reader(csv_file, delimiter=',')
                  next(reader, None)
                  for row in reader:
                      times[index].append(float(row[1]))
                      traffic[index].append(int(row[2]))
  
          avg_times = [np.mean(times[0]), np.mean(times[1]), np.mean(times[2])]
          std_dev_times = [np.std(times[0]), np.std(times[1]), np.std(times[2])]
          fig, ax = matplotlib.pyplot.subplots()
          # col = ax.bar(["SARSA", "SARSA(λ)", "Q-learning", "Q(λ)"], avg_times, align='center',
          #              yerr=std_dev_times)
  
          col = ax.boxplot(times)
  
          ax.set_xticklabels(["SARSA", "SARSA(λ)", "Q-learning"])
  
          # Add some text for labels, title and custom x-axis tick labels, etc.
          ax.set_ylabel('Time (s)')
          # ax.set_title('Training time per algorithm')
  
          matplotlib.pyplot.grid(True, color='gray', linestyle='dashed')
  
          fig.tight_layout()
  
          matplotlib.pyplot.savefig(output_dir + 'training_times.png')
          matplotlib.pyplot.show()
  
          avg_traffic = [np.mean(traffic[0]), np.mean(traffic[1]), np.mean(traffic[2])]
          std_dev_traffic = [np.std(traffic[0]), np.std(traffic[1]), np.std(traffic[2])]
          fig, ax = matplotlib.pyplot.subplots()
          # COLUMN BAR GRAPH
          # col = ax.bar(["SARSA", "SARSA(λ)", "Q-learning", "Q(λ)"], avg_traffic, align='center',
          #              yerr=std_dev_traffic)  # color=('#77FF82', '#47CC99', '#239DBA', '#006586'))
  
          # BOXPLOT GRAPH
          col = ax.boxplot(traffic)
  
          ax.set_xticklabels(["SARSA", "SARSA(λ)", "Q-learning"])
  
          # Add some text for labels, title and custom x-axis tick labels, etc.
          ax.set_ylabel('Number of commands sent')
          # ax.set_title('Traffic generated per algorithm')
  
          matplotlib.pyplot.grid(True, color='gray', linestyle='dashed')
  
          fig.tight_layout()
  
          matplotlib.pyplot.savefig(output_dir + 'training_traffic.png')
          matplotlib.pyplot.show()
  
  
  if __name__ == '__main__':
      # Get training time in seconds and traffic generated by training process, only sent commands
      # into a file that appends or writes:
      # Date | Training time | Sent commands
      # date | 123           |           150
      # As input file I need only the log file
      PlotTrainingTimeTraffic().run()
  
  # 1 sarsa, 2 sarsa_lambda, 3 qlearning, 4 qlearning_lambda
  