duration_estimate 0.0.1
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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.rubocop-my.yml +2 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +18 -0
- data/.yardopts +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +13 -0
- data/bin/console +10 -0
- data/bin/setup +7 -0
- data/duration_estimate.gemspec +36 -0
- data/lib/duration_estimate/null_time.rb +11 -0
- data/lib/duration_estimate/sized_queue.rb +43 -0
- data/lib/duration_estimate/terminal_formatter.rb +59 -0
- data/lib/duration_estimate/version.rb +53 -0
- data/lib/duration_estimate.rb +169 -0
- metadata +162 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa1e5e72f8be0aeda87a2fca48d6bd5a7017bf53
|
4
|
+
data.tar.gz: 8030719f419e5d5287bac608cd5e21eb3a089c98
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6a65ccdc2835b58eabf6708e5319e20565b1f673fec740383594d61aad4fed6c5e3252d30a5155ecd5169bdc381a44ea1c2368d08c5f7f47cb31505fd69b51a
|
7
|
+
data.tar.gz: 889189139a5e5d690b508e4af4df06dcfb965861aad1c75f484febf46331b76e3a949184cc5a084d82e8ee677da62eaabf883aca69ddd06c05f512eddff6190a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop-my.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop-my.yml
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Oldrich Vetesnik
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# DurationEstimate
|
2
|
+
|
3
|
+
Do something to a collection of items and see how long it is going to take.
|
4
|
+
Useful for long-running Rake tasks.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
items = 0..10000 # Some data set.
|
10
|
+
|
11
|
+
DurationEstimate.each(items) do |item, e|
|
12
|
+
print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
13
|
+
|
14
|
+
# Do something time consuming with item.
|
15
|
+
sleep 0.001
|
16
|
+
end
|
17
|
+
|
18
|
+
puts
|
19
|
+
```
|
20
|
+
|
21
|
+
You can specify the collection size if you are using some kind of ORM that
|
22
|
+
does not respond to `:size` method.
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
media = Media
|
26
|
+
.where { created_at > Time.parse('some time') }
|
27
|
+
.order(:created_at)
|
28
|
+
|
29
|
+
File.open('missing-media.log', 'w') do |log|
|
30
|
+
DurationEstimate.each(media, size: media.count) do |medium, e|
|
31
|
+
print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
32
|
+
|
33
|
+
unless medium.on_s3?
|
34
|
+
log.puts medium.id
|
35
|
+
log.fsync # Write changes now, be able tail the file.
|
36
|
+
end
|
37
|
+
|
38
|
+
sleep 2 # Don't overload AWS S3
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
puts
|
43
|
+
```
|
44
|
+
|
45
|
+
This is going to re-print a line with something like this:
|
46
|
+
|
47
|
+
1/11 ( 9.09 %) -, -
|
48
|
+
2/11 ( 18.18 %) 11:47:29, 00:00:34
|
49
|
+
3/11 ( 27.27 %) 11:47:30, 00:00:31
|
50
|
+
4/11 ( 36.36 %) 11:47:31, 00:00:27
|
51
|
+
5/11 ( 45.45 %) 11:47:31, 00:00:23
|
52
|
+
6/11 ( 54.55 %) 11:47:30, 00:00:19
|
53
|
+
7/11 ( 63.64 %) 11:47:30, 00:00:15
|
54
|
+
8/11 ( 72.73 %) 11:47:30, 00:00:11
|
55
|
+
9/11 ( 81.82 %) 11:47:30, 00:00:07
|
56
|
+
10/11 ( 90.91 %) 11:47:30, 00:00:03
|
57
|
+
11/11 (100.00 %) 11:47:30, 00:00:00
|
58
|
+
|
59
|
+
## Installation
|
60
|
+
|
61
|
+
Add this line to your application's Gemfile:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
gem 'duration_estimate'
|
65
|
+
```
|
66
|
+
|
67
|
+
And then execute:
|
68
|
+
|
69
|
+
$ bundle
|
70
|
+
|
71
|
+
Or install it yourself as:
|
72
|
+
|
73
|
+
$ gem install duration_estimate
|
74
|
+
|
75
|
+
## Development
|
76
|
+
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
78
|
+
|
79
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
1. Fork it (https://github.com/ollie/duration_estimate/fork)
|
84
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
85
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
86
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
87
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
task default: :combo
|
2
|
+
|
3
|
+
desc 'Run tests, rubocop and generate documentation'
|
4
|
+
task :combo do
|
5
|
+
sh 'bundle exec rspec'
|
6
|
+
sh('bundle exec rubocop') {} # ignore status > 0
|
7
|
+
sh 'bundle exec yardoc'
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Same as :combo but build a gem, too'
|
11
|
+
task mega_combo: :combo do
|
12
|
+
sh 'gem build duration_estimate.gemspec'
|
13
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'duration_estimate'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
require 'pry'
|
10
|
+
Pry.start
|
data/bin/setup
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'duration_estimate/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'duration_estimate'
|
8
|
+
spec.version = DurationEstimate::VERSION
|
9
|
+
spec.authors = ['Oldrich Vetesnik']
|
10
|
+
spec.email = ['oldrich.vetesnik@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'Do something to a collection of items and see how ' \
|
13
|
+
'long it is going to take. Useful for long-running ' \
|
14
|
+
'Rake tasks.'
|
15
|
+
spec.homepage = 'https://github.com/ollie/duration_estimate'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# rubocop:disable Metrics/LineLength
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
# System
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.9'
|
26
|
+
|
27
|
+
# Test
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
29
|
+
spec.add_development_dependency 'simplecov', '~> 0.10'
|
30
|
+
|
31
|
+
# Code style, debugging, docs
|
32
|
+
spec.add_development_dependency 'rubocop', '~> 0.31'
|
33
|
+
spec.add_development_dependency 'pry', '~> 0.10'
|
34
|
+
spec.add_development_dependency 'yard', '~> 0.8'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.4'
|
36
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class DurationEstimate
|
2
|
+
# Queue (array) that can hold +max_size+ items at most.
|
3
|
+
class SizedQueue
|
4
|
+
# Collection of items.
|
5
|
+
#
|
6
|
+
# @return [Array]
|
7
|
+
attr_accessor :items
|
8
|
+
|
9
|
+
# Maximum number the collection will hold.
|
10
|
+
#
|
11
|
+
# @return [Fixnum]
|
12
|
+
attr_accessor :max_size
|
13
|
+
|
14
|
+
# Setup.
|
15
|
+
#
|
16
|
+
# @param max_size [Fixnum] What is the maximum size?
|
17
|
+
def initialize(max_size)
|
18
|
+
self.max_size = max_size
|
19
|
+
self.items = []
|
20
|
+
end
|
21
|
+
|
22
|
+
# Add an item into the collection.
|
23
|
+
#
|
24
|
+
# @param item [Object] Item to add.
|
25
|
+
#
|
26
|
+
# @return [SizedQueue] Self.
|
27
|
+
def <<(item)
|
28
|
+
items << item
|
29
|
+
items.shift if items.size > max_size
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# Calculate mean (average). It is assumed that the objects in collection
|
34
|
+
# respond to +:++ method.
|
35
|
+
#
|
36
|
+
# @return [Numeric, nil]
|
37
|
+
def average
|
38
|
+
size = items.size
|
39
|
+
return if size.zero?
|
40
|
+
items.reduce(:+) / size
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class DurationEstimate
|
2
|
+
# Format a status line for terminal.
|
3
|
+
class TerminalFormatter
|
4
|
+
# Reference to the estimate instance.
|
5
|
+
#
|
6
|
+
# @return [DurationEstimate]
|
7
|
+
attr_accessor :estimate
|
8
|
+
|
9
|
+
# Format a status line for terminal.
|
10
|
+
#
|
11
|
+
# @return [String]
|
12
|
+
def self.format(estimate)
|
13
|
+
new(estimate).format
|
14
|
+
end
|
15
|
+
|
16
|
+
# Format a status line for terminal.
|
17
|
+
#
|
18
|
+
# @param estimate [DurationEstimate] Reference to the estimate instance.
|
19
|
+
def initialize(estimate)
|
20
|
+
self.estimate = estimate
|
21
|
+
end
|
22
|
+
|
23
|
+
# Format estimate as a string.
|
24
|
+
# Prevent trailing junk characters by setting fixed widths for things.
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
def format
|
28
|
+
[
|
29
|
+
"#{ items_done }/#{ estimate.items_size }",
|
30
|
+
"(#{ percentage } %)",
|
31
|
+
"#{ estimate.ends_at.strftime('%H:%M:%S') },",
|
32
|
+
"#{ estimate.time_remaining }"
|
33
|
+
].join(' ')
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# Align the items_done number to the right.
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
def items_done
|
42
|
+
estimate.items_done.to_s.rjust(items_size_digits)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Number of digits for the items_size number.
|
46
|
+
#
|
47
|
+
# @return [Fixnum]
|
48
|
+
def items_size_digits
|
49
|
+
estimate.items_size.to_s.size
|
50
|
+
end
|
51
|
+
|
52
|
+
# Format percentage number.
|
53
|
+
#
|
54
|
+
# @return [String]
|
55
|
+
def percentage
|
56
|
+
Kernel.format('%6.02f', estimate.percentage)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Do something to a collection of items and see how long it is going to take.
|
2
|
+
# Useful for long-running Rake tasks.
|
3
|
+
#
|
4
|
+
# items = 0..10000 # Some data set.
|
5
|
+
#
|
6
|
+
# DurationEstimate.each(items) do |item, e|
|
7
|
+
# print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
8
|
+
#
|
9
|
+
# # Do something time consuming with item.
|
10
|
+
# sleep 0.001
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# puts
|
14
|
+
#
|
15
|
+
# You can specify the collection size if you are using some kind of ORM that
|
16
|
+
# does not respond to `:size` method.
|
17
|
+
#
|
18
|
+
# media = Media
|
19
|
+
# .where { created_at > Time.parse('some time') }
|
20
|
+
# .order(:created_at)
|
21
|
+
#
|
22
|
+
# File.open('missing-media.log', 'w') do |log|
|
23
|
+
# DurationEstimate.each(media, size: media.count) do |medium, e|
|
24
|
+
# print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
25
|
+
#
|
26
|
+
# unless medium.on_s3?
|
27
|
+
# log.puts medium.id
|
28
|
+
# log.fsync # Write changes now, be able tail the file.
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# sleep 2 # Don't overload AWS S3
|
32
|
+
# end
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# puts
|
36
|
+
#
|
37
|
+
# This is going to re-print a line with something like this:
|
38
|
+
#
|
39
|
+
# 1/11 ( 9.09 %) -, -
|
40
|
+
# 2/11 ( 18.18 %) 11:47:29, 00:00:34
|
41
|
+
# 3/11 ( 27.27 %) 11:47:30, 00:00:31
|
42
|
+
# 4/11 ( 36.36 %) 11:47:31, 00:00:27
|
43
|
+
# 5/11 ( 45.45 %) 11:47:31, 00:00:23
|
44
|
+
# 6/11 ( 54.55 %) 11:47:30, 00:00:19
|
45
|
+
# 7/11 ( 63.64 %) 11:47:30, 00:00:15
|
46
|
+
# 8/11 ( 72.73 %) 11:47:30, 00:00:11
|
47
|
+
# 9/11 ( 81.82 %) 11:47:30, 00:00:07
|
48
|
+
# 10/11 ( 90.91 %) 11:47:30, 00:00:03
|
49
|
+
# 11/11 (100.00 %) 11:47:30, 00:00:00
|
50
|
+
class DurationEstimate
|
51
|
+
# Version, man!
|
52
|
+
VERSION = '0.0.1'
|
53
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'benchmark'
|
2
|
+
|
3
|
+
require 'duration_estimate/version'
|
4
|
+
require 'duration_estimate/sized_queue'
|
5
|
+
require 'duration_estimate/null_time'
|
6
|
+
require 'duration_estimate/terminal_formatter'
|
7
|
+
|
8
|
+
# Do something to a collection of items and see how long it is going to take.
|
9
|
+
# Useful for long-running Rake tasks.
|
10
|
+
#
|
11
|
+
# items = 0..10000 # Some data set.
|
12
|
+
#
|
13
|
+
# DurationEstimate.each(items) do |item, e|
|
14
|
+
# print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
15
|
+
#
|
16
|
+
# # Do something time consuming with item.
|
17
|
+
# sleep 0.001
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# puts
|
21
|
+
#
|
22
|
+
# You can specify the collection size if you are using some kind of ORM that
|
23
|
+
# does not respond to `:size` method.
|
24
|
+
#
|
25
|
+
# media = Media
|
26
|
+
# .where { created_at > Time.parse('some time') }
|
27
|
+
# .order(:created_at)
|
28
|
+
#
|
29
|
+
# File.open('missing-media.log', 'w') do |log|
|
30
|
+
# DurationEstimate.each(media, size: media.count) do |medium, e|
|
31
|
+
# print "\r#{ DurationEstimate::TerminalFormatter.format(e) }"
|
32
|
+
#
|
33
|
+
# unless medium.on_s3?
|
34
|
+
# log.puts medium.id
|
35
|
+
# log.fsync # Write changes now, be able tail the file.
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# sleep 2 # Don't overload AWS S3
|
39
|
+
# end
|
40
|
+
# end
|
41
|
+
#
|
42
|
+
# puts
|
43
|
+
#
|
44
|
+
# This is going to re-print a line with something like this:
|
45
|
+
#
|
46
|
+
# 1/11 ( 9.09 %) -, -
|
47
|
+
# 2/11 ( 18.18 %) 11:47:29, 00:00:34
|
48
|
+
# 3/11 ( 27.27 %) 11:47:30, 00:00:31
|
49
|
+
# 4/11 ( 36.36 %) 11:47:31, 00:00:27
|
50
|
+
# 5/11 ( 45.45 %) 11:47:31, 00:00:23
|
51
|
+
# 6/11 ( 54.55 %) 11:47:30, 00:00:19
|
52
|
+
# 7/11 ( 63.64 %) 11:47:30, 00:00:15
|
53
|
+
# 8/11 ( 72.73 %) 11:47:30, 00:00:11
|
54
|
+
# 9/11 ( 81.82 %) 11:47:30, 00:00:07
|
55
|
+
# 10/11 ( 90.91 %) 11:47:30, 00:00:03
|
56
|
+
# 11/11 (100.00 %) 11:47:30, 00:00:00
|
57
|
+
class DurationEstimate
|
58
|
+
# Some collection to run through.
|
59
|
+
#
|
60
|
+
# @return [Enumerable]
|
61
|
+
attr_accessor :items
|
62
|
+
|
63
|
+
# Number of items.
|
64
|
+
#
|
65
|
+
# @return [Fixnum]
|
66
|
+
attr_accessor :items_size
|
67
|
+
|
68
|
+
# Number of items done.
|
69
|
+
#
|
70
|
+
# @return [Fixnum]
|
71
|
+
attr_accessor :items_done
|
72
|
+
|
73
|
+
# Number of items remaining.
|
74
|
+
#
|
75
|
+
# @return [Fixnum]
|
76
|
+
attr_accessor :items_remaining
|
77
|
+
|
78
|
+
# Hold operation times.
|
79
|
+
#
|
80
|
+
# @return [SizedQueue]
|
81
|
+
attr_accessor :times
|
82
|
+
|
83
|
+
# Iterate through collection, measure how long it took, yield the item
|
84
|
+
# as well as self to use helper methods.
|
85
|
+
#
|
86
|
+
# @yieldparam item [Object] Current item in collection.
|
87
|
+
# @yieldparam e [DurationEstimate] This instance.
|
88
|
+
def self.each(*args, &block)
|
89
|
+
new(*args).each(&block)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Setup.
|
93
|
+
#
|
94
|
+
# @param items [Enumerable] Some collection to run through.
|
95
|
+
# @param options [Hash]
|
96
|
+
# @option options :size [Fixnum] Total number of items.
|
97
|
+
def initialize(items, options = {})
|
98
|
+
self.items = items
|
99
|
+
self.items_size = options[:size] || items.size
|
100
|
+
self.items_done = 0
|
101
|
+
self.items_remaining = items_size
|
102
|
+
self.times = SizedQueue.new(5)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Iterate through collection, measure how long it took, yield the item
|
106
|
+
# as well as self to use helper methods.
|
107
|
+
#
|
108
|
+
# @yieldparam item [Object] Current item in collection.
|
109
|
+
# @yieldparam e [DurationEstimate] This instance.
|
110
|
+
def each
|
111
|
+
items.each do |item|
|
112
|
+
measure do
|
113
|
+
self.items_done += 1 # rubocop:disable Style/SpaceAroundOperators
|
114
|
+
self.items_remaining -= 1
|
115
|
+
|
116
|
+
yield item, self
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Calculate end time when all will be done.
|
122
|
+
#
|
123
|
+
# @return [Time, NullTime]
|
124
|
+
def ends_at
|
125
|
+
seconds = seconds_left
|
126
|
+
return NullTime.new unless seconds
|
127
|
+
Time.now + seconds
|
128
|
+
end
|
129
|
+
|
130
|
+
# Calculate future time when all will be well and done.
|
131
|
+
#
|
132
|
+
# @return [String]
|
133
|
+
def time_remaining
|
134
|
+
seconds = seconds_left
|
135
|
+
return '-' unless seconds
|
136
|
+
|
137
|
+
minutes, seconds = seconds.divmod(60)
|
138
|
+
hours, minutes = minutes.divmod(60)
|
139
|
+
|
140
|
+
[
|
141
|
+
"#{ format('%02d', hours) }",
|
142
|
+
"#{ format('%02d', minutes) }",
|
143
|
+
"#{ format('%02d', seconds) }"
|
144
|
+
].compact.join(':')
|
145
|
+
end
|
146
|
+
|
147
|
+
# Calculates percentage of done items.
|
148
|
+
#
|
149
|
+
# @return [Float]
|
150
|
+
def percentage
|
151
|
+
items_done.to_f / items_size * 100
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
# Calculate how many seconds are left until the end.
|
157
|
+
#
|
158
|
+
# @return [Numeric, nil]
|
159
|
+
def seconds_left
|
160
|
+
average = times.average
|
161
|
+
return unless average
|
162
|
+
items_remaining * average
|
163
|
+
end
|
164
|
+
|
165
|
+
# Do some operation and record how long it took.
|
166
|
+
def measure
|
167
|
+
times << Benchmark.realtime { yield }
|
168
|
+
end
|
169
|
+
end
|
metadata
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: duration_estimate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oldrich Vetesnik
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simplecov
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.31'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.31'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.4'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- oldrich.vetesnik@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rspec"
|
120
|
+
- ".rubocop-my.yml"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".travis.yml"
|
123
|
+
- ".yardopts"
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- duration_estimate.gemspec
|
131
|
+
- lib/duration_estimate.rb
|
132
|
+
- lib/duration_estimate/null_time.rb
|
133
|
+
- lib/duration_estimate/sized_queue.rb
|
134
|
+
- lib/duration_estimate/terminal_formatter.rb
|
135
|
+
- lib/duration_estimate/version.rb
|
136
|
+
homepage: https://github.com/ollie/duration_estimate
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.4.6
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Do something to a collection of items and see how long it is going to take.
|
160
|
+
Useful for long-running Rake tasks.
|
161
|
+
test_files: []
|
162
|
+
has_rdoc:
|