Class: Dynowatch::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/dynowatch/analyzer.rb

Class Method Summary collapse

Class Method Details

.mean(list) ⇒ Object

Return the average of an array of numbers



4
5
6
7
8
9
10
# 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) ⇒ Object

Return the median of an array of numbers



13
14
15
# File 'lib/dynowatch/analyzer.rb', line 13

def self.median(list)
  return list.sort[list.size/2] || 'NaN'
end

.mode(collection) ⇒ Object

Return the most common element in an array



18
19
20
# File 'lib/dynowatch/analyzer.rb', line 18

def self.mode(collection)
  collection.max_by{|elem| collection.count(elem)}
end