class Stepdown::Statistics
Attributes
grouping[R]
scenarios[R]
step_collection[R]
usages[R]
Public Class Methods
new(scenarios, step_collection)
click to toggle source
# File lib/stepdown/statistics.rb, line 8 def initialize(scenarios, step_collection) @scenarios = scenarios @step_collection = step_collection end
Public Instance Methods
empty()
click to toggle source
# File lib/stepdown/statistics.rb, line 157 def empty @empty_scenarios ||= @scenarios.select do |scen| scen.steps.empty? end @empty_scenarios end
empty_rest()
click to toggle source
# File lib/stepdown/statistics.rb, line 149 def empty_rest empty[10..empty.length] || [] end
empty_top(limit = 10)
click to toggle source
# File lib/stepdown/statistics.rb, line 153 def empty_top(limit = 10) empty[0...limit] end
generate()
click to toggle source
# File lib/stepdown/statistics.rb, line 13 def generate puts "Performing analysis..." unless Stepdown.quiet groupings step_usages empty steps_per_scenario unique_steps end
groupings()
click to toggle source
# File lib/stepdown/statistics.rb, line 39 def groupings @groupings ||= grouping(@scenarios) end
groupings_rest()
click to toggle source
# File lib/stepdown/statistics.rb, line 31 def groupings_rest groupings[10..groupings.length] || [] end
groupings_top(limit = 10)
click to toggle source
# File lib/stepdown/statistics.rb, line 35 def groupings_top(limit = 10) groupings[0...limit] end
step_usage(scenarios)
click to toggle source
# File lib/stepdown/statistics.rb, line 75 def step_usage(scenarios) usages = @step_collection.collect{|step| Stepdown::StepUsage.new(step) } scenarios.each do |scenario| scenario.steps.each do |step| usage = usages.detect{|use| use.step.id == step.id} if usage usage.total_usage += step.count usage.number_scenarios += 1 end end end usages.each do |usage| if usage.number_scenarios > 0 use = sprintf "%.2f", (usage.total_usage / Float(usage.number_scenarios)) usage.use_scenario = use end end usages.sort{|a,b| b.total_usage <=> a.total_usage} end
step_usages()
click to toggle source
# File lib/stepdown/statistics.rb, line 106 def step_usages @step_usages ||= step_usage(@scenarios) end
steps_per_scenario()
click to toggle source
# File lib/stepdown/statistics.rb, line 51 def steps_per_scenario @steps_per_scenario ||= steps_scenario(@scenarios) end
steps_scenario(scenarios)
click to toggle source
# File lib/stepdown/statistics.rb, line 140 def steps_scenario(scenarios) scen_count = scenarios.length step_count = 0.0 scenarios.each do |scenario| step_count += scenario.step_count end sprintf "%.2f", (step_count / scen_count) end
to_h()
click to toggle source
# File lib/stepdown/statistics.rb, line 22 def to_h stats = {} stats[:number_scenarios] = total_scenarios stats[:total_steps] = total_steps stats[:steps_per_scenario] = steps_per_scenario stats[:unused_steps] = unused_step_count stats end
total_scenarios()
click to toggle source
# File lib/stepdown/statistics.rb, line 43 def total_scenarios @scenarios.length end
total_steps()
click to toggle source
# File lib/stepdown/statistics.rb, line 47 def total_steps @step_collection.length end
uniq_steps_per_scenario(scenarios)
click to toggle source
# File lib/stepdown/statistics.rb, line 130 def uniq_steps_per_scenario(scenarios) total_steps = 0.0 uniq_steps = 0.0 scenarios.each do |scen| total_steps += scen.step_count uniq_steps += scen.unique_step_count end sprintf "%.2f", (total_steps / uniq_steps) end
unique_steps()
click to toggle source
# File lib/stepdown/statistics.rb, line 55 def unique_steps @uniq_steps_per_scenario ||= uniq_steps_per_scenario(@scenarios) end
unused()
click to toggle source
# File lib/stepdown/statistics.rb, line 122 def unused step_usages.select{|use| use.total_usage == 0} end
unused_rest()
click to toggle source
# File lib/stepdown/statistics.rb, line 114 def unused_rest unused[10..unused.length] || [] end
unused_step_count()
click to toggle source
# File lib/stepdown/statistics.rb, line 126 def unused_step_count unused.length end
unused_top(limit = 10)
click to toggle source
# File lib/stepdown/statistics.rb, line 118 def unused_top(limit = 10) unused[0...limit] end
usages_rest()
click to toggle source
# File lib/stepdown/statistics.rb, line 102 def usages_rest usages[10..usages.length] || [] end
usages_top(limit = 10)
click to toggle source
# File lib/stepdown/statistics.rb, line 98 def usages_top(limit = 10) usages[0...limit] end