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
-
.record_a_science(experiment, scientist_result, **kwargs) ⇒ Object
CLASS METHODS #####.
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, **kwargs) ⇒ 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, **kwargs ) self.create!(experiment: experiment) do |result| result.record_a_science scientist_result, **kwargs end end |
Instance Method Details
#candidate ⇒ Object
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, diff_with: nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/lab_tech/result.rb', line 53 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 = diff_with&.call(scientist_result.control, candidate) record_observation candidate, diff: diff end record_simple_stats scientist_result end |
#speedup ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/lab_tech/result.rb', line 69 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
80 81 82 |
# File 'app/models/lab_tech/result.rb', line 80 def timed_out? candidates.any?(&:timed_out?) end |