rstat 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +80 -0
- data/CHANGELOG.md +10 -0
- data/lib/rstat/core_ext/array.rb +3 -4
- data/lib/rstat/core_ext/array/mean.rb +2 -2
- data/lib/rstat/core_ext/array/mode.rb +4 -19
- data/lib/rstat/core_ext/array/product.rb +5 -0
- data/lib/rstat/core_ext/array/range.rb +5 -0
- data/lib/rstat/core_ext/array/standard_deviation.rb +4 -0
- data/lib/rstat/core_ext/array/sum.rb +5 -0
- data/lib/rstat/version.rb +1 -1
- data/spec/rstat/array_spec.rb +23 -1
- metadata +40 -53
data/.rvmrc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ruby-1.9.3-p194@rstat"
|
8
|
+
|
9
|
+
#
|
10
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
11
|
+
#
|
12
|
+
# rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
#
|
18
|
+
|
19
|
+
#
|
20
|
+
# Uncomment following line if you want options to be set only for given project.
|
21
|
+
#
|
22
|
+
# PROJECT_JRUBY_OPTS=( --1.9 )
|
23
|
+
#
|
24
|
+
# The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
|
25
|
+
#
|
26
|
+
# chmod +x ${rvm_path}/hooks/after_use_jruby_opts
|
27
|
+
#
|
28
|
+
|
29
|
+
#
|
30
|
+
# First we attempt to load the desired environment directly from the environment
|
31
|
+
# file. This is very fast and efficient compared to running through the entire
|
32
|
+
# CLI and selector. If you want feedback on which environment was used then
|
33
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
34
|
+
#
|
35
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
36
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
37
|
+
then
|
38
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
39
|
+
|
40
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
41
|
+
then
|
42
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
43
|
+
fi
|
44
|
+
else
|
45
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
46
|
+
if ! rvm --create "$environment_id"
|
47
|
+
then
|
48
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
49
|
+
return 1
|
50
|
+
fi
|
51
|
+
fi
|
52
|
+
|
53
|
+
#
|
54
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
55
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
56
|
+
# necessary.
|
57
|
+
#
|
58
|
+
# filename=".gems"
|
59
|
+
# if [[ -s "$filename" ]]
|
60
|
+
# then
|
61
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
62
|
+
# fi
|
63
|
+
|
64
|
+
# If you use bundler, this might be useful to you:
|
65
|
+
# if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
|
66
|
+
# then
|
67
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
68
|
+
# gem install bundler
|
69
|
+
# fi
|
70
|
+
# if [[ -s Gemfile ]] && command -v bundle
|
71
|
+
# then
|
72
|
+
# bundle install
|
73
|
+
# fi
|
74
|
+
|
75
|
+
if [[ $- == *i* ]] # check for interactive shells
|
76
|
+
then
|
77
|
+
echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
|
78
|
+
else
|
79
|
+
echo "Using: $GEM_HOME" # don't use colors in interactive shells
|
80
|
+
fi
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
## v0.0.3
|
2
|
+
|
3
|
+
* Better mode algorithm.
|
4
|
+
* Fixed geometric mean test to test for realness instead of NaN because Ruby 1.9+ returns complex number instead of NaN when there's negative numbers in the set.
|
5
|
+
* Made array.rb load all files automatically instead of listing them manually.
|
6
|
+
* Added sum.
|
7
|
+
* Added product.
|
8
|
+
* Added range.
|
9
|
+
* Added coefficient of variation.
|
10
|
+
|
1
11
|
## v0.0.2
|
2
12
|
|
3
13
|
* Added standard deviation.
|
data/lib/rstat/core_ext/array.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
require "rstat/core_ext/array
|
3
|
-
|
4
|
-
require "rstat/core_ext/array/standard_deviation"
|
1
|
+
Dir["#{File.dirname(__FILE__)}/array/*.rb"].sort.each do |path|
|
2
|
+
require "rstat/core_ext/array/#{File.basename(path, ".rb")}"
|
3
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Array
|
2
2
|
def mean
|
3
|
-
self.
|
3
|
+
self.sum.to_f / self.length
|
4
4
|
end
|
5
5
|
|
6
6
|
def arithmetric_mean
|
@@ -8,7 +8,7 @@ class Array
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def geometric_mean
|
11
|
-
self.
|
11
|
+
self.product.to_f ** (1.0 / self.length)
|
12
12
|
end
|
13
13
|
|
14
14
|
def harmonic_mean
|
@@ -4,27 +4,12 @@ class Array
|
|
4
4
|
return self
|
5
5
|
end
|
6
6
|
|
7
|
-
|
7
|
+
seen = Hash.new(0)
|
8
8
|
|
9
|
-
self.
|
9
|
+
self.each{ |value| seen[value] += 1 }
|
10
10
|
|
11
|
-
|
11
|
+
max = seen.values.max
|
12
12
|
|
13
|
-
|
14
|
-
modes = []
|
15
|
-
|
16
|
-
q.each_cons(2) do |pair|
|
17
|
-
if !pair[1].nil? and pair[0][1] == pair[1][1]
|
18
|
-
modes << pair[0][0]
|
19
|
-
modes << pair[1][0]
|
20
|
-
else
|
21
|
-
break
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
modes.uniq.sort
|
26
|
-
else
|
27
|
-
[q[0][0]]
|
28
|
-
end
|
13
|
+
seen.find_all{ |key, value| value == max }.map{ |key, value| key }
|
29
14
|
end
|
30
15
|
end
|
data/lib/rstat/version.rb
CHANGED
data/spec/rstat/array_spec.rb
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Rstat do
|
5
|
+
describe ".sum" do
|
6
|
+
it "calculates the sum of an array" do
|
7
|
+
[1, 2, 3, 4, 5, 6].sum.should be(21)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".product" do
|
12
|
+
it "calculates the product of an array" do
|
13
|
+
[1, 2, 3, 4, 5, 6].product.should be(720)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe ".range" do
|
18
|
+
it "finds the range of an array" do
|
19
|
+
[0, 34, 656, 400, 1000].range.should be(1000)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
5
23
|
describe ".mean" do
|
6
24
|
it "calculates the mean of an array" do
|
7
25
|
[1, 2, 3, 4, 5].mean.should be_within(0.0001).of(3.0000)
|
@@ -18,7 +36,7 @@ describe Rstat do
|
|
18
36
|
end
|
19
37
|
|
20
38
|
it "calculates the geometric mean of an array with a negative element" do
|
21
|
-
[-1, 2, 3, 4, 5].geometric_mean.
|
39
|
+
[-1, 2, 3, 4, 5].geometric_mean.real?.should be_false
|
22
40
|
end
|
23
41
|
end
|
24
42
|
|
@@ -83,5 +101,9 @@ describe Rstat do
|
|
83
101
|
it "calculates the standard deviation of an array" do
|
84
102
|
[1, 2, 3, 4, 5, 6].standard_deviation.should be_within(0.00001).of(1.70783)
|
85
103
|
end
|
104
|
+
|
105
|
+
it "calculates the coefficient of variation of an array" do
|
106
|
+
[1, 2, 3, 4, 5, 6].coefficient_of_variation.should be_within(0.00001).of(0.48795)
|
107
|
+
end
|
86
108
|
end
|
87
109
|
end
|
metadata
CHANGED
@@ -1,48 +1,41 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rstat
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 2
|
10
|
-
version: 0.0.2
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Sean Eshbaugh
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-05-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
35
30
|
description: A Simple statistics gem.
|
36
|
-
email:
|
31
|
+
email:
|
37
32
|
- seaneshbaugh@gmail.com
|
38
33
|
executables: []
|
39
|
-
|
40
34
|
extensions: []
|
41
|
-
|
42
35
|
extra_rdoc_files: []
|
43
|
-
|
44
|
-
files:
|
36
|
+
files:
|
45
37
|
- .gitignore
|
38
|
+
- .rvmrc
|
46
39
|
- CHANGELOG.md
|
47
40
|
- Gemfile
|
48
41
|
- README.md
|
@@ -53,44 +46,38 @@ files:
|
|
53
46
|
- lib/rstat/core_ext/array/mean.rb
|
54
47
|
- lib/rstat/core_ext/array/median.rb
|
55
48
|
- lib/rstat/core_ext/array/mode.rb
|
49
|
+
- lib/rstat/core_ext/array/product.rb
|
50
|
+
- lib/rstat/core_ext/array/range.rb
|
56
51
|
- lib/rstat/core_ext/array/standard_deviation.rb
|
52
|
+
- lib/rstat/core_ext/array/sum.rb
|
57
53
|
- lib/rstat/version.rb
|
58
54
|
- rstat.gemspec
|
59
55
|
- spec/rstat/array_spec.rb
|
60
56
|
- spec/spec_helper.rb
|
61
|
-
has_rdoc: true
|
62
57
|
homepage: http://seaneshbaugh.com/
|
63
58
|
licenses: []
|
64
|
-
|
65
59
|
post_install_message:
|
66
60
|
rdoc_options: []
|
67
|
-
|
68
|
-
require_paths:
|
61
|
+
require_paths:
|
69
62
|
- lib
|
70
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
64
|
none: false
|
72
|
-
requirements:
|
73
|
-
- -
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
|
76
|
-
|
77
|
-
- 0
|
78
|
-
version: "0"
|
79
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
70
|
none: false
|
81
|
-
requirements:
|
82
|
-
- -
|
83
|
-
- !ruby/object:Gem::Version
|
84
|
-
|
85
|
-
segments:
|
86
|
-
- 0
|
87
|
-
version: "0"
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
88
75
|
requirements: []
|
89
|
-
|
90
76
|
rubyforge_project: rstat
|
91
|
-
rubygems_version: 1.
|
77
|
+
rubygems_version: 1.8.23
|
92
78
|
signing_key:
|
93
79
|
specification_version: 3
|
94
80
|
summary: A Simple statistics gem.
|
95
|
-
test_files:
|
96
|
-
|
81
|
+
test_files:
|
82
|
+
- spec/rstat/array_spec.rb
|
83
|
+
- spec/spec_helper.rb
|