jtl 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jtl.rb +1 -0
- data/lib/jtl/core_ext/enumerable.rb +34 -0
- data/lib/jtl/version.rb +1 -1
- data/spec/jtl_spec.rb +17 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b30d3cc2a4b0c7d80c8841e9891c626210e9b20c
|
4
|
+
data.tar.gz: 56862bed1eecfb670735155e8bcf4eeff3cbc343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372abdaf0f91b7e226d625b4bfb196827ee618eb73056c0e6c686ae4b977988022ce38ae33819cc33e9451fe446e87ab58c363d0703f2a0bf72bba97b1707a29
|
7
|
+
data.tar.gz: 9e8ed41c5fe78fbc5565d0cd3086e2f6100f573e037ca4a979dbdf1abb5e57ff691eac0674befd47c6248bfa9d2c5aaa359ae3d2807bf3d9f434bb811e23f6c3
|
data/lib/jtl.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'simple_stats/core_ext/enumerable'
|
2
|
+
|
3
|
+
module Enumerable
|
4
|
+
alias frequencies_orig frequencies
|
5
|
+
|
6
|
+
def frequencies(interval = nil, &block)
|
7
|
+
if interval
|
8
|
+
fs0 = self.map {|i| i - i % interval }.frequencies(&block)
|
9
|
+
fs = {}
|
10
|
+
|
11
|
+
(fs0.keys.min..fs0.keys.max).step(interval).each do |n|
|
12
|
+
fs[n] = fs0[n] || 0
|
13
|
+
end
|
14
|
+
|
15
|
+
fs
|
16
|
+
else
|
17
|
+
frequencies_orig(&block)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_gruff_labels
|
22
|
+
labels = {}
|
23
|
+
|
24
|
+
self.each_with_index do |label, i|
|
25
|
+
labels[i] = label
|
26
|
+
end
|
27
|
+
|
28
|
+
if block_given?
|
29
|
+
labels = Hash[*labels.select {|k, v| yield(k, v) }.flatten]
|
30
|
+
end
|
31
|
+
|
32
|
+
Hash[*labels.map {|k, v| [k, v.to_s] }.flatten]
|
33
|
+
end
|
34
|
+
end
|
data/lib/jtl/version.rb
CHANGED
data/spec/jtl_spec.rb
CHANGED
@@ -188,4 +188,21 @@ describe Jtl do
|
|
188
188
|
expect(v.all? {|ts, vs| ts.kind_of?(Time) and vs.kind_of?(Numeric) }).to be_true
|
189
189
|
end
|
190
190
|
end
|
191
|
+
|
192
|
+
it 'frequencies' do
|
193
|
+
jtl = Jtl.new(jtl_path).flatten
|
194
|
+
expect(jtl.elapseds.frequencies {|i| i - i % 10 }).to eq({140=>4, 150=>612, 160=>1601, 170=>713, 180=>271, 190=>105, 200=>33, 210=>15, 220=>17, 230=>6, 240=>1, 250=>1, 270=>1, 290=>1, 300=>1, 310=>7, 320=>3, 330=>2, 350=>1, 380=>1, 410=>1, 420=>2, 450=>1})
|
195
|
+
expect(jtl.elapseds.frequencies(10)).to eq({140=>4, 150=>612, 160=>1601, 170=>713, 180=>271, 190=>105, 200=>33, 210=>15, 220=>17, 230=>6, 240=>1, 250=>1, 260=>0, 270=>1, 280=>0, 290=>1, 300=>1, 310=>7, 320=>3, 330=>2, 340=>0, 350=>1, 360=>0, 370=>0, 380=>1, 390=>0, 400=>0, 410=>1, 420=>2, 430=>0, 440=>0, 450=>1})
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'to_gruff_labels' do
|
199
|
+
jtl = Jtl.new(jtl_path).flatten
|
200
|
+
expect(jtl.elapseds.frequencies(10).keys.to_gruff_labels).to eq({0=>"140", 1=>"150", 2=>"160", 3=>"170", 4=>"180", 5=>"190", 6=>"200", 7=>"210", 8=>"220", 9=>"230", 10=>"240", 11=>"250", 12=>"260", 13=>"270", 14=>"280", 15=>"290", 16=>"300", 17=>"310", 18=>"320", 19=>"330", 20=>"340", 21=>"350", 22=>"360", 23=>"370", 24=>"380", 25=>"390", 26=>"400", 27=>"410", 28=>"420", 29=>"430", 30=>"440", 31=>"450"})
|
201
|
+
end
|
202
|
+
it 'to_gruff_labels (pass block)' do
|
203
|
+
jtl = Jtl.new(jtl_path).flatten
|
204
|
+
labels = jtl.elapseds.frequencies(10).keys.to_gruff_labels {|k, v| (v % 100).zero? }
|
205
|
+
expect(labels).to eq({6=>"200", 16=>"300", 26=>"400"})
|
206
|
+
end
|
207
|
+
|
191
208
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jtl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- Rakefile
|
96
96
|
- jtl.gemspec
|
97
97
|
- lib/jtl.rb
|
98
|
+
- lib/jtl/core_ext/enumerable.rb
|
98
99
|
- lib/jtl/data_set.rb
|
99
100
|
- lib/jtl/jtl.rb
|
100
101
|
- lib/jtl/labeled_value.rb
|