Class: StreamStat

Inherits:
Object
  • Object
show all
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

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

#eachObject



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