Class: CompletionKit::Metric
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- CompletionKit::Metric
- Defined in:
- app/models/completion_kit/metric.rb
Constant Summary collapse
- DEFAULT_RUBRIC_BANDS =
[ { "stars" => 5, "description" => "Fully meets or exceeds all criteria. No meaningful issues." }, { "stars" => 4, "description" => "Meets criteria well. Minor issues only." }, { "stars" => 3, "description" => "Meets criteria adequately. Some room for improvement." }, { "stars" => 2, "description" => "Partially meets criteria. Significant gaps or frequent errors." }, { "stars" => 1, "description" => "Fails to meet the criteria. Major errors or completely off-target." } ].freeze
Class Method Summary collapse
- .default_rubric_bands ⇒ Object
- .default_rubric_text ⇒ Object
- .normalize_rubric_bands(raw_bands) ⇒ Object
- .rubric_text_for(bands) ⇒ Object
Instance Method Summary collapse
Class Method Details
.default_rubric_bands ⇒ Object
25 26 27 |
# File 'app/models/completion_kit/metric.rb', line 25 def self.default_rubric_bands DEFAULT_RUBRIC_BANDS.map(&:dup) end |
.default_rubric_text ⇒ Object
29 30 31 |
# File 'app/models/completion_kit/metric.rb', line 29 def self.default_rubric_text rubric_text_for(default_rubric_bands) end |
.normalize_rubric_bands(raw_bands) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/completion_kit/metric.rb', line 41 def self.normalize_rubric_bands(raw_bands) bands = raw_bands.is_a?(Hash) ? raw_bands.values : Array(raw_bands) band_map = bands.each_with_object({}) do |band, acc| next unless band.respond_to?(:to_h) normalized = band.to_h.stringify_keys.slice("stars", "description") stars = normalized["stars"].to_i next unless (1..5).cover?(stars) acc[stars] = { "stars" => stars, "description" => normalized["description"].to_s.strip } end default_rubric_bands.map do |default_band| stars = default_band["stars"] band = band_map[stars] { "stars" => stars, "description" => band && band["description"].present? ? band["description"] : default_band["description"] } end end |
.rubric_text_for(bands) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/completion_kit/metric.rb', line 33 def self.rubric_text_for(bands) Array(bands).sort_by { |b| -(b["stars"] || 0) }.map do |band| stars = band["stars"].to_i label = stars == 1 ? "1 star" : "#{stars} stars" "#{label}: #{band["description"]}" end.join("\n\n") end |
Instance Method Details
#as_json(options = {}) ⇒ Object
74 75 76 77 78 79 80 |
# File 'app/models/completion_kit/metric.rb', line 74 def as_json( = {}) { id: id, name: name, key: key, instruction: instruction, evaluation_steps: evaluation_steps, rubric_bands: rubric_bands, created_at: created_at, updated_at: updated_at } end |
#display_rubric_text ⇒ Object
70 71 72 |
# File 'app/models/completion_kit/metric.rb', line 70 def display_rubric_text self.class.rubric_text_for(rubric_bands_for_form) end |
#rubric_bands_for_form ⇒ Object
66 67 68 |
# File 'app/models/completion_kit/metric.rb', line 66 def rubric_bands_for_form self.class.normalize_rubric_bands(rubric_bands) end |