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 +4 -4
- data/lib/bucketizer.rb +9 -1
- data/lib/stdout_print.rb +12 -4
- 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: 4f7a5efff36a9fd8c54c233cfdc39985b4877a8d
|
4
|
+
data.tar.gz: 5af300736977af50a2feb8959c796706b9f3f227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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,
|
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)
|