Sha256: dab6b822c3da005faf6337c5512545a87974977fd500a97453529e453cd34597

Contents?: true

Size: 613 Bytes

Versions: 19

Compression:

Stored size: 613 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

19 entries across 19 versions & 1 rubygems

Version Path
metric_fu-4.11.3 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.11.2 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.11.1 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.11.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.10.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.9.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.8.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.7.4 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.7.3 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.7.2 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.7.1 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.7.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.6.0 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.5.2 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.5.1 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.4.4 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.4.3 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.4.2 lib/metric_fu/metrics/hotspots/analysis/ranking.rb
metric_fu-4.4.1 lib/metric_fu/metrics/hotspots/analysis/ranking.rb