Module: HeapScope::Findings
- Defined in:
- lib/heapscope/findings.rb
Overview
Ranking / dedupe helpers for findings lists.
Constant Summary collapse
- SEVERITY_WEIGHT =
{ high: 100, medium: 50, low: 10 }.freeze
- CODE_PRIORITY =
{ "HS002" => 20, "HS003" => 18, "HS004" => 18, "HS008" => 17, "HS001" => 15, "HS007" => 14, "HS005" => 12, "HS006" => 12, "HS010" => 10, "HS009" => 4 }.freeze
Class Method Summary collapse
Class Method Details
.priority_score(finding) ⇒ Object
89 90 91 92 93 |
# File 'lib/heapscope/findings.rb', line 89 def priority_score(finding) sev = SEVERITY_WEIGHT[finding.severity] || 0 code = CODE_PRIORITY[finding.code] || 1 sev + code end |
.rank_and_dedupe(findings) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/heapscope/findings.rb', line 95 def rank_and_dedupe(findings) grouped = Array(findings).group_by { |f| [f.code, f.subject.to_s] } deduped = grouped.map do |_key, list| list.max_by { |f| priority_score(f) } end deduped.sort_by { |f| [-priority_score(f), f.code.to_s, f.subject.to_s] } end |