class Dynowatch::Analyzer

Public Class Methods

mean(list) click to toggle source

Return the average of an array of numbers

# File lib/dynowatch/analyzer.rb, line 4
def self.mean(list)
  if (list.size > 0)
    return list.inject{ |sum, el| sum + el }.to_f / list.size
  else
    return "NaN"
  end
end
median(list) click to toggle source

Return the median of an array of numbers

# File lib/dynowatch/analyzer.rb, line 13
def self.median(list)
  return list.sort[list.size/2] || 'NaN'
end
mode(collection) click to toggle source

Return the most common element in an array

# File lib/dynowatch/analyzer.rb, line 18
def self.mode(collection)
  collection.max_by{|elem| collection.count(elem)}
end