to_histogram 1.0.9 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bucketizer.rb +6 -6
- data/lib/histogram.rb +8 -8
- data/lib/stdout_print.rb +7 -6
- data/lib/to_histogram.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eca08f2d21e518ea5e4db6a1c30a59a2fb63b520
|
4
|
+
data.tar.gz: c174cf44570b3ce27d012e71d29e61481e72f521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 072f67a79f664adeda1a608045795e8eb8c4d6e5a688717ac4a860a2a9e6814a9d9dc3ff652bbdf782a39e1b55d04441bbec3a7a01148abe00f79d14cb476ea1
|
7
|
+
data.tar.gz: ae1d70a20e0fd9cd98c83efd66061cb51e5986ffb9cf96ad081b7ce82df9e22e0ef9e31e0ddfd846ae5bd838ad5aea0ae5ff95286893be381055ab7375c69bab
|
data/lib/bucketizer.rb
CHANGED
@@ -2,19 +2,19 @@ module ToHistogram
|
|
2
2
|
|
3
3
|
class Bucketizer
|
4
4
|
|
5
|
-
def initialize(array, num_buckets, percentile)
|
5
|
+
def initialize(array, num_buckets: 10, bucket_width: 'auto', percentile: 100)
|
6
6
|
@arr = array.sort
|
7
7
|
@num_buckets = num_buckets
|
8
|
-
@percentile =percentile
|
8
|
+
@percentile = percentile
|
9
9
|
|
10
10
|
remove_elements_outside_of_percentile
|
11
|
-
@
|
11
|
+
@bucket_width = (bucket_width == 'auto') ? get_bucket_increment : bucket_width
|
12
12
|
end
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :bucket_width
|
14
14
|
|
15
15
|
def create_buckets
|
16
16
|
l_index = 0
|
17
|
-
next_bucket = get_initial_next_bucket(@
|
17
|
+
next_bucket = get_initial_next_bucket(@bucket_width)
|
18
18
|
buckets = []
|
19
19
|
|
20
20
|
# Deal with the special case where we have elements that == 0 and an increment sizes of 1 (count 0 as a value and don't lump it in with 1)
|
@@ -40,7 +40,7 @@ module ToHistogram
|
|
40
40
|
end
|
41
41
|
|
42
42
|
l_index = i
|
43
|
-
next_bucket += @
|
43
|
+
next_bucket += @bucket_width
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/lib/histogram.rb
CHANGED
@@ -5,15 +5,15 @@ module ToHistogram
|
|
5
5
|
class Histogram
|
6
6
|
include Enumerable
|
7
7
|
|
8
|
-
def initialize(array, num_buckets, percentile)
|
9
|
-
bucketizer
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
8
|
+
def initialize(array, num_buckets: 10, bucket_width: 'auto', percentile: 100)
|
9
|
+
bucketizer = Bucketizer.new(array, num_buckets: num_buckets, bucket_width: bucket_width, percentile: percentile)
|
10
|
+
|
11
|
+
@buckets = bucketizer.create_buckets
|
12
|
+
@bucket_width = bucketizer.bucket_width
|
13
|
+
@percentile = percentile
|
14
|
+
@num_buckets = num_buckets
|
15
15
|
end
|
16
|
-
attr_reader :
|
16
|
+
attr_reader :percentile, :num_buckets, :bucket_width, :buckets
|
17
17
|
|
18
18
|
def each(&block)
|
19
19
|
@buckets.each do |b|
|
data/lib/stdout_print.rb
CHANGED
@@ -20,18 +20,19 @@ module ToHistogram
|
|
20
20
|
private
|
21
21
|
def print_header
|
22
22
|
@stdout.puts "\n**************************************************************"
|
23
|
-
@stdout.puts "Results for #to_histogram(num_buckets: #{@histogram.num_buckets}, percentile: #{@histogram.percentile}, print_info: true)"
|
23
|
+
@stdout.puts "Results for #to_histogram(num_buckets: #{@histogram.num_buckets}, bucket_width: #{@histogram.bucket_width}, percentile: #{@histogram.percentile}, print_info: true)"
|
24
24
|
|
25
25
|
@stdout.puts "\n"
|
26
26
|
|
27
27
|
percentile_info = (@histogram.percentile == 100) ? '' : "(Numbers limited to the #{@histogram.percentile}th percentile)"
|
28
28
|
@stdout.puts "Data set used in this calculation #{percentile_info}"
|
29
|
-
@stdout.puts "Data set Size: #{@histogram.
|
30
|
-
|
31
|
-
@stdout.puts "
|
29
|
+
@stdout.puts "Data set Size: #{@histogram.reduce(:+).length} items"
|
30
|
+
|
31
|
+
@stdout.puts "Min Value: #{@histogram[0][0]}, Max Value: #{@histogram[-1][-1]}"
|
32
|
+
@stdout.puts "Mean: #{mean(@histogram.reduce(:+))}, Median: #{median(@histogram.reduce(:+))}, Mode: #{mode(@histogram.reduce(:+))}"
|
32
33
|
@stdout.puts "\n"
|
33
34
|
|
34
|
-
@stdout.puts "Histogram bucket
|
35
|
+
@stdout.puts "Histogram bucket width: #{@histogram.bucket_width}"
|
35
36
|
@stdout.puts "**************************************************************\n\n"
|
36
37
|
end
|
37
38
|
|
@@ -48,7 +49,7 @@ module ToHistogram
|
|
48
49
|
percentage.round.times { |x| stars << '*' }
|
49
50
|
|
50
51
|
if(i == (@histogram.length - 1))
|
51
|
-
if(b[-1] - b[0] != 0 && (b[-1] - b[0] > @histogram.
|
52
|
+
if(b[-1] - b[0] != 0 && (b[-1] - b[0] > @histogram.bucket_width))
|
52
53
|
range = "> than #{b[0]}"
|
53
54
|
end
|
54
55
|
end
|
data/lib/to_histogram.rb
CHANGED
@@ -2,8 +2,8 @@ require_relative './histogram'
|
|
2
2
|
require_relative './stdout_print'
|
3
3
|
|
4
4
|
class Array
|
5
|
-
def to_histogram(num_buckets: 10, percentile: 100, print_info: true)
|
6
|
-
histogram = ToHistogram::Histogram.new(self, num_buckets, percentile)
|
5
|
+
def to_histogram(num_buckets: 10, bucket_width: 'auto', percentile: 100, print_info: true)
|
6
|
+
histogram = ToHistogram::Histogram.new(self, num_buckets: num_buckets, bucket_width: bucket_width, percentile: percentile)
|
7
7
|
stdout_print = ToHistogram::StdoutPrint.new(histogram, self)
|
8
8
|
|
9
9
|
stdout_print.invoke if print_info
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_histogram
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Sykes
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Adds #to_histogram to Array. Returns a histogram distribution object
|
14
14
|
from an Array and optionally prints detailed info to stdout.'
|