ke 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ke/capped_sample.rb +17 -4
- data/lib/ke/indeterminate_task.rb +2 -1
- data/lib/ke/reporters/multi_line_reporter.rb +21 -5
- data/lib/ke/reporters/single_line_reporter.rb +10 -4
- data/lib/ke/version.rb +1 -1
- data/test/ke_test.rb +24 -22
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac5fe567263c2c11146fb81885c01e7d1c7e563b
|
4
|
+
data.tar.gz: 2be98663121456d17d17afadc50589c61d5a54b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f77cf8fe60eb71c672203fcae9ec837f97b0bd62bf8b264a278b4f7152d6e3503ad25822763400ba4e56032482bb35a2e6988e00a63a20e295b9dcbd7b0be79
|
7
|
+
data.tar.gz: a5d860927aa29abec767b81a0d542fcd577966028571714eaf11334ef1ef39f207c163f6234d5b62598d5208e7b9ae978b551dd3c7081a470b08b37b884651a2
|
data/lib/ke/capped_sample.rb
CHANGED
@@ -22,15 +22,28 @@ module Ke
|
|
22
22
|
alias :to_ary :to_a
|
23
23
|
|
24
24
|
def mean
|
25
|
+
array_mean @array
|
26
|
+
end
|
27
|
+
|
28
|
+
def mean_iqr
|
29
|
+
array_sorted = @array.sort
|
30
|
+
array_size = @array.size
|
31
|
+
iqr = array_sorted[(array_size * 0.25).floor..(array_size * 0.75).ceil]
|
32
|
+
array_mean iqr
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
"#<CappedSample: #{@array.inspect}>"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def array_mean(array)
|
25
42
|
if @array.size > 0
|
26
43
|
@array.inject(:+) / @array.size.to_f
|
27
44
|
else
|
28
45
|
0
|
29
46
|
end
|
30
47
|
end
|
31
|
-
|
32
|
-
def to_s
|
33
|
-
"#<CappedSample: #{@array.inspect}>"
|
34
|
-
end
|
35
48
|
end
|
36
49
|
end
|
@@ -7,6 +7,7 @@ module Ke
|
|
7
7
|
@duration_per_tick = 0
|
8
8
|
@duration_per_tick_history = CappedSample.new(100)
|
9
9
|
@mutex = Mutex.new
|
10
|
+
@last_tick_time = nil
|
10
11
|
end
|
11
12
|
|
12
13
|
def start_time
|
@@ -26,7 +27,7 @@ module Ke
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def duration_per_tick
|
29
|
-
@duration_per_tick_history.
|
30
|
+
@duration_per_tick_history.mean_iqr
|
30
31
|
end
|
31
32
|
|
32
33
|
def tick
|
@@ -11,19 +11,35 @@ module Ke
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def print_tick
|
14
|
-
|
14
|
+
@io.puts "#{prefix}#{infix}#{suffix}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_complete
|
18
|
+
@io.puts "Completed #{@label}, #{@task.total_duration} total duration"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def prefix
|
15
24
|
elapsed_time = (@task.elapsed_duration / 60.0).round(2)
|
25
|
+
"Running #{@label}, #{elapsed_time} minutes elapsed"
|
26
|
+
end
|
16
27
|
|
28
|
+
def infix
|
17
29
|
if @task.respond_to?(:estimated_duration_until_complete)
|
18
30
|
estimated_duration_until_complete = (@task.estimated_duration_until_complete / 60.0).round(2)
|
19
|
-
|
31
|
+
", #{estimated_duration_until_complete} minutes remaining"
|
20
32
|
else
|
21
|
-
|
33
|
+
ticks_per_second = (1.0 / @task.duration_per_tick).round(2)
|
34
|
+
", #{ticks_per_second} ticks/second"
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
25
|
-
def
|
26
|
-
|
38
|
+
def suffix
|
39
|
+
if @task.respond_to?(:total_ticks)
|
40
|
+
pct = (@task.tick_count.to_f * 100 / @task.total_ticks).round(2)
|
41
|
+
", #{@task.tick_count}/#{@task.total_ticks} ticks ~ #{pct}% complete"
|
42
|
+
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
end
|
@@ -7,7 +7,7 @@ module Ke
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def print_start
|
10
|
-
@io.print "Starting #{@label}"
|
10
|
+
@io.print "Starting #{@label} ..."
|
11
11
|
end
|
12
12
|
|
13
13
|
def print_tick
|
@@ -16,14 +16,20 @@ module Ke
|
|
16
16
|
|
17
17
|
if @task.respond_to?(:estimated_duration_until_complete)
|
18
18
|
estimated_duration_until_complete = (@task.estimated_duration_until_complete / 60.0).round(2)
|
19
|
-
|
19
|
+
|
20
|
+
if @task.respond_to?(:total_ticks)
|
21
|
+
pct = (@task.tick_count.to_f * 100 / @task.total_ticks).round(2)
|
22
|
+
@io.print " #{elapsed_time}/#{estimated_duration_until_complete} mins, #{@task.tick_count}/#{@task.total_ticks} ticks ~ #{pct}% ..."
|
23
|
+
else
|
24
|
+
@io.print " #{elapsed_time}/#{estimated_duration_until_complete} mins ..."
|
25
|
+
end
|
20
26
|
else
|
21
|
-
@io.print "
|
27
|
+
@io.print " #{elapsed_time} mins, #{ticks_per_second} ticks/sec ..."
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
31
|
def print_complete
|
26
|
-
@io.puts "complete."
|
32
|
+
@io.puts " complete (#{@task.total_duration} total duration)."
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
data/lib/ke/version.rb
CHANGED
data/test/ke_test.rb
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
task
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
[Ke::MultiLineReporter, Ke::SingleLineReporter].each do |reporter_klass|
|
4
|
+
task = Ke::IndeterminateTask.new
|
5
|
+
reporter = reporter_klass.new(task, "indeterminate task")
|
6
|
+
task.start
|
7
|
+
reporter.print_start
|
8
|
+
loop do
|
9
|
+
break if rand(200) == 50
|
10
|
+
sleep 0.05 + (rand / 100.0)
|
11
|
+
task.tick
|
12
|
+
reporter.print_tick if task.tick_count % 10 == 0
|
13
|
+
end
|
14
|
+
task.complete
|
15
|
+
reporter.print_complete
|
15
16
|
|
16
|
-
task = Ke::DeterminateTask.new(total_ticks: 50)
|
17
|
-
reporter =
|
18
|
-
task.start
|
19
|
-
reporter.print_start
|
20
|
-
50.times do
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
task = Ke::DeterminateTask.new(total_ticks: 50)
|
18
|
+
reporter = reporter_klass.new(task, "determinate task")
|
19
|
+
task.start
|
20
|
+
reporter.print_start
|
21
|
+
50.times do
|
22
|
+
sleep 0.05 + (rand / 100.0)
|
23
|
+
task.tick
|
24
|
+
reporter.print_tick if task.tick_count % 10 == 0
|
25
|
+
end
|
26
|
+
task.complete
|
27
|
+
reporter.print_complete
|
24
28
|
end
|
25
|
-
task.complete
|
26
|
-
reporter.print_complete
|
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ke
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Dodwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: Measure progress of Ruby code.
|
@@ -45,8 +45,8 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
-
- .gitignore
|
49
|
-
- .travis.yml
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
50
|
- Gemfile
|
51
51
|
- LICENSE
|
52
52
|
- README.md
|
@@ -73,21 +73,20 @@ require_paths:
|
|
73
73
|
- lib
|
74
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- -
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.4.5.1
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Measure progress of Ruby code.
|
90
90
|
test_files:
|
91
91
|
- test/ke_test.rb
|
92
92
|
- test/test_helper.rb
|
93
|
-
has_rdoc:
|