Module: Observ::Scoreable

Extended by:
ActiveSupport::Concern
Included in:
DatasetRunItem, Session, Trace
Defined in:
app/models/concerns/observ/scoreable.rb

Instance Method Summary collapse

Instance Method Details

#manual_scoreObject

Returns the manual score (name="manual", source="manual")



25
26
27
# File 'app/models/concerns/observ/scoreable.rb', line 25

def manual_score
  score_for("manual", source: :manual)
end

#score_for(name, source: nil) ⇒ Object

Find a score by name, optionally filtered by source Returns the most recent score if multiple exist



13
14
15
16
17
# File 'app/models/concerns/observ/scoreable.rb', line 13

def score_for(name, source: nil)
  scope = scores.where(name: name)
  scope = scope.where(source: source) if source
  scope.order(created_at: :desc).first
end

#score_summaryObject

Returns a hash of score names to their average values



30
31
32
# File 'app/models/concerns/observ/scoreable.rb', line 30

def score_summary
  scores.group(:name).average(:value).transform_values { |v| v.round(4) }
end

#scored?Boolean

Returns true if any scores exist for this record

Returns:

  • (Boolean)


20
21
22
# File 'app/models/concerns/observ/scoreable.rb', line 20

def scored?
  scores.exists?
end