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.
33 34 35 36 37 38 |
# File 'lib/openc3/processors/statistics_processor.rb', line 33 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.
28 29 30 |
# File 'lib/openc3/processors/statistics_processor.rb', line 28 def samples @samples end |
Instance Method Details
#as_json(*a) ⇒ Object
81 82 83 |
# File 'lib/openc3/processors/statistics_processor.rb', line 81 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
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/openc3/processors/statistics_processor.rb', line 43 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
69 70 71 72 73 |
# File 'lib/openc3/processors/statistics_processor.rb', line 69 def clone processor = super() processor.samples = processor.samples.clone processor end |
#reset ⇒ Object
Reset any state
58 59 60 61 62 63 64 |
# File 'lib/openc3/processors/statistics_processor.rb', line 58 def reset @samples = [] @results[:MAX] = nil @results[:MIN] = nil @results[:MEAN] = nil @results[:STDDEV] = nil end |
#to_config ⇒ Object
Convert to configuration file string
77 78 79 |
# File 'lib/openc3/processors/statistics_processor.rb', line 77 def to_config " PROCESSOR #{@name} #{self.class.name.to_s.class_name_to_filename} #{@item_name} #{@samples_to_average} #{@value_type}\n" end |