Class: Chawk::Models::Aggregator
- Inherits:
-
Object
- Object
- Chawk::Models::Aggregator
- Defined in:
- lib/aggregator.rb
Overview
TODO: Most expensive version imaginable. To be replaced.
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(node) ⇒ Aggregator
constructor
A new instance of Aggregator.
- #max ⇒ Object
- #mean ⇒ Object
- #min ⇒ Object
- #stdev ⇒ Object
- #sum ⇒ Object
- #sumsqr ⇒ Object
Constructor Details
#initialize(node) ⇒ Aggregator
Returns a new instance of Aggregator.
9 10 11 12 13 14 |
# File 'lib/aggregator.rb', line 9 def initialize(node) node.check_read_access if node.points.length > 0 @dataset = node.points.to_a.reduce([]) {|ary,p| ary << p.value} end end |
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
7 8 9 |
# File 'lib/aggregator.rb', line 7 def dataset @dataset end |
Instance Method Details
#count ⇒ Object
32 33 34 |
# File 'lib/aggregator.rb', line 32 def count @dataset.length end |
#max ⇒ Object
16 17 18 |
# File 'lib/aggregator.rb', line 16 def max() @dataset.max end |
#mean ⇒ Object
24 25 26 |
# File 'lib/aggregator.rb', line 24 def mean sum.to_f / @dataset.length end |
#min ⇒ Object
20 21 22 |
# File 'lib/aggregator.rb', line 20 def min() @dataset.min end |
#stdev ⇒ Object
40 41 42 43 |
# File 'lib/aggregator.rb', line 40 def stdev m = mean Math.sqrt((sumsqr - count * m * m)/(count-1)) end |
#sum ⇒ Object
28 29 30 |
# File 'lib/aggregator.rb', line 28 def sum @dataset.reduce(0) {|sum,p| sum+=p} end |
#sumsqr ⇒ Object
36 37 38 |
# File 'lib/aggregator.rb', line 36 def sumsqr @dataset.map {|x| x * x}.reduce(&:+) end |