Class: LabTech::Result
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LabTech::Result
- 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
-
#candidate ⇒ Object
Having multiple candidates is annoying; I’ve mistyped this one a lot.
- #compare_observations(io: $stdout, &block) ⇒ Object
- #record_a_science(scientist_result, diff_with: nil) ⇒ Object
- #speedup ⇒ Object
- #timed_out? ⇒ Boolean
Class Method Details
.record_a_science(experiment, scientist_result, *args) ⇒ Object
27 28 29 30 31 |
# File 'app/models/lab_tech/result.rb', line 27 def record_a_science( experiment, scientist_result, *args ) create!(experiment: experiment) do |result| result.record_a_science scientist_result, *args end end |
Instance Method Details
#candidate ⇒ Object
Having multiple candidates is annoying; I’ve mistyped this one a lot
40 41 42 |
# File 'app/models/lab_tech/result.rb', line 40 def candidate candidates.first end |
#compare_observations(io: $stdout, &block) ⇒ Object
49 50 51 52 53 54 55 |
# File 'app/models/lab_tech/result.rb', line 49 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, diff_with: nil) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/lab_tech/result.rb', line 57 def record_a_science(scientist_result, diff_with: nil) 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| diff = nil if diff_with # Pass values to the diff block, not the observations themselves cont = scientist_result.control.value cand = candidate.value diff = diff_with&.call(cont, cand) end record_observation candidate, diff: diff end record_simple_stats scientist_result end |
#speedup ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'app/models/lab_tech/result.rb', line 80 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
91 92 93 |
# File 'app/models/lab_tech/result.rb', line 91 def timed_out? candidates.any?(&:timed_out?) end |