2 |
2 |
3 belongs_to :benchmark_info, inverse_of: :benchmark_results |
3 belongs_to :benchmark_info, inverse_of: :benchmark_results |
4 belongs_to :benchmark_batch, inverse_of: :benchmark_results |
4 belongs_to :benchmark_batch, inverse_of: :benchmark_results |
5 has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result |
5 has_many :benchmark_durations, dependent: :destroy, inverse_of: :benchmark_result |
6 has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result |
6 has_many :benchmark_parameters, dependent: :destroy, inverse_of: :benchmark_result |
7 |
|
8 scope :for_configuration_id, -> (configuration_id) do |
|
9 joins(:benchmark_batch). |
|
10 where("benchmark_batches.benchmark_configuration_id = ?", configuration_id) |
|
11 end |
|
12 |
|
13 scope :with_batch_and_duration_preloaded, -> do |
|
14 includes(:benchmark_batch, :benchmark_durations) |
|
15 end |
|
16 |
|
17 scope :newest_first, -> do |
|
18 order("benchmark_batches.performed_at desc, benchmark_batches.created_at desc") |
|
19 end |
|
20 |
7 |
21 def average_duration |
8 def average_duration |
22 sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration } |
9 sum = benchmark_durations.inject(0) { |acc, val| acc += val.duration } |
23 sum / benchmark_durations.size |
10 sum / benchmark_durations.size |
24 end |
11 end |