Class: Utils::Histogram
- Inherits:
-
Object
- Object
- Utils::Histogram
- Defined in:
- lib/ruby_pager/histogram.rb
Instance Method Summary collapse
- #derivate_to_line(hist_index, row_index) ⇒ Object
- #each_derivate ⇒ Object
- #each_line ⇒ Object
-
#initialize(file_path, ex_type) ⇒ Histogram
constructor
A new instance of Histogram.
- #load_file(file_path) ⇒ Object
- #process_data_line(values) ⇒ Object
- #process_limit(values) ⇒ Object
- #process_line(line) ⇒ Object
- #to_line(hist_index, row_index) ⇒ Object
Constructor Details
#initialize(file_path, ex_type) ⇒ Histogram
Returns a new instance of Histogram.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ruby_pager/histogram.rb', line 7 def initialize(file_path,ex_type) @logger = Utils::ApplicationLogger.instance @logger.level = Logger::INFO @limits= [] @type = ex_type.to_sym @histogram= Hash.new{|h,key|h[key]=Array.new} @derivate= Hash.new{|h,key|h[key]=Array.new} @logger.info("Loading histogram") load_file(file_path) end |
Instance Method Details
#derivate_to_line(hist_index, row_index) ⇒ Object
77 78 79 |
# File 'lib/ruby_pager/histogram.rb', line 77 def derivate_to_line(hist_index,row_index) return [@limits[hist_index][:start],((@limits[hist_index][:end] - @limits[hist_index][:start])*@derivate[hist_index][row_index]*2000).to_i+ @limits[hist_index][:start]] end |
#each_derivate ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/ruby_pager/histogram.rb', line 91 def each_derivate @buckets.times do |r| temp = [] @num_histograms.times do |h| temp.push(derivate_to_line(h,r)) end yield r,temp end end |
#each_line ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/ruby_pager/histogram.rb', line 81 def each_line @buckets.times do |r| temp = [] @num_histograms.times do |h| temp.push(to_line(h,r)) end yield r,temp end end |
#load_file(file_path) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ruby_pager/histogram.rb', line 18 def load_file(file_path) File.open(file_path, "r") do |file| while (line = file.gets) process_line(line) end end puts "BUCKETS ARE #{@buckets}" puts "HISTOGRAMS ARE #{@histogram.size}" puts "HISTOGRAMS ARE #{@histogram[0].size}" end |
#process_data_line(values) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ruby_pager/histogram.rb', line 52 def process_data_line(values) if @type == :basic values.each_index{|i| @histogram[i].push(values[i])} else values.each_index do |i| if i.even? @histogram[i/2].push(values[i]) else @derivate[(i-1)/2].push(values[i]) end end end end |
#process_limit(values) ⇒ Object
47 48 49 50 |
# File 'lib/ruby_pager/histogram.rb', line 47 def process_limit(values) @limits.push({:start => values[0],:end => values[1]}) end |
#process_line(line) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_pager/histogram.rb', line 30 def process_line(line) values = line.split @buckets = values[1].to_i if values[0] == "NumVect" if values[0]== "NumParam" @num_histograms = values[1].to_i @num_histograms/=2 if @type == :derivate end process_limit(values[1..2].map{|val| val.to_i}) if values[0] == "Limit" @logger.info("Processing data") if values[0] == "Data" process_data_line(values.map{|val| val.to_f})if values[0] =~ /\d/ end |
#to_line(hist_index, row_index) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/ruby_pager/histogram.rb', line 67 def to_line(hist_index,row_index) #return [@limits[hist_index][:start],((@limits[hist_index][:end] - @limits[hist_index][:start])*@histogram[hist_index][row_index]*100).to_i+ @limits[hist_index][:start]] return [@limits[hist_index][:start],((@limits[hist_index][:end] - @limits[hist_index][:start])*(@histogram[hist_index][row_index])/100).to_i+ @limits[hist_index][:start]] if hist_index < 3 return [@limits[hist_index][:start],((@limits[hist_index][:end] - @limits[hist_index][:start])*@histogram[hist_index][row_index]*200).to_i+ @limits[hist_index][:start]] if hist_index == 3 return [@limits[hist_index][:start],((@limits[hist_index][:end] - @limits[hist_index][:start])*@histogram[hist_index][row_index]*2000).to_i+ @limits[hist_index][:start]] if hist_index > 3 end |