stream_stat 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -1
- data/Gemfile +0 -1
- data/Gemfile.lock +92 -3
- data/Guardfile +21 -0
- data/README.md +46 -6
- data/README.md.erb +45 -0
- data/Rakefile +15 -4
- data/example/1.rb +13 -0
- data/example/2.rb +35 -0
- data/example/example.rb +40 -0
- data/lib/stream_stat.rb +4 -55
- data/lib/stream_stat/v.rb +48 -0
- data/lib/stream_stat/version.rb +1 -1
- data/stream_stat.gemspec +5 -0
- metadata +79 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44a36e6474555715f19679997845b387616dbd25
|
4
|
+
data.tar.gz: bfda29b9ebfe28ba4d4a5705dc82a5318ca5eba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44ef0eddc12b767eb0f16a03a95d3b5d75f22a42e52ea369c257598fad3e0ace2ccbbc0087055423594eb08c71fabf62a3466d3d081010420a7241b81018df43
|
7
|
+
data.tar.gz: 3623719ccc9bea1042fcf31a81b24ec23ccd1db75e866e51614d19ebf2b4fcfad1cdba235e052012d723686f9f94c6a337c0efb616da6efc6b5ca6af48f810bb
|
data/.travis.yml
CHANGED
@@ -1,4 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
3
|
+
- 2.3.1
|
4
4
|
script: bundle exec rake test
|
5
|
+
notifications:
|
6
|
+
slack:
|
7
|
+
secure: XrNLlxm7F4PX5IwFUXow1gCDO/99+jT2zlQRwADuPvAXjg2cMme7+e81ZBqzBGDB6MwfZararE0gS10CuadMJm3NTzzNFDolBXJV4OTbbVxBSRkbZ8cxlbOwmxRof9x4xw8E+VXaZYsVa6sDL2ZFJamV7fg+B+POUGBAI/iR0uyff77T6T2JIHvlUUX31IVDjHjW4NAfnKW7xmm0i4hQSh7iRO3Yp25Mvkkx5i5CpEhvFUbh8lhf3oLJ0h2AzS1xhdX6x1eQn4Siz6OXb701ap1GMYWf5lQLfYQZkCSW1O2M40HeJCBUUfD3l5yykBSfPr+km4ql5yjoZpcCLQYW5G490x0YTjqureaF70Ltpy6SUJo503b1EoIpWJJRXrrxEUW/a1Il/nYPqFPWcdPhluXMeT91Ulq7GKiJNEsU3t+aR1H9X7N+GQJCBxuT9C4zedYPl+3Aqgq3Iq3RRuOLBnmfFdLSMJtAr9nrDVcVGmsvlOLosoGDdyOzRpF4xwkY97XP9dNnnbBEbGFQw4xExAXGqo5DljoQJpTyVuyBc3npsWwt8PgVAcyAIa4226xLbMowjGi2Hxtzxs4Sx9ooSU3x7WweTHlUOuxnUNMDuVjERQXW+kxY0o/rg1u7ZDPEpBeJrTWu6nPe7CUjIcBTI1ZulKt6o/rxZpXnDtn2B8A=
|
8
|
+
addons:
|
9
|
+
code_climate:
|
10
|
+
repo_token:
|
11
|
+
secure: JHdpp5Bw3sNT55CoGTB4DXBYk352li5LKc7rHV3JCfr8eHu9wGcwWG6P6KK9rkbZxLV01+X/R7wRhYeKzTU45jgcFkM1tbEKEYFG7ttOPOenD/voLVxzSYRcnupFrnl4ZuOxwhE8Uw9vR9qc8NmLT9+MlR4Oi+sWGXFIroTPtdNQYrV/z8XwQTWy0ihi/N+DZoOCVDKaIa2afYWW99ZRjRKOTWrTtB3SRoBobzkue69/g5LUUZnQXB164cGkzuMPxSNccstq02WZ7EgSKPxjHND6PGUVZwPpuhzh9xPX8ljnAlLEBQbhV/iqXGR5n8MCIx4QecMgaGMYxGqkJArY52OUekmT1D2XL4a3tyX1tWChsJifQaSMEpKMDErRLmrYGfluSNTZf6g1tKhMo6E4eNPp/Ihn3zqdAyU2cbv3bAiJZ8d1tffbGiJ681AvVoZyAl6q06CtoJ4PcvnZUeG4842C3qTXqlHJWyotNFVOxQkbpZnm1fRDiJVznmB/AXZG+prORjNFfFBCuJwy+rtdpE0p4wB+1LV5CwKm9zGf0SM80v9dNl2GDg2InPI9yo090Ze00G1gDPkYfbQF7BCG+hq4mDk2864wcWHFudXQSFhNwE5CQ3lE+oCnOs371Ni54LfICjpf55TWD06t/mAiJeVa5NquZO1LYMDJUgd9hu8=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,78 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stream_stat (0.1.
|
4
|
+
stream_stat (0.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
abstract_type (0.0.7)
|
10
|
+
adamantium (0.2.0)
|
11
|
+
ice_nine (~> 0.11.0)
|
12
|
+
memoizable (~> 0.4.0)
|
9
13
|
ast (2.3.0)
|
14
|
+
binding_of_caller (0.7.2)
|
15
|
+
debug_inspector (>= 0.0.1)
|
16
|
+
codeclimate-test-reporter (0.6.0)
|
17
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
18
|
+
coderay (1.1.1)
|
19
|
+
concord (0.1.5)
|
20
|
+
adamantium (~> 0.2.0)
|
21
|
+
equalizer (~> 0.0.9)
|
22
|
+
debug_inspector (0.0.2)
|
10
23
|
diff-lcs (1.2.5)
|
24
|
+
docile (1.1.5)
|
25
|
+
equalizer (0.0.11)
|
26
|
+
ffi (1.9.14)
|
27
|
+
formatador (0.2.5)
|
28
|
+
guard (2.14.0)
|
29
|
+
formatador (>= 0.2.4)
|
30
|
+
listen (>= 2.7, < 4.0)
|
31
|
+
lumberjack (~> 1.0)
|
32
|
+
nenv (~> 0.1)
|
33
|
+
notiffany (~> 0.0)
|
34
|
+
pry (>= 0.9.12)
|
35
|
+
shellany (~> 0.0)
|
36
|
+
thor (>= 0.18.1)
|
37
|
+
guard-compat (1.2.1)
|
38
|
+
guard-rspec (4.7.3)
|
39
|
+
guard (~> 2.1)
|
40
|
+
guard-compat (~> 1.1)
|
41
|
+
rspec (>= 2.99.0, < 4.0)
|
42
|
+
guard-rubocop (1.2.0)
|
43
|
+
guard (~> 2.0)
|
44
|
+
rubocop (~> 0.20)
|
45
|
+
ice_nine (0.11.2)
|
46
|
+
json (2.0.2)
|
47
|
+
listen (3.1.5)
|
48
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
49
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
50
|
+
ruby_dep (~> 1.2)
|
51
|
+
lumberjack (1.0.10)
|
52
|
+
memoizable (0.4.2)
|
53
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
54
|
+
method_source (0.8.2)
|
55
|
+
nenv (0.3.0)
|
56
|
+
notiffany (0.1.1)
|
57
|
+
nenv (~> 0.1)
|
58
|
+
shellany (~> 0.0)
|
11
59
|
parser (2.3.1.4)
|
12
60
|
ast (~> 2.2)
|
13
61
|
powerpack (0.1.1)
|
62
|
+
proc_to_ast (0.1.0)
|
63
|
+
coderay
|
64
|
+
parser
|
65
|
+
unparser
|
66
|
+
procto (0.0.3)
|
67
|
+
pry (0.10.4)
|
68
|
+
coderay (~> 1.1.0)
|
69
|
+
method_source (~> 0.8.1)
|
70
|
+
slop (~> 3.4)
|
14
71
|
rainbow (2.1.0)
|
15
72
|
rake (11.3.0)
|
73
|
+
rb-fsevent (0.9.7)
|
74
|
+
rb-inotify (0.9.7)
|
75
|
+
ffi (>= 0.5.0)
|
16
76
|
rspec (3.5.0)
|
17
77
|
rspec-core (~> 3.5.0)
|
18
78
|
rspec-expectations (~> 3.5.0)
|
@@ -28,8 +88,14 @@ GEM
|
|
28
88
|
rspec-mocks (3.5.0)
|
29
89
|
diff-lcs (>= 1.2.0, < 2.0)
|
30
90
|
rspec-support (~> 3.5.0)
|
91
|
+
rspec-parameterized (0.3.1)
|
92
|
+
binding_of_caller
|
93
|
+
parser
|
94
|
+
proc_to_ast
|
95
|
+
rspec (>= 2.13, < 4)
|
96
|
+
unparser
|
31
97
|
rspec-support (3.5.0)
|
32
|
-
rubocop (0.
|
98
|
+
rubocop (0.44.1)
|
33
99
|
parser (>= 2.3.1.1, < 3.0)
|
34
100
|
powerpack (~> 0.1)
|
35
101
|
rainbow (>= 1.99.1, < 3.0)
|
@@ -38,19 +104,42 @@ GEM
|
|
38
104
|
rubocop-rspec (1.7.0)
|
39
105
|
rubocop (>= 0.42.0)
|
40
106
|
ruby-progressbar (1.8.1)
|
107
|
+
ruby_dep (1.5.0)
|
108
|
+
shellany (0.0.1)
|
109
|
+
simplecov (0.12.0)
|
110
|
+
docile (~> 1.1.0)
|
111
|
+
json (>= 1.8, < 3)
|
112
|
+
simplecov-html (~> 0.10.0)
|
113
|
+
simplecov-html (0.10.0)
|
114
|
+
slop (3.6.0)
|
115
|
+
thor (0.19.1)
|
116
|
+
thread_safe (0.3.5)
|
41
117
|
unicode-display_width (1.1.1)
|
118
|
+
unparser (0.2.5)
|
119
|
+
abstract_type (~> 0.0.7)
|
120
|
+
adamantium (~> 0.2.0)
|
121
|
+
concord (~> 0.1.5)
|
122
|
+
diff-lcs (~> 1.2.5)
|
123
|
+
equalizer (~> 0.0.9)
|
124
|
+
parser (~> 2.3.0)
|
125
|
+
procto (~> 0.0.2)
|
42
126
|
|
43
127
|
PLATFORMS
|
44
128
|
ruby
|
45
129
|
|
46
130
|
DEPENDENCIES
|
47
131
|
bundler
|
132
|
+
codeclimate-test-reporter
|
133
|
+
guard
|
134
|
+
guard-rspec
|
135
|
+
guard-rubocop
|
48
136
|
rake
|
49
137
|
rspec
|
50
138
|
rspec-its
|
139
|
+
rspec-parameterized
|
51
140
|
rubocop
|
52
141
|
rubocop-rspec
|
53
142
|
stream_stat!
|
54
143
|
|
55
144
|
BUNDLED WITH
|
56
|
-
1.13.
|
145
|
+
1.13.2
|
data/Guardfile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
4
|
+
require 'guard/rspec/dsl'
|
5
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
6
|
+
|
7
|
+
# RSpec files
|
8
|
+
rspec = dsl.rspec
|
9
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
10
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
11
|
+
watch(rspec.spec_files)
|
12
|
+
|
13
|
+
# Ruby files
|
14
|
+
ruby = dsl.ruby
|
15
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
16
|
+
end
|
17
|
+
|
18
|
+
guard :rubocop do
|
19
|
+
watch(/.+\.rb$/)
|
20
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
21
|
+
end
|
data/README.md
CHANGED
@@ -1,27 +1,67 @@
|
|
1
1
|
StreamStat: Aggregate large data statictics with streaming.
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/stream_stat.svg)](https://badge.fury.io/rb/stream_stat)
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/ne-sachirou/stream_stat.svg)](https://gemnasium.com/github.com/ne-sachirou/stream_stat)
|
3
5
|
[![Build Status](https://travis-ci.org/ne-sachirou/stream_stat.svg?branch=master)](https://travis-ci.org/ne-sachirou/stream_stat)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/ne-sachirou/stream_stat/badges/gpa.svg)](https://codeclimate.com/github/ne-sachirou/stream_stat)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/ne-sachirou/stream_stat/badges/coverage.svg)](https://codeclimate.com/github/ne-sachirou/stream_stat/coverage)
|
4
8
|
|
5
9
|
StreamStat
|
6
10
|
==
|
7
11
|
A library to aggragate statistics of large data with streaming, less memory.
|
8
12
|
|
13
|
+
Currently average (`:avg`), variance (`:variance`), standard deviation (`:sd`), minimun (`:min`) & maximum (`:max`) are supported.
|
14
|
+
|
9
15
|
Usage
|
10
16
|
--
|
11
17
|
Aggragate a SD of large_data.
|
12
18
|
|
13
19
|
```ruby
|
14
|
-
|
20
|
+
# Monkey patch
|
21
|
+
module Enumerable
|
22
|
+
def last
|
23
|
+
inject { |_a, v| v }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
large_data = (1..100_000).lazy.collect { rand 100_000 }
|
28
|
+
p StreamStat.new(large_data).last.sd
|
15
29
|
```
|
16
30
|
|
17
31
|
View the intermediate results.
|
18
32
|
|
19
33
|
```ruby
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
34
|
+
# Monkey patch
|
35
|
+
module Enumerable
|
36
|
+
def each_tap
|
37
|
+
collect do |*item|
|
38
|
+
yield(*item)
|
39
|
+
[*item]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def last
|
44
|
+
inject { |_a, v| v }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def pstat(stat)
|
49
|
+
puts <<-EOF
|
50
|
+
avg:\t#{stat.avg}
|
51
|
+
variance:\t#{stat.variance}
|
52
|
+
sd:\t#{stat.sd}
|
53
|
+
min:\t#{stat.min}
|
54
|
+
max:\t#{stat.max}
|
55
|
+
EOF
|
56
|
+
end
|
57
|
+
|
58
|
+
large_data = (1..100_000).lazy.collect { rand 100_000 }
|
59
|
+
stat = StreamStat.new(large_data)
|
60
|
+
.lazy
|
61
|
+
.each_with_index
|
62
|
+
.each_tap { |st, i| pstat st if (i % 10_000).zero? }
|
63
|
+
.last[0]
|
64
|
+
pstat stat
|
25
65
|
```
|
26
66
|
|
27
67
|
Installation
|
data/README.md.erb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
StreamStat: Aggregate large data statictics with streaming.
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/stream_stat.svg)](https://badge.fury.io/rb/stream_stat)
|
4
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/ne-sachirou/stream_stat.svg)](https://gemnasium.com/github.com/ne-sachirou/stream_stat)
|
5
|
+
[![Build Status](https://travis-ci.org/ne-sachirou/stream_stat.svg?branch=master)](https://travis-ci.org/ne-sachirou/stream_stat)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/ne-sachirou/stream_stat/badges/gpa.svg)](https://codeclimate.com/github/ne-sachirou/stream_stat)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/ne-sachirou/stream_stat/badges/coverage.svg)](https://codeclimate.com/github/ne-sachirou/stream_stat/coverage)
|
8
|
+
|
9
|
+
StreamStat
|
10
|
+
==
|
11
|
+
A library to aggragate statistics of large data with streaming, less memory.
|
12
|
+
|
13
|
+
Currently average (`:avg`), variance (`:variance`), standard deviation (`:sd`), minimun (`:min`) & maximum (`:max`) are supported.
|
14
|
+
|
15
|
+
Usage
|
16
|
+
--
|
17
|
+
<%= @examples[0].description %>
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
<%= @examples[0].code %>
|
21
|
+
```
|
22
|
+
|
23
|
+
<%= @examples[1].description %>
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
<%= @examples[1].code %>
|
27
|
+
```
|
28
|
+
|
29
|
+
Installation
|
30
|
+
--
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'stream_stat'
|
35
|
+
```
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install stream_stat
|
44
|
+
|
45
|
+
<%# vim:set ft=markdown: %>
|
data/Rakefile
CHANGED
@@ -1,9 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'rubocop/rake_task'
|
6
|
+
require 'rubocop-rspec'
|
7
|
+
require_relative 'example/example'
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
+
RuboCop::RakeTask.new
|
10
|
+
RSpec::Core::RakeTask.new
|
11
|
+
|
12
|
+
desc 'Render readme'
|
13
|
+
task :readme do
|
14
|
+
@examples = Example.all
|
15
|
+
readme = ERB.new(File.read("#{__dir__}/README.md.erb", encoding: Encoding::UTF_8)).result.strip + "\n"
|
16
|
+
File.write "#{__dir__}/README.md", readme
|
9
17
|
end
|
18
|
+
|
19
|
+
desc 'Test'
|
20
|
+
task test: %i(rubocop spec)
|
data/example/1.rb
ADDED
data/example/2.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# View the intermediate results.
|
4
|
+
|
5
|
+
# Monkey patch
|
6
|
+
module Enumerable
|
7
|
+
def each_tap
|
8
|
+
collect do |*item|
|
9
|
+
yield(*item)
|
10
|
+
[*item]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def last
|
15
|
+
inject { |_a, v| v }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def pstat(stat)
|
20
|
+
puts <<-EOF
|
21
|
+
avg:\t#{stat.avg}
|
22
|
+
variance:\t#{stat.variance}
|
23
|
+
sd:\t#{stat.sd}
|
24
|
+
min:\t#{stat.min}
|
25
|
+
max:\t#{stat.max}
|
26
|
+
EOF
|
27
|
+
end
|
28
|
+
|
29
|
+
large_data = (1..100_000).lazy.collect { rand 100_000 }
|
30
|
+
stat = StreamStat.new(large_data)
|
31
|
+
.lazy
|
32
|
+
.each_with_index
|
33
|
+
.each_tap { |st, i| pstat st if (i % 10_000).zero? }
|
34
|
+
.last[0]
|
35
|
+
pstat stat
|
data/example/example.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Example code reader
|
4
|
+
#
|
5
|
+
# example := head empty_line description empty_line code
|
6
|
+
# head := non_empty_line*
|
7
|
+
# description := comment_line+
|
8
|
+
# code := /.+/m
|
9
|
+
# empty_line := /^\s*$/
|
10
|
+
# non_empty_line := /^\s*\S+.*$/
|
11
|
+
# comment_line := /^#.*$/
|
12
|
+
class Example
|
13
|
+
attr_reader :description, :code
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def all
|
17
|
+
Dir["#{__dir__}/*.rb"]
|
18
|
+
.select { |file| File.basename(file, '.rb') =~ /\d+/ }
|
19
|
+
.collect { |file| new file }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(file)
|
24
|
+
@file = file
|
25
|
+
content = drop_head File.read(file, encoding: Encoding::UTF_8).each_line
|
26
|
+
description_lines = content.take_while { |line| line[0] == '#' }
|
27
|
+
@description = description_lines.join('').gsub(/^#\s*/, '').strip
|
28
|
+
@code = content.drop(description_lines.size).join('').strip
|
29
|
+
end
|
30
|
+
|
31
|
+
def eval
|
32
|
+
load @file
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def drop_head(content)
|
38
|
+
content.drop_while { |line| line =~ /^\s*\S+.*$/ }.drop(1)
|
39
|
+
end
|
40
|
+
end
|
data/lib/stream_stat.rb
CHANGED
@@ -1,75 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'stream_stat/v'
|
4
|
+
|
3
5
|
# StreamStat: Aggregate large data statictics with streaming.
|
4
|
-
#
|
5
|
-
# = StreamStat
|
6
|
-
# A library to aggragate statistics of large data with streaming, less memory.
|
7
|
-
#
|
8
|
-
# == Usage
|
9
|
-
# Aggragate a SD of large_data.
|
10
|
-
#
|
11
|
-
# p StreamStat.new(large_data).inject { |_a, stat| stat }.sd
|
12
|
-
#
|
13
|
-
# View the intermediate results.
|
14
|
-
#
|
15
|
-
# p StreamStat.new(large_data)
|
16
|
-
# .lazy
|
17
|
-
# .each_with_index
|
18
|
-
# .inject { |_a, r| stat, i = r; p stat.sd if i % 100 == 0; stst }
|
19
|
-
# .sd
|
20
6
|
class StreamStat
|
21
7
|
include Enumerable
|
22
8
|
|
23
|
-
# Accumrator.
|
24
|
-
#
|
25
|
-
# This holds :avg, :variance & :sd.
|
26
|
-
class V
|
27
|
-
def initialize(length = 0, sum = 0, variance_sum = 0.0)
|
28
|
-
@length = length
|
29
|
-
@sum = sum
|
30
|
-
@variance_sum = variance_sum
|
31
|
-
end
|
32
|
-
|
33
|
-
def next(item)
|
34
|
-
self.class.new(
|
35
|
-
@length + 1,
|
36
|
-
@sum + item,
|
37
|
-
next_variance_sum(avg, (@sum + item).to_f / (@length + 1), item)
|
38
|
-
)
|
39
|
-
end
|
40
|
-
|
41
|
-
def avg
|
42
|
-
@length.zero? ? 0.0 : @sum.to_f / @length
|
43
|
-
end
|
44
|
-
|
45
|
-
def variance
|
46
|
-
@length.zero? ? 0.0 : @variance_sum / @length
|
47
|
-
end
|
48
|
-
|
49
|
-
def sd
|
50
|
-
Math.sqrt variance
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def next_variance_sum(current_avg, next_avg, item)
|
56
|
-
(@variance_sum + (next_avg**2 - current_avg**2) * @length + 2 * (current_avg - next_avg) * @sum) + (item - next_avg)**2
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
9
|
def initialize(enum)
|
61
10
|
@enum = enum
|
62
11
|
end
|
63
12
|
|
64
13
|
def each
|
65
14
|
ys = Enumerator.new do |y|
|
66
|
-
@enum.
|
15
|
+
@enum.inject(V.new) do |v1, item|
|
67
16
|
v2 = v1.next item
|
68
17
|
y << v2
|
69
18
|
v2
|
70
19
|
end
|
71
20
|
end
|
72
|
-
ys.each { |
|
21
|
+
ys.each { |stat| yield stat } if block_given?
|
73
22
|
ys
|
74
23
|
end
|
75
24
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class StreamStat
|
4
|
+
# Accumrator.
|
5
|
+
#
|
6
|
+
# This holds :avg, :variance & :sd.
|
7
|
+
class V
|
8
|
+
attr_reader :avg, :min, :max
|
9
|
+
|
10
|
+
def initialize(count = 0, avg = 0.0, square_avg = 0.0, min = Float::INFINITY, max = -Float::INFINITY)
|
11
|
+
@count = count
|
12
|
+
@avg = avg
|
13
|
+
@square_avg = square_avg
|
14
|
+
@min = min
|
15
|
+
@max = max
|
16
|
+
end
|
17
|
+
|
18
|
+
def next(item)
|
19
|
+
item = item.to_f
|
20
|
+
next_length = @count + 1
|
21
|
+
self.class.new(
|
22
|
+
next_length,
|
23
|
+
next_avg(next_length, item),
|
24
|
+
next_square_avg(next_length, item),
|
25
|
+
[@min, item].min,
|
26
|
+
[@max, item].max
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def variance
|
31
|
+
@square_avg - @avg**2
|
32
|
+
end
|
33
|
+
|
34
|
+
def sd
|
35
|
+
Math.sqrt variance
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def next_avg(next_length, item)
|
41
|
+
@count.to_f / next_length * @avg + item / next_length
|
42
|
+
end
|
43
|
+
|
44
|
+
def next_square_avg(next_length, item)
|
45
|
+
@count.to_f / next_length * @square_avg + item**2 / next_length
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/stream_stat/version.rb
CHANGED
data/stream_stat.gemspec
CHANGED
@@ -23,9 +23,14 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.require_paths = ['lib']
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
27
|
+
spec.add_development_dependency 'guard'
|
28
|
+
spec.add_development_dependency 'guard-rspec'
|
29
|
+
spec.add_development_dependency 'guard-rubocop'
|
26
30
|
spec.add_development_dependency 'rake'
|
27
31
|
spec.add_development_dependency 'rspec'
|
28
32
|
spec.add_development_dependency 'rspec-its'
|
33
|
+
spec.add_development_dependency 'rspec-parameterized'
|
29
34
|
spec.add_development_dependency 'rubocop'
|
30
35
|
spec.add_development_dependency 'rubocop-rspec'
|
31
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_stat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ne_Sachirou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,62 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codeclimate-test-reporter
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
27
83
|
- !ruby/object:Gem::Dependency
|
28
84
|
name: rake
|
29
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +122,20 @@ dependencies:
|
|
66
122
|
- - ">="
|
67
123
|
- !ruby/object:Gem::Version
|
68
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-parameterized
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
69
139
|
- !ruby/object:Gem::Dependency
|
70
140
|
name: rubocop
|
71
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,10 +178,16 @@ files:
|
|
108
178
|
- ".travis.yml"
|
109
179
|
- Gemfile
|
110
180
|
- Gemfile.lock
|
181
|
+
- Guardfile
|
111
182
|
- LICENSE
|
112
183
|
- README.md
|
184
|
+
- README.md.erb
|
113
185
|
- Rakefile
|
186
|
+
- example/1.rb
|
187
|
+
- example/2.rb
|
188
|
+
- example/example.rb
|
114
189
|
- lib/stream_stat.rb
|
190
|
+
- lib/stream_stat/v.rb
|
115
191
|
- lib/stream_stat/version.rb
|
116
192
|
- stream_stat.gemspec
|
117
193
|
homepage: https://github.com/ne-sachirou/stream_stat
|
@@ -133,7 +209,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
209
|
version: '0'
|
134
210
|
requirements: []
|
135
211
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.5.1
|
137
213
|
signing_key:
|
138
214
|
specification_version: 4
|
139
215
|
summary: 'StreamStat: Aggregate large data statictics with streaming.'
|