Class: StudFinder::Scorer
- Inherits:
-
Object
- Object
- StudFinder::Scorer
- Defined in:
- lib/stud_finder/scorer.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: ValidationError
Constant Summary collapse
- DEFAULT_WEIGHTS =
{ fan_in: 0.19, fan_out: 0.095, complexity: 0.2375, churn: 0.2375, coverage: 0.095, interaction: 0.095, coupling: 0.05 }.freeze
- BASE_WEIGHT_KEYS =
%i[fan_in fan_out complexity churn].freeze
- WEIGHT_KEYS =
%i[fan_in fan_out complexity churn coverage interaction coupling].freeze
- COMPLEXITY_FLOOR =
15- FAN_IN_FLOOR =
25
Instance Attribute Summary collapse
-
#normalized_weights ⇒ Object
readonly
Returns the value of attribute normalized_weights.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(files:, fan_in:, fan_out:, complexity:, churn:, churn_lines: nil, loc: nil, loc_pct: nil, coverage: nil, weights: DEFAULT_WEIGHTS, branch_threshold: 50, trunk_threshold: 85, coupling: nil) ⇒ Scorer
constructor
A new instance of Scorer.
Constructor Details
#initialize(files:, fan_in:, fan_out:, complexity:, churn:, churn_lines: nil, loc: nil, loc_pct: nil, coverage: nil, weights: DEFAULT_WEIGHTS, branch_threshold: 50, trunk_threshold: 85, coupling: nil) ⇒ Scorer
Returns a new instance of Scorer.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stud_finder/scorer.rb', line 22 def initialize(files:, fan_in:, fan_out:, complexity:, churn:, churn_lines: nil, loc: nil, loc_pct: nil, coverage: nil, weights: DEFAULT_WEIGHTS, branch_threshold: 50, trunk_threshold: 85, coupling: nil) @files = files @fan_in = fan_in @fan_out = fan_out @complexity = complexity @churn = churn @churn_lines = churn_lines || churn @loc = loc || @files.to_h { |file| [file, 0] } @loc_pct = loc_pct @coverage = coverage @weights = weights @branch_threshold = branch_threshold @trunk_threshold = trunk_threshold @coupling = coupling @warnings = [] validate! @normalized_weights = normalize_weights end |
Instance Attribute Details
#normalized_weights ⇒ Object (readonly)
Returns the value of attribute normalized_weights.
20 21 22 |
# File 'lib/stud_finder/scorer.rb', line 20 def normalized_weights @normalized_weights end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
20 21 22 |
# File 'lib/stud_finder/scorer.rb', line 20 def warnings @warnings end |
Instance Method Details
#call ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/stud_finder/scorer.rb', line 42 def call pcts = { fan_in: Normalizer.percentile_rank(@fan_in, @files), fan_out: Normalizer.percentile_rank(@fan_out, @files), complexity: Normalizer.percentile_rank(@complexity, @files), churn: composite_churn_pct, loc: @loc_pct || Normalizer.percentile_rank(@loc, @files), instability: instability_pct, coupling: coupling_pct, coverage: coverage_risk_pct } @warnings = insufficient_dispersion_warnings(pcts) scores = @files.to_h { |file| [file, weighted_score(file, pcts)] } score_pcts = Normalizer.percentile_rank(scores, @files) rows = @files.each_with_index.map do |file, index| [index, result_row(file, scores.fetch(file), pcts, score_pcts.fetch(file))] end rows.sort_by { |index, row| [-row[:score], index] } .map.with_index(1) do |(_index, row), rank| row.merge(rank: rank) end end |