to_histogram 1.0.10 → 1.0.11
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 +7 -1
- data/lib/stdout_print.rb +6 -2
- data/lib/to_histogram.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d05347479d1ed05a641f8340d5fa10f5ed46a289
|
4
|
+
data.tar.gz: 5a0b25984a17f27b7fe899c8ff3706a86a044bf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdb131e078435c3899409b12fd1ac6f442b1b83a6aa15f9c5228389b6464306e0ae78b0e1a21bacf654709cd472c26e80624e9693c327e6458217b269438efb6
|
7
|
+
data.tar.gz: 16077b970962f3846b3df7d6353a7331e05c5c11204f9008d331f98dffdf0d8d3ed4448b488a94fb2be6fdd335136bd2ae7641eae6e46890fd1bd657af0c9419
|
data/lib/bucketizer.rb
CHANGED
@@ -2,7 +2,7 @@ module ToHistogram
|
|
2
2
|
|
3
3
|
class Bucketizer
|
4
4
|
|
5
|
-
def initialize(array, num_buckets:
|
5
|
+
def initialize(array, num_buckets: 20, bucket_width: 'auto', percentile: 100)
|
6
6
|
@arr = array.sort
|
7
7
|
@num_buckets = num_buckets
|
8
8
|
@percentile = percentile
|
@@ -41,6 +41,12 @@ module ToHistogram
|
|
41
41
|
|
42
42
|
l_index = i
|
43
43
|
next_bucket += @bucket_width
|
44
|
+
|
45
|
+
# Add empty buckets until the next bucket is greater than the current l_index
|
46
|
+
while(next_bucket < @arr[l_index])
|
47
|
+
buckets << []
|
48
|
+
next_bucket += @bucket_width
|
49
|
+
end
|
44
50
|
end
|
45
51
|
end
|
46
52
|
|
data/lib/stdout_print.rb
CHANGED
@@ -40,9 +40,11 @@ module ToHistogram
|
|
40
40
|
total_data_value_length = (@histogram.map { |b| b.length }).reduce(:+)
|
41
41
|
@stdout.printf("%-20s %-20s %-30s %-20s \n\n", "Range", "Frequency", " Percentage", "Histogram (each * =~ 1%)")
|
42
42
|
|
43
|
+
from = @histogram[0][0]
|
44
|
+
to = (from + @histogram.bucket_width - 1)
|
43
45
|
@histogram.each_with_index do |b, i|
|
44
|
-
next_bucket = (@histogram[i + 1]) ? @histogram[i + 1][0] : b[-1]
|
45
|
-
range = "#{
|
46
|
+
#next_bucket = (@histogram[i + 1]) ? @histogram[i + 1][0] : b[-1]
|
47
|
+
range = "#{from} to #{to}"
|
46
48
|
frequency = b.length
|
47
49
|
percentage = ((frequency.to_f / total_data_value_length) * 100)
|
48
50
|
stars = ''
|
@@ -55,6 +57,8 @@ module ToHistogram
|
|
55
57
|
end
|
56
58
|
|
57
59
|
@stdout.printf("%-20s | %-20s | %-30s | %-20s \n", range, frequency, ('%.4f' % percentage), stars)
|
60
|
+
from = to + 1
|
61
|
+
to += @histogram.bucket_width
|
58
62
|
end
|
59
63
|
end
|
60
64
|
|
data/lib/to_histogram.rb
CHANGED
@@ -2,7 +2,7 @@ require_relative './histogram'
|
|
2
2
|
require_relative './stdout_print'
|
3
3
|
|
4
4
|
class Array
|
5
|
-
def to_histogram(num_buckets:
|
5
|
+
def to_histogram(num_buckets: 20, bucket_width: 'auto', percentile: 100, print_info: true)
|
6
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
|
|