ministat 1.2.1 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,21 @@
1
+ == 1.2.4 / 2010-09-18
2
+
3
+ * Version bump for packaging
4
+
5
+ == 1.2.2 / 2010-09-18
6
+
7
+ * Returned to Hoe's sweet embrace
8
+ * Minor median bug fix
9
+ * Cleaned up packaging stuff
10
+ * Added a little to the Synopsis
11
+
12
+ == 1.1.*
13
+
14
+ * Moved most everything into MiniStat::Data
15
+ * Added geometric and harmonic means
16
+ * Briefly left Hoe's sweet embrace while the author suffered confusion regarding rubygems.org
17
+
18
+ == 1.0.0 / 2007-11-11
19
+
20
+ * Birthday!
21
+
@@ -0,0 +1,9 @@
1
+ History.rdoc
2
+ Manifest.txt
3
+ README.rdoc
4
+ Rakefile
5
+ bin/ministat
6
+ lib/ministat.rb
7
+ test/data/1.dat
8
+ test/data/2.dat
9
+ test/test_ministat.rb
@@ -1,5 +1,6 @@
1
- ministat
2
- Author: H. Dean Hudson <dean@ero.com>
1
+ = ministat
2
+
3
+ * http://github.com/deanh/MiniStat
3
4
 
4
5
  == DESCRIPTION:
5
6
 
@@ -22,11 +23,22 @@ at least to get you thinking about what it may take to do so.
22
23
  require 'ministat'
23
24
 
24
25
  data = [1,2,3,4,5,6,7,7,6,5,4,4]
26
+ d = MiniStat::Data.new(data)
27
+
28
+ d.median # => 4.5
29
+ d.mean # => 4.5
30
+ d.mode # => 4.0
31
+ d.q1 # => 3.5
32
+ d.outliers # => []
33
+ d.std_dev # => 1.80277563773199
34
+ # and so on...
35
+
25
36
  puts MiniStat::Data.new(data).to_s
37
+ # this outputs most everything
26
38
 
27
39
  == REQUIREMENTS:
28
40
 
29
- None
41
+ Hoe is your friend.
30
42
 
31
43
  == INSTALL:
32
44
 
data/Rakefile CHANGED
@@ -7,9 +7,10 @@ spec = Gem::Specification.new do |p|
7
7
  p.author = 'Dean Hudson'
8
8
  p.email = 'dean@ero.com'
9
9
  p.summary = 'A small and simple library to generate statistical info on single-variable datasets.'
10
- p.description = File.read(File.join(File.dirname(__FILE__), 'README'))
10
+ p.description = File.read(File.join(File.dirname(__FILE__), 'README.rdoc'))
11
11
  p.requirements = ['An eye for data and a strong will to live']
12
12
  p.has_rdoc = true
13
13
  p.files = Dir['**/**']
14
14
  end
15
15
  Rake::GemPackageTask.new(spec).define
16
+
@@ -1,7 +1,7 @@
1
1
  require 'mathn'
2
2
 
3
3
  module MiniStat
4
- VERSION = '1.2.1'
4
+ VERSION = '1.2.5'
5
5
  class Data
6
6
  attr_reader :data
7
7
 
@@ -26,10 +26,12 @@ module MiniStat
26
26
  @sort = true
27
27
  end
28
28
  if data.size % 2 == 0
29
- return (data[data.size / 2 - 1] + data[(data.size / 2)]) / 2
29
+ return (data[data.size / 2.0 - 1] + data[(data.size / 2.0)]) / 2
30
30
  else
31
- split = (data.size + 1) / 2
32
- return (data[split - 1.5] + data[split - 0.5]) / 2
31
+ # split = (data.size - 1) / 2
32
+ # this was just weird. i need to look this up
33
+ # return (data[split - 1.5] + data[split - 0.5]) / 2
34
+ return data[(data.size - 1)/2]
33
35
  end
34
36
  end
35
37
 
@@ -82,7 +84,7 @@ module MiniStat
82
84
  @hist[val] ||= 0
83
85
  @hist[val] += 1
84
86
  @max_freq, @mode = @hist[val], val if @hist[val] > @max_freq
85
- end
87
+ end
86
88
  end
87
89
  @mode
88
90
  end
@@ -115,21 +117,22 @@ module MiniStat
115
117
  end
116
118
 
117
119
  # Put the histogram into a string if we have it
