plot-experience.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/usr/bin/env python3
  2. import sys
  3. import matplotlib.pyplot as plt
  4. import matplotlib as mpl
  5. import vcclib
  6. def run(args):
  7. git_dirs = args[0].split(':')
  8. # the paths in the git dir to filter on (use "" or . to use everything)
  9. project_paths = args[1].split(':')
  10. # the directory where experiences are stored
  11. exp_dirs = vcclib.expdirs(args[2].split(':'))
  12. counts = vcclib.count_all_commits(git_dirs, project_paths, exp_dirs, {})
  13. cuml_tot = [sum(c.total for c in counts[:j+1]) for j in range(len(counts))]
  14. return cuml_tot
  15. def main(argv):
  16. # the path+name of where to save the resulting plot
  17. frac_path = argv[9]
  18. tot_path = argv[10]
  19. cuml_tot1 = run(argv[1:4])
  20. label1 = argv[4]
  21. cuml_tot2 = run(argv[5:8])
  22. label2 = argv[8]
  23. cuml_frac1 = [v/cuml_tot1[-1] for v in cuml_tot1]
  24. cuml_frac2 = [v/cuml_tot2[-1] for v in cuml_tot2]
  25. xs1 = [x+1 for x in range(len(cuml_tot1))]
  26. xs2 = [x+1 for x in range(len(cuml_tot2))]
  27. plt.rc('text', usetex=True)
  28. plt.rc('font', family='serif', size=18)
  29. mpl.rcParams["text.latex.preamble"] = \
  30. "\\usepackage{relsize}\n\\usepackage{xspace}"
  31. l1 = plt.plot(xs1, cuml_frac1, 'b+',
  32. label=r"{} $c_{{\le j}}$".format(label1))
  33. l2 = plt.plot(xs2, cuml_frac2, 'rs',
  34. label=r"{} $c_{{\le j}}$".format(label2))
  35. plt.xlabel("$j=$ Experience")
  36. plt.ylabel("Fraction of projects' commits")
  37. plt.xscale('log')
  38. plt.yscale('log')
  39. plt.xlim(left=1)
  40. ax = plt.gca()
  41. plt.legend(loc='lower right')
  42. plt.tight_layout()
  43. plt.savefig(frac_path)
  44. l1.pop().remove()
  45. l2.pop().remove()
  46. plt.ylabel("Number of projects' commits")
  47. ax.set_ylim([1, 50000])
  48. plt.plot(xs1, cuml_tot1, 'b+', label=r"{} $c_{{\le j}}$".format(label1))
  49. plt.plot(xs2, cuml_tot2, 'rs', label=r"{} $c_{{\le j}}$".format(label2))
  50. plt.tight_layout()
  51. plt.savefig(tot_path)
  52. if __name__ == '__main__':
  53. main(sys.argv)