to_histogram 1.0.12 → 1.0.13

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: 95f6c12298b9da0f4bf82a323b643cb61309bbd8
4
- data.tar.gz: cb98da14fc867bb1a50d150c1c2dbb0e1317e997
3
+ metadata.gz: 4f7a5efff36a9fd8c54c233cfdc39985b4877a8d
4
+ data.tar.gz: 5af300736977af50a2feb8959c796706b9f3f227
5
5
  SHA512:
6
- metadata.gz: 86bfa3f3d6f6de5033c1b6036096dc6c25cc1f0fe04dc195c9bcdb1e8d45b164ae7b467a7f3d856bdf72a404f91eb7326a6a263d3065d5077c71787312929c60
7
- data.tar.gz: 9ab0280cf88d0f7fc71f19285a061baa5f733635e3f59efc599c98d61ec3075c0c315a981e40a0183770a954920706180314de7bef99ef44313ab04147c39b7c
6
+ metadata.gz: 359d663aa9272e65df320de8dc23c0d641e405d6484a1626fb915ac50c1bbc0a554a011947bb3f6841dfc176af05826adf80e624b33d929e336fc701e8102def
7
+ data.tar.gz: e27aaa6a607b942b75e73e7e51725c2dc482260f4755bc7a980fca293812a4ebb193b252a01f1b335445b55f8d097020f944900198024f9c82caa9e95d3c6f18
data/lib/bucketizer.rb CHANGED
@@ -5,7 +5,7 @@ module ToHistogram
5
5
  class Bucketizer
6
6
 
7
7
  def initialize(array, num_buckets: 20, bucket_width: 'auto', percentile: 100)
8
- @arr = array.sort
8
+ @arr = prepare_data(array)
9
9
  @num_buckets = num_buckets
10
10
  @percentile = percentile
11
11
 
@@ -66,6 +66,14 @@ module ToHistogram
66
66
  end
67
67
 
68
68
  private
69
+ def prepare_data(data)
70
+ if(data.any? { |e| e.is_a? String })
71
+ return (data.map { |e| e.to_i }).sort
72
+ else
73
+ return data.sort
74
+ end
75
+ end
76
+
69
77
  def get_initial_next_bucket(increments)
70
78
  if(@arr[0] != nil && @arr[0] < 0)
71
79
  return (@arr[0] + increments)
data/lib/stdout_print.rb CHANGED
@@ -5,13 +5,22 @@ module ToHistogram
5
5
  class StdoutPrint
6
6
  include Averages
7
7
 
8
- def initialize(histogram, original_array, stdout=$stdout)
8
+ def initialize(histogram, stdout=$stdout)
9
9
  @histogram = histogram
10
- @original_array = original_array.sort
11
10
  @stdout = stdout
12
11
  end
13
12
 
14
- def invoke
13
+ def invoke
14
+ if @histogram.length == 0
15
+ @stdout.puts "You have no histogram data"
16
+ return
17
+ end
18
+
19
+ if (@histogram.length == 1 && (@histogram[0].from == 0 && @histogram[0].to == -1))
20
+ @stdout.puts "The data you have provided is not histogram-able"
21
+ return
22
+ end
23
+
15
24
  print_header
16
25
 
17
26
  print_body
@@ -40,7 +49,6 @@ module ToHistogram
40
49
  @stdout.printf("%-20s %-20s %-30s %-20s \n\n", "Range", "Frequency", " Percentage", "Histogram (each * =~ 1%)")
41
50
 
42
51
  @histogram.each_with_index do |b, i|
43
- #next_bucket = (@histogram[i + 1]) ? @histogram[i + 1][0] : b[-1]
44
52
  range = "#{@histogram[i].from} to #{@histogram[i].to}"
45
53
  frequency = b.contents.length
46
54
  percentage = ((frequency.to_f / @histogram.bucket_contents_length) * 100)
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.12
4
+ version: 1.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Sykes