/utils/latency/lib/score.rb
Ruby | 41 lines | 34 code | 5 blank | 2 comment | 0 complexity | 8f941b1b1328599883c3720bb9530c7e MD5 | raw file
- ## Score is a hash with any key but value can only be an array.
- class Score < Hash
- def initialize(*args)
- super(*args)
- self.default_proc = proc do |hash, key|
- hash[key] = []
- end
- end
- def sort!
- self.each do |key, value|
- self[key].sort!
- end
- self
- end
- def to_csv
- buff = ""
- self.each do |k, v|
- buff += "#{k};#{self.get_9_decile k}\n"
- end
- buff
- end
- def to_all_csv
- buff = ""
- self.each do |k, vs|
- vs.each do |v|
- buff += "#{k};#{v}\n"
- end
- end
- buff
- end
- ## get the 9nth decile
- def get_9_decile key
- v = self[key]
- v[v.length * 0.9]
- end
- end