Class: Wonkavision::Analytics::CellSet::Measure

Inherits:
Object
  • Object
show all
Defined in:
lib/wonkavision/plugins/analytics/cellset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



143
144
145
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 143

def data
  @data
end

#nameObject (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

#countObject



151
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 151

def count; @data["count"]; end

#meanObject Also known as: average



153
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 153

def mean; sum/count; end

#std_devObject



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

#sumObject



149
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 149

def sum; @data["sum"]; end

#sum2Object



150
# File 'lib/wonkavision/plugins/analytics/cellset.rb', line 150

def sum2; @data["sum2"]; end