module Metrics

  IDENTIFIERS = [:completeness,
                 :weighted_completeness,
                 :richness_of_information,
                 :accuracy,
                 :accessibility,
                 :link_checker]

  ABBREVIATIONS = [:C, :WC, :RoI, :ACCU, :ACCE, :LC]

  NORMALIZE = [:richness_of_information,
               :accessibility]

  def self.normalize(metric, values)

    unless NORMALIZE.include?(metric)
      return values
    end

    scores = []
    repositories = Repository.all
    repositories.each do |repository|
      score = repository.send(metric)
      unless score.nil?
        scores << score[:minimum]
        scores << score[:maximum]
      end
    end
    min = scores.min
    max = scores.max
    range = max - min
    values.map { |value| (value - min) / range }
  end

  def self.get_url_representation(metric)
    metric.to_s.gsub('_', '-')
  end

  def self.get_internal_representation(metric)
    metric.to_s.gsub('-', '_')
  end

end

module Metrics

  IDENTIFIERS = [:completeness,
                 :weighted_completeness,
                 :richness_of_information,
                 :accuracy,
                 :accessibility,
                 :link_checker]

  ABBREVIATIONS = [:C, :WC, :RoI, :ACCU, :ACCE, :LC]

  NORMALIZE = [:richness_of_information,
               :accessibility]

  def self.normalize(metric, values)

    unless NORMALIZE.include?(metric)
      return values
    end

    scores = values
    repositories = Repository.all
    repositories.each do |repository|
      score = repository.send(metric)
      unless score.nil?
        scores << score[:minimum]
        scores << score[:maximum]
      end
    end
    min = scores.min
    max = scores.max
    range = max - min
    values.map { |value| (value - min) / range }
  end

  def self.get_url_representation(metric)
    metric.to_s.gsub('_', '-')
  end

  def self.get_internal_representation(metric)
    metric.to_s.gsub('-', '_')
  end

end

Change source of scores for value normalization
Change source of scores for value normalization

Instead of starting with an empty array for the normalization of metric
scores, the array is initialized with the values passed to the method.
This way exceptions can be prevented, if there are no scores available.

Signed-off-by: Konrad Reiche <4ff0213f56e2082fcd8c882d04c546881c579ce4@gmail.com>
