Class: StreamStat
- Inherits:
-
Object
- Object
- StreamStat
- Includes:
- Enumerable
- Defined in:
- lib/stream_stat.rb,
lib/stream_stat/version.rb
Overview
StreamStat: Aggregate large data statictics with streaming.
StreamStat
A library to aggragate statistics of large data with streaming, less memory.
Usage
Aggragate a SD of large_data.
p StreamStat.new(large_data).inject { |_a, stat| stat }.sd
View the intermediate results.
p StreamStat.new(large_data)
.lazy
.each_with_index
.inject { |_a, r| stat, i = r; p stat.sd if i % 100 == 0; stst }
.sd
Defined Under Namespace
Classes: V
Constant Summary collapse
- VERSION =
'0.1.0'
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(enum) ⇒ StreamStat
constructor
A new instance of StreamStat.
Constructor Details
#initialize(enum) ⇒ StreamStat
Returns a new instance of StreamStat.
60 61 62 |
# File 'lib/stream_stat.rb', line 60 def initialize(enum) @enum = enum end |
Instance Method Details
#each ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/stream_stat.rb', line 64 def each ys = Enumerator.new do |y| @enum.lazy.inject(V.new) do |v1, item| v2 = v1.next item y << v2 v2 end end ys.each { |avg| yield avg } if block_given? ys end |