class Utils::Histogram
Public Class Methods
new(file_path,ex_type)
click to toggle source
# 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
Public Instance Methods
derivate_to_line(hist_index,row_index)
click to toggle source
# 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() { |r,temp| ... }
click to toggle source
# 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() { |r,temp| ... }
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/ruby_pager/histogram.rb, line 47 def process_limit(values) @limits.push({:start => values[0],:end => values[1]}) end
process_line(line)
click to toggle source
# 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)
click to toggle source
# 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