Sha256: 5683e0094573262a69b1d088b58b270274747fc9633d770b117b01d3fa7ce5b4

Contents?: true

Size: 1.11 KB

Versions: 9

Compression:

Stored size: 1.11 KB

Contents

module MetricFu
  
  class FlogGrapher < Grapher
    
    attr_accessor :flog_average, :labels, :top_five_percent_average
    
    def initialize
      super
      @flog_average = []
      @labels = {}
      @top_five_percent_average =[]
    end
    
    def get_metrics(metrics, date)
      @top_five_percent_average.push(calc_top_five_percent_average(metrics))
      @flog_average.push(metrics[:flog][:average])
      @labels.update( { @labels.size => date })
    end
    
    private
    
    def calc_top_five_percent_average(metrics)
      methods = metrics[:flog][:pages].inject([]) {|methods, page| methods << page[:scanned_methods]}
      methods.flatten!
      methods = methods.sort_by {|method| method[:score]}.reverse

      number_of_methods_that_is_five_percent = (methods.size * 0.05).ceil

      total_for_five_percent =
        methods[0...number_of_methods_that_is_five_percent].inject(0) {|total, method| total += method[:score] }
      if number_of_methods_that_is_five_percent == 0
        0.0
      else
        total_for_five_percent / number_of_methods_that_is_five_percent.to_f
      end
    end
    
  end
  
end

Version data entries

9 entries across 9 versions & 6 rubygems

Version Path
cayblood-metric_fu-1.1.6 lib/graphs/flog_grapher.rb
metric_fu-1.4.0 lib/graphs/flog_grapher.rb
devver-metric_fu-1.3.3 lib/graphs/flog_grapher.rb
nielsm-metric_fu-1.3.1 lib/graphs/flog_grapher.rb
metric_fu-1.3.0 lib/graphs/flog_grapher.rb
edouard-metric_fu-1.2.1 lib/graphs/flog_grapher.rb
edouard-metric_fu-1.2.0 lib/graphs/flog_grapher.rb
metric_fu-1.2.0 lib/graphs/flog_grapher.rb
flyerhzm-metric_fu-1.0.0 lib/graphs/flog_grapher.rb