Class: LabTech::Result

Inherits:
ApplicationRecord show all
Defined in:
app/models/lab_tech/result.rb

Constant Summary collapse

DEFAULT_COMPARISON =
->(control, candidate) {
  [ control, candidate ].map { |obs|
    "    %20s # => %s" % [ obs.name, obs.value.inspect ]
  }
}

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.record_a_science(experiment, scientist_result) ⇒ Object

CLASS METHODS #####



31
32
33
34
35
# File 'app/models/lab_tech/result.rb', line 31

def self.record_a_science( experiment, scientist_result )
  self.create!(experiment: experiment) do |result|
    result.record_a_science scientist_result
  end
end

Instance Method Details

#candidateObject

Having multiple candidates is annoying; I’ve mistyped this one a lot



42
43
44
# File 'app/models/lab_tech/result.rb', line 42

def candidate
  candidates.first
end

#compare_observations(io: $stdout, &block) ⇒ Object



51
52
53
54
55
56
57
# File 'app/models/lab_tech/result.rb', line 51

def compare_observations(io: $stdout, &block)
  block ||= DEFAULT_COMPARISON
  candidates.each do |candidate|
    io.puts block.( control, candidate )
  end
  return nil
end

#record_a_science(scientist_result) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/lab_tech/result.rb', line 59

def record_a_science(scientist_result)
  unless scientist_result.kind_of?( Scientist::Result )
    raise ArgumentError, "expected a Scientist::Result but got #{scientist_result.class}"
  end

  self.context = scientist_result.context

  record_observation scientist_result.control
  scientist_result.candidates.each do |candidate|
    record_observation candidate
  end

  record_simple_stats scientist_result
end

#speedupObject



74
75
76
77
78
79
80
81
82
83
# File 'app/models/lab_tech/result.rb', line 74

def speedup
  return nil unless candidates.count == 1

  LabTech::Speedup.new(
    baseline:   control.duration,
    comparison: candidate.duration,
    time:       time_delta,
    factor:     speedup_factor,
  )
end

#timed_out?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/lab_tech/result.rb', line 85

def timed_out?
  candidates.any?(&:timed_out?)
end