Class: OpenC3::StatisticsProcessor
- Defined in:
- lib/openc3/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
- #as_json(*a) ⇒ Object
-
#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.
-
#to_config ⇒ Object
Convert to configuration file string.
Methods inherited from Processor
Constructor Details
#initialize(item_name, samples_to_average, value_type = :CONVERTED) ⇒ StatisticsProcessor
Returns a new instance of StatisticsProcessor.
30 31 32 33 34 35 |
# File 'lib/openc3/processors/statistics_processor.rb', line 30 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.
25 26 27 |
# File 'lib/openc3/processors/statistics_processor.rb', line 25 def samples @samples end |
Instance Method Details
#as_json(*a) ⇒ Object
78 79 80 |
# File 'lib/openc3/processors/statistics_processor.rb', line 78 def as_json(*a) { 'name' => @name, 'class' => self.class.name, 'params' => [@item_name, @samples_to_average, @value_type.to_s] } end |
#call(packet, buffer) ⇒ Object
Run statistics on the item
See Processor#call
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/openc3/processors/statistics_processor.rb', line 40 def call(packet, buffer) value = packet.read(@item_name, @value_type, buffer) # Don't process NaN or Infinite values return if value.to_f.nan? || value.to_f.infinite? @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
66 67 68 69 70 |
# File 'lib/openc3/processors/statistics_processor.rb', line 66 def clone processor = super() processor.samples = processor.samples.clone processor end |
#reset ⇒ Object
Reset any state
55 56 57 58 59 60 61 |
# File 'lib/openc3/processors/statistics_processor.rb', line 55 def reset @samples = [] @results[:MAX] = nil @results[:MIN] = nil @results[:MEAN] = nil @results[:STDDEV] = nil end |
#to_config ⇒ Object
Convert to configuration file string
74 75 76 |
# File 'lib/openc3/processors/statistics_processor.rb', line 74 def to_config " PROCESSOR #{@name} #{self.class.name.to_s.class_name_to_filename} #{@item_name} #{@samples_to_average} #{@value_type}\n" end |