Class: RSpec::FlakeClassifier::Predictor
- Inherits:
-
Object
- Object
- RSpec::FlakeClassifier::Predictor
- Defined in:
- lib/rspec/flake/classifier/predictor.rb,
sig/rspec/flake/classifier.rbs
Defined Under Namespace
Classes: Trainer
Constant Summary collapse
- WEIGHTS =
{ "duration" => 0.15, "uses_network" => 0.2, "uses_filesystem" => 0.08, "uses_time" => 0.15, "uses_randomness" => 0.15, "uses_concurrency" => 0.17, "uses_async_wait" => 0.2 }.freeze
Instance Attribute Summary collapse
-
#weights ⇒ Hash[String, Float]
readonly
Returns the value of attribute weights.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(weights: WEIGHTS) ⇒ Predictor
constructor
A new instance of Predictor.
- #rank(feature_sets) ⇒ Array[Hash[String, untyped]]
- #score(features) ⇒ Float
- #to_h ⇒ Hash[String, Hash[String, Float]]
Constructor Details
Instance Attribute Details
#weights ⇒ Hash[String, Float] (readonly)
Returns the value of attribute weights.
18 19 20 |
# File 'lib/rspec/flake/classifier/predictor.rb', line 18 def weights @weights end |
Class Method Details
.load(path) ⇒ Predictor
24 25 26 27 |
# File 'lib/rspec/flake/classifier/predictor.rb', line 24 def self.load(path) payload = JSON.parse(File.read(path)) new(weights: payload.fetch("weights", payload)) end |
Instance Method Details
#rank(feature_sets) ⇒ Array[Hash[String, untyped]]
40 41 42 43 44 |
# File 'lib/rspec/flake/classifier/predictor.rb', line 40 def rank(feature_sets) Array(feature_sets).map do |features| features.merge("flake_score" => score(features), "priority" => priority(score(features))) end.sort_by { |features| -features.fetch("flake_score") } end |
#score(features) ⇒ Float
33 34 35 36 37 38 |
# File 'lib/rspec/flake/classifier/predictor.rb', line 33 def score(features) score = weights.sum do |key, weight| feature_score(features, key) * weight end [[score, 0.0].max, 1.0].min.round(4) end |
#to_h ⇒ Hash[String, Hash[String, Float]]
46 47 48 |
# File 'lib/rspec/flake/classifier/predictor.rb', line 46 def to_h { "weights" => weights } end |