statkit 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1d7d29073704627fcb8793653485b7e35e1892e
4
+ data.tar.gz: a03ab89f53ffec59b4479cb9f0bb53e1d835f05d
5
+ SHA512:
6
+ metadata.gz: c108f774481f8a249274615078dd46e76c594b89feb3dfcb1161b8452af8868b755ec249c5012204355d8ddad124e90935eaec0cec9d264cc9cad744dc32eef4
7
+ data.tar.gz: 952fbcba3229a604d36be101e6c01fc628e83499f9d5cc545ddd8c8c515af0102e036384a9e69dcb11e7cd1eab429bc8825f231220b0d1421ae9a14ee11d3436
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statkit.gemspec
4
+ gemspec
@@ -0,0 +1,36 @@
1
+ # Statkit
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/statkit`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'statkit'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install statkit
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/statkit.
36
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "statkit"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "statkit"
4
+
5
+ exit(Statkit::CLI.new.run(ARGV))
@@ -0,0 +1,3 @@
1
+ require "statkit/version"
2
+ require 'statkit/cli'
3
+ require 'statkit/specexp'
@@ -0,0 +1,68 @@
1
+
2
+ require 'optparse'
3
+
4
+ module Statkit
5
+ class CLI
6
+ def initialize()
7
+ setup_parser
8
+ end
9
+
10
+ def setup_parser()
11
+ @parser = OptionParser.new
12
+ @parser.banner = "Usage: statkit [options] STAT_SPEC"
13
+
14
+ @parser.on('-h', '--help', 'Show this help.') do
15
+ puts(@parser.help)
16
+ exit(true)
17
+ end
18
+ end
19
+
20
+ def do_parse(argv)
21
+ argv = argv.dup
22
+ @parser.parse!(argv)
23
+ @args = argv
24
+
25
+ if @args.size < 1
26
+ $stderr.puts("[ERROR] STAT_SPEC is not specified.")
27
+ $stderr.puts("")
28
+ puts(@parser.help)
29
+ exit(false)
30
+ end
31
+
32
+ @stat_spec = @args.first
33
+
34
+ true
35
+ end
36
+
37
+ def run(argv)
38
+ do_parse(argv)
39
+
40
+ exps = @stat_spec.split().map do |spec|
41
+ case spec
42
+ when "avg"
43
+ ::Statkit::Spec::AvgFuncExp.new
44
+ when "stdev"
45
+ ::Statkit::Spec::StdevFuncExp.new
46
+ when "min"
47
+ ::Statkit::Spec::MinFuncExp.new
48
+ when "max"
49
+ ::Statkit::Spec::MaxFuncExp.new
50
+ else
51
+ raise RuntimeError.new("Unknown function: #{spec}")
52
+ end
53
+ end
54
+
55
+ $stdin.each_line do |line|
56
+ val = Float(line)
57
+
58
+ exps.each do |exp|
59
+ exp.add_input(val)
60
+ end
61
+ end
62
+
63
+ puts(exps.map(&:evaluate).join("\t"))
64
+
65
+ true
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,116 @@
1
+
2
+ module Statkit
3
+ module Spec
4
+ class BaseExp
5
+ # return true if this expression is evaluated with streaming input
6
+ def streaming?
7
+ false
8
+ end
9
+
10
+ # evaluate with bulk input
11
+ def evaluate()
12
+ raise NotImplementedError.new
13
+ end
14
+
15
+ # add input for evaluation
16
+ def add_input(input_chunk)
17
+ if ! input_chunk.is_a?(Array)
18
+ input_chunk = [input_chunk]
19
+ end
20
+
21
+ add_input_chunk(input_chunk)
22
+ end
23
+ end
24
+
25
+ class AvgFuncExp < BaseExp
26
+ def initialize
27
+ @nr_input = 0
28
+ @sum = 0
29
+ end
30
+
31
+ def streaming?
32
+ true
33
+ end
34
+
35
+ def add_input_chunk(input_chunk)
36
+ input_chunk.each do |val|
37
+ @sum += val
38
+ @nr_input += 1
39
+ end
40
+ end
41
+
42
+ def evaluate()
43
+ @sum / @nr_input.to_f
44
+ end
45
+ end
46
+
47
+ class StdevFuncExp < BaseExp
48
+ def initialize
49
+ @nr_input = 0
50
+ @sum = 0
51
+ @sum_sq = 0
52
+ end
53
+
54
+ def streaming?
55
+ true
56
+ end
57
+
58
+ def add_input_chunk(input_chunk)
59
+ input_chunk.each do |val|
60
+ @nr_input += 1
61
+ @sum += val
62
+ @sum_sq += val ** 2
63
+ end
64
+ end
65
+
66
+ def evaluate()
67
+ var = @sum_sq / @nr_input.to_f - (@sum / @nr_input.to_f)**2
68
+ Math.sqrt(var) * Math.sqrt(@nr_input / (@nr_input.to_f - 1))
69
+ end
70
+ end
71
+
72
+ class MinFuncExp < BaseExp
73
+ def initialize
74
+ @min = nil
75
+ end
76
+
77
+ def streaming?
78
+ true
79
+ end
80
+
81
+ def add_input_chunk(input_chunk)
82
+ if @min.nil?
83
+ @min = input_chunk.min
84
+ else
85
+ @min = (input_chunk + [@min]).min
86
+ end
87
+ end
88
+
89
+ def evaluate()
90
+ @min
91
+ end
92
+ end
93
+
94
+ class MaxFuncExp < BaseExp
95
+ def initialize
96
+ @max = nil
97
+ end
98
+
99
+ def streaming?
100
+ true
101
+ end
102
+
103
+ def add_input_chunk(input_chunk)
104
+ if @max.nil?
105
+ @max = input_chunk.max
106
+ else
107
+ @max = (input_chunk + [@max]).max
108
+ end
109
+ end
110
+
111
+ def evaluate()
112
+ @max
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,3 @@
1
+ module Statkit
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'statkit/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "statkit"
8
+ spec.version = Statkit::VERSION
9
+ spec.authors = ["Yuto Hayamizu"]
10
+ spec.email = ["y.hayamizu@gmail.com"]
11
+
12
+ spec.summary = %q{Command line statistical analysis kit}
13
+ spec.description = %q{Command line statistical analysis kit}
14
+ spec.homepage = "https://github.com/hayamiz/statkit"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statkit
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yuto Hayamizu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Command line statistical analysis kit
56
+ email:
57
+ - y.hayamizu@gmail.com
58
+ executables:
59
+ - statkit
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - exe/statkit
71
+ - lib/statkit.rb
72
+ - lib/statkit/cli.rb
73
+ - lib/statkit/specexp.rb
74
+ - lib/statkit/version.rb
75
+ - statkit.gemspec
76
+ homepage: https://github.com/hayamiz/statkit
77
+ licenses: []
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.5.1
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Command line statistical analysis kit
99
+ test_files: []