batch.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. from matplotlib import pyplot
  2. from os import listdir
  3. def is_numeric(x):
  4. try:
  5. float(x)
  6. except ValueError:
  7. return False
  8. return True
  9. avg_lap_time = {}
  10. avg_pos = {}
  11. avg_speed = {}
  12. avg_top = {}
  13. total_rescued = {}
  14. tests = len(listdir('../../batch'))-1
  15. for file in listdir('../../batch'):
  16. if (file == '.DS_Store'):
  17. continue
  18. f = open('../../batch/'+file,'r')
  19. '''
  20. name_index = file.find('.')
  21. kart_name = str(file[:name_index])
  22. first = file.find('.',name_index+1)
  23. track_name = file[name_index+1:first]
  24. second = file.find('.',first+1)
  25. run = int(file[first+1:second])
  26. '''
  27. track_name = "snowmountain"
  28. kart_names = ["gnu", "sara", "tux", "elephpant"]
  29. if track_name == "snowmountain":
  30. contents = f.readlines()
  31. '''
  32. contents = contents[2:contents.index("[debug ] profile: \n")-1]
  33. content = [s for s in contents if kart_name in s]
  34. data = [float(x) for x in content[0].split() if is_numeric(x)]
  35. if kart_name not in avg_lap_time:
  36. avg_lap_time[kart_name] = []
  37. avg_pos[kart_name] = []
  38. avg_speed[kart_name] = []
  39. avg_top[kart_name] = []
  40. total_rescued[kart_name] = []
  41. avg_lap_time[kart_name].append(data[2]/4)
  42. avg_pos[kart_name].append(data[1])
  43. avg_speed[kart_name].append(data[3])
  44. avg_top[kart_name].append(data[4])
  45. total_rescued[kart_name].append(data[7])
  46. '''
  47. contents = contents[2:6] #TODO check if all is in here
  48. for kart in kart_names:
  49. content = [s for s in contents if kart in s]
  50. data = [float(x) for x in content[0].split() if is_numeric(x)]
  51. if kart not in avg_lap_time:
  52. avg_lap_time[kart] = []
  53. avg_pos[kart] = []
  54. avg_speed[kart] = []
  55. avg_top[kart] = []
  56. total_rescued[kart] = []
  57. avg_lap_time[kart].append(data[2]/4)
  58. avg_pos[kart].append(data[1])
  59. avg_speed[kart].append(data[3])
  60. avg_top[kart].append(data[4])
  61. total_rescued[kart].append(data[7])
  62. tests = len(avg_lap_time["gnu"])
  63. print total_rescued
  64. for kart in kart_names:
  65. print "rescues for ", kart , ": ", sum(total_rescued[kart])/tests
  66. print "avg_lap_time for " , kart , ": " , sum(avg_lap_time[kart])/tests
  67. print "avg_pos for " , kart , ": " , sum(avg_pos[kart])/tests
  68. print "avg_speed for " , kart , ": " , sum(avg_speed[kart])/tests
  69. print "avg_top for " , kart , ": " , sum(avg_top[kart])/tests
  70. pyplot.subplot(2,2,1)
  71. pyplot.plot(list(xrange(tests)),avg_pos["gnu"], "b-")
  72. pyplot.xlabel("tests")
  73. pyplot.ylabel("gnu")
  74. pyplot.subplot(2,2,2)
  75. pyplot.plot(list(xrange(tests)),avg_pos["sara"], "r-")
  76. pyplot.xlabel("tests")
  77. pyplot.ylabel("sara")
  78. pyplot.subplot(2,2,3)
  79. pyplot.plot(list(xrange(tests)),avg_pos["elephpant"], "y-")
  80. pyplot.xlabel("tests")
  81. pyplot.ylabel("elephpant")
  82. pyplot.subplot(2,2,4)
  83. pyplot.plot(list(xrange(tests)),avg_pos["tux"], "g-")
  84. pyplot.xlabel("tests")
  85. pyplot.ylabel("tux")
  86. pyplot.show()