class StepStats::Stats

Attributes

stats[RW]

Public Class Methods

new(*args) click to toggle source
# File lib/step_stats/stats.rb, line 5
def initialize(*args)
  @stats = {}
  @step_counter = "STEP-000"
  @steps = {}
end

Public Instance Methods

add_stat(step_definition, duration, status, location) click to toggle source
# File lib/step_stats/stats.rb, line 11
def add_stat step_definition, duration, status, location
  step_number = get_step_number step_definition.regexp_source
  if @stats[step_number].nil?
    @stats[step_number] = Step.new(step_definition.regexp_source, step_definition.file_colon_line)
  end
  step_entry = {duration: duration, status: status, location: location}
  @stats[step_number].add step_entry
end
get_step_number(step_regx) click to toggle source
# File lib/step_stats/stats.rb, line 20
def get_step_number step_regx
  @steps[step_regx] = @step_counter.next!.dup if @steps[step_regx].nil?
  @steps[step_regx]
end
percent(step,rounding='ceil') click to toggle source
# File lib/step_stats/stats.rb, line 25
def percent step,rounding='ceil'
  ((step.total/total_time)*100).send(rounding)
end
to_chart_data() click to toggle source
# File lib/step_stats/stats.rb, line 49
def to_chart_data
  @stats.values.each.map{|s|[s.name,s.total,s.location]}.to_s
end
top30() click to toggle source
# File lib/step_stats/stats.rb, line 41
def top30
  (@stats.values.count*0.3).ceil
end
top30count() click to toggle source
# File lib/step_stats/stats.rb, line 33
def top30count
  @stats.values.sort_by{|step| step.count}.reverse[0..top30]
end
top30time() click to toggle source
# File lib/step_stats/stats.rb, line 37
def top30time
  @stats.values.sort_by{|step| step.avg}.reverse[0..top30]
end
total_time() click to toggle source
# File lib/step_stats/stats.rb, line 45
def total_time
  @stats.values.inject(0){|accum,step| accum+step.total}.to_f
end