web/app/models/benchmark_result.rb
author Marcel Hlopko <marcel.hlopko@gmail.com>
Tue, 25 Jun 2013 23:35:43 +0200
changeset 110 02126b7e1cbb
parent 108 69aa849f6930
child 131 6b91c5b58be4
child 133 bef72dea1e7e
permissions -rw-r--r--
imports fixed and nicely working

# == 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
#

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

  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

end