Class: Vangrail::ScoreResult
- Inherits:
-
Object
- Object
- Vangrail::ScoreResult
- Defined in:
- lib/vangrail/score.rb
Overview
Validated output from one risk reader.
Constant Summary collapse
- STATUSES =
%i[ok abstained invalid].freeze
Instance Attribute Summary collapse
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#feature_schema ⇒ Object
readonly
Returns the value of attribute feature_schema.
-
#intervals ⇒ Object
readonly
Returns the value of attribute intervals.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#model_id ⇒ Object
readonly
Returns the value of attribute model_id.
-
#reader_id ⇒ Object
readonly
Returns the value of attribute reader_id.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
-
#scores ⇒ Object
readonly
Returns the value of attribute scores.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
- .abstained(reason:, **options) ⇒ Object
- .invalid(reason:, **options) ⇒ Object
- .ok(**options) ⇒ Object
Instance Method Summary collapse
- #abstained? ⇒ Boolean
-
#initialize(reader_id:, model_id:, feature_schema:, side:, scores: {}, status: :ok, reason: nil, cost: {}, intervals: {}, metadata: {}) ⇒ ScoreResult
constructor
A new instance of ScoreResult.
- #invalid? ⇒ Boolean
- #to_h ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(reader_id:, model_id:, feature_schema:, side:, scores: {}, status: :ok, reason: nil, cost: {}, intervals: {}, metadata: {}) ⇒ ScoreResult
Returns a new instance of ScoreResult.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/vangrail/score.rb', line 11 def initialize(reader_id:, model_id:, feature_schema:, side:, scores: {}, status: :ok, reason: nil, cost: {}, intervals: {}, metadata: {}) @reader_id = reader_id.to_s.freeze @model_id = model_id.to_s.freeze @feature_schema = Array(feature_schema).map(&:to_s).uniq.freeze @side = side.to_sym @status = status.to_sym raise ArgumentError, "unknown score status #{status}" unless STATUSES.include?(@status) @scores = numeric_hash(scores) @cost = numeric_hash(cost) @intervals = interval_hash(intervals) @metadata = immutable() @reason = reason&.to_s&.freeze validate_ok! freeze end |
Instance Attribute Details
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def cost @cost end |
#feature_schema ⇒ Object (readonly)
Returns the value of attribute feature_schema.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def feature_schema @feature_schema end |
#intervals ⇒ Object (readonly)
Returns the value of attribute intervals.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def intervals @intervals end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def @metadata end |
#model_id ⇒ Object (readonly)
Returns the value of attribute model_id.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def model_id @model_id end |
#reader_id ⇒ Object (readonly)
Returns the value of attribute reader_id.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def reader_id @reader_id end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def reason @reason end |
#scores ⇒ Object (readonly)
Returns the value of attribute scores.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def scores @scores end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def side @side end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/vangrail/score.rb', line 8 def status @status end |
Class Method Details
.abstained(reason:, **options) ⇒ Object
33 34 35 |
# File 'lib/vangrail/score.rb', line 33 def self.abstained(reason:, **) new(status: :abstained, reason: reason, scores: {}, **) end |
.invalid(reason:, **options) ⇒ Object
37 38 39 |
# File 'lib/vangrail/score.rb', line 37 def self.invalid(reason:, **) new(status: :invalid, reason: reason, scores: {}, **) end |
.ok(**options) ⇒ Object
29 30 31 |
# File 'lib/vangrail/score.rb', line 29 def self.ok(**) new(status: :ok, **) end |
Instance Method Details
#abstained? ⇒ Boolean
45 46 47 |
# File 'lib/vangrail/score.rb', line 45 def abstained? status == :abstained end |
#invalid? ⇒ Boolean
49 50 51 |
# File 'lib/vangrail/score.rb', line 49 def invalid? status == :invalid end |
#to_h ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vangrail/score.rb', line 53 def to_h { 'reader_id' => reader_id, 'model_id' => model_id, 'feature_schema' => feature_schema, 'side' => side.to_s, 'status' => status.to_s, 'scores' => scores, 'intervals' => (intervals unless intervals.empty?), 'cost' => (cost unless cost.empty?), 'metadata' => ( unless .empty?), 'reason' => reason, }.compact end |
#valid? ⇒ Boolean
41 42 43 |
# File 'lib/vangrail/score.rb', line 41 def valid? status == :ok end |