class BenchmarkResult < ActiveRecord::Base
belongs_to :benchmark_info, inverse_of: :benchmark_results
belongs_to :benchmark_batch, inverse_of: :benchmark_results
has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result
has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result
def average_duration
sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration }
sum / benchmark_durations.size
end
def min_duration
benchmark_durations.map { |duration| duration.duration }.min
end
def max_duration
benchmark_durations.map { |duration| duration.duration }.max
end
def to_json
{ timestamp: performed_at.to_i, value: min_duration }
end
def performed_at
benchmark_batch.performed_at
end
def benchmark_name
benchmark_info.name
end
def benchmark_parameters_json
JSON.generate(benchmark_parameters.collect { |p| p.to_json } )
end
end
# == Schema Information
#
# Table name: benchmark_results
#
# id :integer not null, primary key
# benchmark_info_id :integer
# created_at :datetime
# updated_at :datetime
# benchmark_batch_id :integer
#