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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eca08f2d21e518ea5e4db6a1c30a59a2fb63b520
4
- data.tar.gz: c174cf44570b3ce27d012e71d29e61481e72f521
3
+ metadata.gz: d05347479d1ed05a641f8340d5fa10f5ed46a289
4
+ data.tar.gz: 5a0b25984a17f27b7fe899c8ff3706a86a044bf2
5
5
  SHA512:
6
- metadata.gz: 072f67a79f664adeda1a608045795e8eb8c4d6e5a688717ac4a860a2a9e6814a9d9dc3ff652bbdf782a39e1b55d04441bbec3a7a01148abe00f79d14cb476ea1
7
- data.tar.gz: ae1d70a20e0fd9cd98c83efd66061cb51e5986ffb9cf96ad081b7ce82df9e22e0ef9e31e0ddfd846ae5bd838ad5aea0ae5ff95286893be381055ab7375c69bab
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: 10, bucket_width: 'auto', percentile: 100)
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 = "#{b[0]} to #{next_bucket}"
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: 10, bucket_width: 'auto', percentile: 100, print_info: true)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: to_histogram
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Sykes