Class: Cosmos::StatisticsProcessor
- Defined in:
- lib/cosmos/processors/statistics_processor.rb
Instance Attribute Summary collapse
-
#samples ⇒ Array
The set of samples stored by the processor.
Attributes inherited from Processor
Instance Method Summary collapse
-
#call(packet, buffer) ⇒ Object
Run statistics on the item.
-
#clone ⇒ Processor
(also: #dup)
Make a light weight clone of this processor.
-
#initialize(item_name, samples_to_average, value_type = :CONVERTED) ⇒ StatisticsProcessor
constructor
A new instance of StatisticsProcessor.
-
#reset ⇒ Object
Reset any state.
Methods inherited from Processor
Constructor Details
#initialize(item_name, samples_to_average, value_type = :CONVERTED) ⇒ StatisticsProcessor
Returns a new instance of StatisticsProcessor.
23 24 25 26 27 28 |
# File 'lib/cosmos/processors/statistics_processor.rb', line 23 def initialize(item_name, samples_to_average, value_type = :CONVERTED) super(value_type) @item_name = item_name.to_s.upcase @samples_to_average = Integer(samples_to_average) reset() end |
Instance Attribute Details
#samples ⇒ Array
Returns The set of samples stored by the processor.
18 19 20 |
# File 'lib/cosmos/processors/statistics_processor.rb', line 18 def samples @samples end |
Instance Method Details
#call(packet, buffer) ⇒ Object
Run statistics on the item
See Processor#call
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cosmos/processors/statistics_processor.rb', line 33 def call(packet, buffer) value = packet.read(@item_name, @value_type, buffer) @samples << value @samples = @samples[-@samples_to_average..-1] if @samples.length > @samples_to_average mean, stddev = Math.stddev_sample(@samples) @results[:MAX] = @samples.max @results[:MIN] = @samples.min @results[:MEAN] = mean @results[:STDDEV] = stddev end |
#clone ⇒ Processor Also known as: dup
Make a light weight clone of this processor. This only creates a new hash of results
56 57 58 59 60 |
# File 'lib/cosmos/processors/statistics_processor.rb', line 56 def clone processor = super() processor.samples = processor.samples.clone processor end |
#reset ⇒ Object
Reset any state
45 46 47 48 49 50 51 |
# File 'lib/cosmos/processors/statistics_processor.rb', line 45 def reset @samples = [] @results[:MAX] = nil @results[:MIN] = nil @results[:MEAN] = nil @results[:STDDEV] = nil end |