Ragex.Analysis.Suggestions.Ranker
(Ragex v0.3.1)
View Source
Priority ranking system for refactoring suggestions.
Scores suggestions based on multiple factors:
- Benefit (40%): Expected improvement from refactoring
- Impact (20%): Scope of change (number of affected files/modules)
- Risk (20%): Likelihood of introducing bugs (subtracted)
- Effort (10%): Time/complexity to implement (subtracted)
- Confidence (10%): Confidence in the detection
Priority Levels
- critical (score > 0.8): Must address soon, high impact issues
- high (score > 0.6): Important improvements with good ROI
- medium (score > 0.4): Beneficial but not urgent
- low (score > 0.2): Optional improvements
- info (score <= 0.2): For awareness only
Examples
alias Ragex.Analysis.Suggestions.Ranker
suggestion = %{
pattern: :extract_function,
confidence: 0.85,
benefit_score: 0.8,
effort_score: 0.5,
impact: %{affected_files: 3, risk: :medium}
}
scored = Ranker.score_suggestion(suggestion)
# => %{...suggestion, priority: :high, priority_score: 0.72}
Summary
Functions
Adjusts priority score based on pattern-specific factors.
Calculates ROI (Return on Investment) for a suggestion.
Calculates statistics for a list of suggestions.
Classifies a numeric priority score into a priority level.
Compares two suggestions for sorting.
Generates a human-readable explanation of the scoring.
Filters suggestions by minimum priority level.
Groups suggestions by priority level.
Scores a suggestion and assigns a priority level.
Functions
Adjusts priority score based on pattern-specific factors.
Some patterns are inherently more important:
- Dead code removal: Low risk, easy win
- Complexity reduction: High benefit
- Coupling reduction: Medium-high effort, high benefit
Calculates ROI (Return on Investment) for a suggestion.
ROI = Benefit / Effort
Higher ROI means better return for the effort invested.
Calculates statistics for a list of suggestions.
Returns map with:
:total- Total number of suggestions:by_priority- Count by priority level:average_score- Average priority score:average_roi- Average ROI:high_priority_count- Count of high + critical
Classifies a numeric priority score into a priority level.
Examples
iex> Ranker.classify_priority(0.85)
:critical
iex> Ranker.classify_priority(0.65)
:high
iex> Ranker.classify_priority(0.15)
:info
Compares two suggestions for sorting.
Returns:
:gtif first has higher priority:ltif second has higher priority:eqif equal priority
Generates a human-readable explanation of the scoring.
Examples
explanation = Ranker.explain_score(suggestion)
IO.puts(explanation)
Filters suggestions by minimum priority level.
Examples
suggestions
|> Ranker.filter_by_priority(:high)
# Returns only :critical and :high priority suggestions
Groups suggestions by priority level.
Returns
Map with priority levels as keys and lists of suggestions as values.
Scores a suggestion and assigns a priority level.
Parameters
suggestion- Raw suggestion map from pattern detector
Returns
- Suggestion with added
:priorityand:priority_scorefields