class Perforat::ResultsProcessor
Attributes
formatter[R]
settings[R]
Public Class Methods
new(contents:, formatter: default_formatter, settings: Perforat.settings)
click to toggle source
# File lib/perforat/results_processor.rb, line 3 def initialize(contents:, formatter: default_formatter, settings: Perforat.settings) @formatter = formatter @contents = contents @settings = settings end
Public Instance Methods
call()
click to toggle source
# File lib/perforat/results_processor.rb, line 9 def call results = @contents.map(&parse_info).inject(&:merge) results.values.map(&:keys).inject(&:&).map do |test_name| durations = results.map(&tests_by(test_name)).reverse [test_name, durations, durations.inject(&:/)] end .sort_by(&by_coefficient_increasing) .last(settings.fetch(:results_count)) .reject(&by_low_results) .each(&formatter) end
Private Instance Methods
by_coefficient_increasing()
click to toggle source
# File lib/perforat/results_processor.rb, line 38 def by_coefficient_increasing -> (_, _, coefficient) { coefficient } end
by_low_results()
click to toggle source
# File lib/perforat/results_processor.rb, line 42 def by_low_results lambda do |_, durations, coefficient| durations.all? { |duration| duration < settings.fetch(:minimal_duration) } || coefficient - 1 < settings.fetch(:minimal_epsilon) end end
default_formatter()
click to toggle source
# File lib/perforat/results_processor.rb, line 53 def default_formatter lambda do |(test_name, durations, coefficient)| puts "#{test_name}: #{durations[1]} -> #{durations[0]} coefficient: #{coefficient}" end end
parse_info()
click to toggle source
# File lib/perforat/results_processor.rb, line 24 def parse_info lambda do |info| { parse_timestamp(info.shift.first) => info.map(&present_test_info).inject(&:merge) } end end
parse_timestamp(timestamp)
click to toggle source
# File lib/perforat/results_processor.rb, line 49 def parse_timestamp(timestamp) Time.at(timestamp.to_i).to_datetime end
present_test_info()
click to toggle source
# File lib/perforat/results_processor.rb, line 30 def present_test_info -> (test, time) { { test => time.to_f } } end
tests_by(test_name)
click to toggle source
# File lib/perforat/results_processor.rb, line 34 def tests_by(test_name) -> (_, tests) { tests.fetch(test_name) } end