118
- # def hist
119
- # str = ''
120
- # if defined? @hist
121
- # # this is a textbook example of how to lie with statistics...
122
- # # TODO: iterate over a range rather than @hist.keys--a histogram
123
- # # produced out of the keys won't properly represent flat spots
124
- # # with no data. or something like that. do as i say, not as i do.
125
- # @hist.keys do |k|
126
- # str << "[#{k}\t] "
127
- # 1.upto(@hist[k].to_i) {|i| str << "*"}
128
- # str << "\n"
129
- # end
130
- # end
131
- # str
132
- # end
120
+ def hist
121
+ if defined? @hist
122
+ # this is a textbook example of how to lie with statistics...
123
+ # TODO: iterate over a range rather than @hist.keys--a histogram
124
+ # produced out of the keys won't properly represent flat spots
125
+ # with no data. or something like that. do as i say, not as i do.
126
+ #
127
+ # this code borrows liberally from the ruby cookbook, recipe 5.12
128
+ # ORA, 2006
129
+ pairs = @hist.keys.collect { |x| [x.to_s, @hist[x]] }.sort
130
+ largest_key_size = pairs.max {|x,y| x[0].size <=> y[0].size }[0].size
131
+ pairs.inject("") do |s,kv|
132
+ s<< "#{kv[0].ljust(largest_key_size)} |#{char*kv[1]}\n"
133
+ end
134
+ end
135
+ end
133
136
 
134
137
  # Return a string with statisical info about a dataset.
135
138
  def to_s
@@ -4,8 +4,6 @@
4
4
 
5
5
  require 'test/unit' unless defined? $ZENTEST and $ZENTEST
6
6
  require 'ministat'
7
- require 'rubygems'
8
- require 'ruby-debug'
9
7
 
10
8
  class TestMiniStat < Test::Unit::TestCase
11
9
  def setup
@@ -59,7 +57,7 @@ class TestMiniStat < Test::Unit::TestCase
59
57
  def test_q1
60
58
  assert(@ms1.q1 - 17 < @error)
61
59
  assert(@ms3.q1 - 1.05 < @error)
62
- assert(@ms4.q1 - -2.6 < @error)
60
+ assert(@ms4.q1 - -2.4 < @error)
63
61
  end
64
62
 
65
63
  def test_q3
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ministat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
5
4
  prerelease: false
6
5
  segments:
7
6
  - 1
8
7
  - 2
9
- - 1
10
- version: 1.2.1
8
+ - 5
9
+ version: 1.2.5
11
10
  platform: ruby
12
11
  authors:
13
12
  - Dean Hudson
@@ -15,13 +14,14 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-06-18 00:00:00 -07:00
17
+ date: 2010-11-13 00:00:00 -08:00
19
18
  default_executable:
20
19
  dependencies: []
21
20
 
22
21
  description: |
23
- ministat
24
- Author: H. Dean Hudson <dean@ero.com>
22
+ = ministat
23
+
24
+ * http://github.com/deanh/MiniStat
25
25
 
26
26
  == DESCRIPTION:
27
27
 
@@ -44,11 +44,22 @@ description: |
44
44
  require 'ministat'
45
45
 
46
46
  data = [1,2,3,4,5,6,7,7,6,5,4,4]
47
+ d = MiniStat::Data.new(data)
48
+
49
+ d.median # => 4.5
50
+ d.mean # => 4.5
51
+ d.mode # => 4.0
52
+ d.q1 # => 3.5
53
+ d.outliers # => []
54
+ d.std_dev # => 1.80277563773199
55
+ # and so on...
56
+
47
57
  puts MiniStat::Data.new(data).to_s
58
+ # this outputs most everything
48
59
 
49
60
  == REQUIREMENTS:
50
61
 
51
- None
62
+ Hoe is your friend.
52
63
 
53
64
  == INSTALL:
54
65
 
@@ -87,15 +98,15 @@ extensions: []
87
98
  extra_rdoc_files: []
88
99
 
89
100
  files:
90
- - History.txt
91
- - pkg/ministat-1.2.0.gem
101
+ - bin/ministat
102
+ - History.rdoc
92
103
  - lib/ministat.rb
93
- - test/test_ministat.rb
94
- - test/data/2.dat
95
- - test/data/1.dat
104
+ - Manifest.txt
96
105
  - Rakefile
97
- - README
98
- - bin/ministat
106
+ - README.rdoc
107
+ - test/data/1.dat
108
+ - test/data/2.dat
109
+ - test/test_ministat.rb
99
110
  has_rdoc: true
100
111
  homepage:
101
112
  licenses: []
@@ -110,7 +121,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
121
  requirements:
111
122
  - - ">="
112
123
  - !ruby/object:Gem::Version
113
- hash: 3
114
124
  segments:
115
125
  - 0
116
126
  version: "0"
@@ -119,7 +129,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
129
  requirements:
120
130
  - - ">="
121
131
  - !ruby/object:Gem::Version
122
- hash: 3
123
132
  segments:
124
133
  - 0
125
134
  version: "0"
@@ -1,5 +0,0 @@
1
- == 1.0.0 / 2007-11-11
2
-
3
- * 1 major enhancement
4
- * Birthday!
5
-
Binary file