Method: LabTech::Result#record_a_science

Defined in:
app/models/lab_tech/result.rb

#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