PageRenderTime 45ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/utils/latency/lib/score.rb

http://github.com/AF83/ucengine
Ruby | 41 lines | 34 code | 5 blank | 2 comment | 0 complexity | 8f941b1b1328599883c3720bb9530c7e MD5 | raw file
  1. ## Score is a hash with any key but value can only be an array.
  2. class Score < Hash
  3. def initialize(*args)
  4. super(*args)
  5. self.default_proc = proc do |hash, key|
  6. hash[key] = []
  7. end
  8. end
  9. def sort!
  10. self.each do |key, value|
  11. self[key].sort!
  12. end
  13. self
  14. end
  15. def to_csv
  16. buff = ""
  17. self.each do |k, v|
  18. buff += "#{k};#{self.get_9_decile k}\n"
  19. end
  20. buff
  21. end
  22. def to_all_csv
  23. buff = ""
  24. self.each do |k, vs|
  25. vs.each do |v|
  26. buff += "#{k};#{v}\n"
  27. end
  28. end
  29. buff
  30. end
  31. ## get the 9nth decile
  32. def get_9_decile key
  33. v = self[key]
  34. v[v.length * 0.9]
  35. end
  36. end