Class: Bmg::Summarizer::Avg
- Inherits:
-
Bmg::Summarizer
- Object
- Bmg::Summarizer
- Bmg::Summarizer::Avg
- Defined in:
- lib/bmg/summarizer/avg.rb
Overview
Average summarizer.
Example:
# direct ruby usage
Bmg::Summarizer.avg(:qty).summarize(...)
Instance Attribute Summary
Attributes inherited from Bmg::Summarizer
Instance Method Summary collapse
-
#_happens(memo, val) ⇒ Object
Collects one more value + the sum of all.
-
#finalize(memo) ⇒ Object
Finalizes the computation.
-
#least ⇒ Object
Returns [0.0, 0.0] as least value.
Methods inherited from Bmg::Summarizer
avg, bucketize, by_proc, collect, concat, count, distinct, distinct_count, first, #happens, #initialize, last, max, median, median_cont, median_disc, min, multiple, percentile, percentile_cont, percentile_disc, stddev, sum, summarization, #summarize, #to_summarizer_name, value_by, variance
Constructor Details
This class inherits a constructor from Bmg::Summarizer
Instance Method Details
#_happens(memo, val) ⇒ Object
Collects one more value + the sum of all
19 20 21 |
# File 'lib/bmg/summarizer/avg.rb', line 19 def _happens(memo, val) [memo.first + val, memo.last + 1] end |
#finalize(memo) ⇒ Object
Finalizes the computation.
24 25 26 |
# File 'lib/bmg/summarizer/avg.rb', line 24 def finalize(memo) memo.first / memo.last end |
#least ⇒ Object
Returns [0.0, 0.0] as least value.
14 15 16 |
# File 'lib/bmg/summarizer/avg.rb', line 14 def least() [0.0, 0.0] end |