Class: Wonkavision::Analytics::CellSet::Measure
- Inherits:
-
Object
- Object
- Wonkavision::Analytics::CellSet::Measure
- Defined in:
- lib/wonkavision/plugins/analytics/cellset.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #aggregate(new_data) ⇒ Object
- #count ⇒ Object
-
#initialize(name, data) ⇒ Measure
constructor
A new instance of Measure.
- #mean ⇒ Object (also: #average)
- #std_dev ⇒ Object
- #sum ⇒ Object
- #sum2 ⇒ Object
Constructor Details
#initialize(name, data) ⇒ Measure
Returns a new instance of Measure.
144 145 146 147 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 144 def initialize(name,data) @name = name @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
143 144 145 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 143 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
143 144 145 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 143 def name @name end |
Instance Method Details
#aggregate(new_data) ⇒ Object
161 162 163 164 165 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 161 def aggregate(new_data) @data["sum"] = @data["sum"].to_f + new_data["sum"].to_f @data["sum2"] = @data["sum2"].to_f + new_data["sum2"].to_f @data["count"] = @data["count"].to_i + new_data["count"].to_i end |
#count ⇒ Object
151 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 151 def count; @data["count"]; end |
#mean ⇒ Object Also known as: average
153 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 153 def mean; sum/count; end |
#std_dev ⇒ Object
156 157 158 159 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 156 def std_dev return Wonkavision::NaN unless count > 1 Math.sqrt((sum2.to_f - ((sum.to_f * sum.to_f)/count.to_f)) / (count.to_f - 1)) end |
#sum ⇒ Object
149 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 149 def sum; @data["sum"]; end |
#sum2 ⇒ Object
150 |
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 150 def sum2; @data["sum2"]; end |