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



25
26
27
28
29
# File 'app/models/lab_tech/result.rb', line 25

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



36
37
38
# File 'app/models/lab_tech/result.rb', line 36

def candidate
  candidates.first
end

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



45
46
47
48
49
50
51
# File 'app/models/lab_tech/result.rb', line 45

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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/lab_tech/result.rb', line 53

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



68
69
70
71
72
73
74
75
76
77
# File 'app/models/lab_tech/result.rb', line 68

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)


79
80
81
# File 'app/models/lab_tech/result.rb', line 79

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