calibrate.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import sys
  2. operations = {}
  3. with open("calibration/result", 'r') as f:
  4. for l in f:
  5. try:
  6. op, t = l.split(": ")
  7. t = float(t)
  8. operations.setdefault(op, []).append(t)
  9. except:
  10. pass
  11. with open("calibration/averages", 'w') as averages:
  12. with open("calibration/plot", 'w') as plot:
  13. for op in operations:
  14. avg = sum(operations[op]) / len(operations[op])
  15. op_max = avg * 3
  16. new_list = []
  17. with open("calibration/distribution_%s" % op, 'w') as f:
  18. for t in sorted(operations[op]):
  19. if t < op_max:
  20. f.write("%.17f\n" % t)
  21. averages.write("%20s: %.17f\n" % (op, avg))
  22. plot.write("set terminal postscript enhanced colour portrait size 6,6\n")
  23. plot.write("set xtics rotate by -45\n")
  24. plot.write("n = 20\n")
  25. plot.write("max=%s\n" % op_max)
  26. plot.write("width=max/n\n")
  27. plot.write("set boxwidth width absolute\n")
  28. plot.write("set style fill solid 1.0 noborder\n")
  29. plot.write("rounded(x)=width*floor(x/width)+width/2\n")
  30. plot.write("set out 'calibration/plot_%s.eps'\n" % op)
  31. plot.write("set ylabel 'Frequency (time)'\n")
  32. plot.write("set xlabel 'Duration (s)'\n")
  33. plot.write("set title 'Operation %s'\n" % op.replace("_", "\\_"))
  34. plot.write("plot 'calibration/distribution_%s' u (rounded($1)):(1) smooth freq w boxes title ''\n" % op)