class CucumberStatistics::StepStatistics

Public Class Methods

new() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 3
def initialize
  @all = Hash.new
end

Public Instance Methods

all() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 37
def all
  @all
end
average_times_plot_data() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 58
def average_times_plot_data
  @all.map {|step_name, data| data[:average].to_f}.sort.reverse
end
calculate() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 24
def calculate
  @all.each do |step_name, step_results|
    step_results[:total] = step_results[:instances].inject{|sum,x| sum + x }
    step_results[:count] = step_results[:instances].count
    step_results[:average] = step_results[:total].to_f / step_results[:count].to_f
    step_results[:fastest] = step_results[:instances].sort.first
    step_results[:slowest] = step_results[:instances].sort.last
    step_results[:variation] = step_results[:slowest] - step_results[:fastest]
    step_results[:variance] = self.sample_variance step_results[:instances]
    step_results[:standard_deviation] = self.standard_deviation step_results[:variance]
  end
end
highest_average() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 46
def highest_average
  sort_by_property(:average).reverse.first
end
highest_total() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 50
def highest_total
  sort_by_property(:total).reverse.first
end
highest_variation() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 54
def highest_variation
  sort_by_property(:variation).reverse.first
end
record(step_name, duration, file_colon_line) click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 7
def record step_name, duration, file_colon_line

  # "/Users/kross/alienfast/acme/features/account management/admin_cancel_account.feature:8"
  step_results = @all[step_name]
  step_results ||= Hash.new
  step_results[:instances] ||= []
  step_results[:instances] << duration
  begin
    file = file_colon_line[file_colon_line.index('features')..-1]
    step_results[:file] = file
  rescue Exception => e
    step_results[:file] = e.message
  end

  @all[step_name] ||= step_results
end
sample_variance(data) click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 74
def sample_variance data
  count = data.count
  average = data.inject{|sum,x| sum + x } / count.to_f

  return nil if count <= 1
  
  sum = data.inject(0){|acc,i|acc.to_f + (i.to_f - average)**2.0}

  return 1 / (count.to_f - 1.0) * sum.to_f
end
sort_by_property(property) click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 41
def sort_by_property property
  result = @all.sort {|a,b| a.last[property.to_sym] <=> b.last[property.to_sym]}
  result
end
standard_deviation(sample_variance) click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 85
def standard_deviation sample_variance
  return nil if sample_variance.nil?
  
  return Math.sqrt(sample_variance)
end
step_part_of_total() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 66
def step_part_of_total
  @all.map {|step_name, data| data[:total]}.sort.reverse
end
total_elapsed_time() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 70
def total_elapsed_time
  @all.map {|step_name, data| data[:total]}.inject{|sum,x| sum + x }
end
total_times_plot_data() click to toggle source
# File lib/cucumber_statistics/step_statistics.rb, line 62
def total_times_plot_data
  sort_by_property(:average).reverse.map {|step_name, data| data[:total].to_f}
end