Sha256: 5b15ceecbb9483367dcb9b030085bbbf688386b6d2350c56305c3abf459dff51

Contents?: true

Size: 622 Bytes

Versions: 9

Compression:

Stored size: 622 Bytes

Contents

require "forwardable"
module MetricFu
  class Ranking
    extend Forwardable

    def initialize
      @items_to_score = {}
    end

    def top
      sorted_items
    end

    def percentile(item)
      index = sorted_items.index(item)
      worse_item_count = (length - (index + 1))
      worse_item_count.to_f / length
    end

    def_delegator :@items_to_score, :has_key?, :scored?
    def_delegators :@items_to_score, :[], :[]=, :length, :each, :delete, :fetch

    private

    def sorted_items
      @sorted_items ||= @items_to_score.sort_by { |_item, score| -score }.map { |item, _score| item }
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
metric_fu-4.13.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
fastruby-metric_fu-5.0.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
code_metric_fu-4.14.4 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
code_metric_fu-4.14.3 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
code_metric_fu-4.14.2 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
code_metric_fu-4.14.1 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
code_metric_fu-4.14.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.12.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.11.4 lib/metric_fu/metrics/hotspots/analysis/ranking.rb