remain_timer 0.1.0
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/.prettierrc +3 -0
- data/.rubocop.yml +17 -0
- data/.rubocop_airbnb.yml +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +14 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/remain_timer.rb +86 -0
- data/lib/remain_timer/version.rb +3 -0
- data/remain_timer.gemspec +27 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7e885186ec61a3639b97081e6aba086912b09259bdc78d700126736eb810f57f
|
|
4
|
+
data.tar.gz: 3f448dfbf3f199a5469d39bec354073f215414b8e68fe0bee7b7cc689b21d8fb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: af16182e3b6b625b1f09ca19ab73a7ecdf13104ed42d93e8aac427dd6ea1358909bc1ddb870b2cb24575674fb209eea9ee9d6fdb8b84b93b4e4a1b36f88018e0
|
|
7
|
+
data.tar.gz: 92cd591491ffcf66746afcc64cf28eb2251a6fbce4f94ab9aa3b23f01e6ee89352ba2b6f4a2bf90ae4b0ec1cfb2825c3876851cbe871214538c3ac00c50560cb
|
data/.gitignore
ADDED
data/.prettierrc
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
inherit_from:
|
|
2
|
+
- .rubocop_airbnb.yml
|
|
3
|
+
# prettier
|
|
4
|
+
Style/PercentLiteralDelimiters:
|
|
5
|
+
Description: Use `%`-literal delimiters consistently
|
|
6
|
+
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-literal-braces
|
|
7
|
+
Enabled: false
|
|
8
|
+
PreferredDelimiters:
|
|
9
|
+
! '%': ()
|
|
10
|
+
! '%i': ()
|
|
11
|
+
! '%q': ()
|
|
12
|
+
! '%Q': ()
|
|
13
|
+
! '%r': ! '{}'
|
|
14
|
+
! '%s': ()
|
|
15
|
+
! '%w': ()
|
|
16
|
+
! '%W': ()
|
|
17
|
+
! '%x': ()
|
data/.rubocop_airbnb.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in remain_timer.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
|
|
6
|
+
gem "rake", ">= 12.0"
|
|
7
|
+
gem "yard", ">= 0.9"
|
|
8
|
+
gem "minitest", "~> 5.0"
|
|
9
|
+
gem "minitest-power_assert", "~> 0.3"
|
|
10
|
+
gem "rubocop", "~> 0.76"
|
|
11
|
+
gem "rubocop-airbnb", "~> 3"
|
|
12
|
+
gem "prettier", ">= 0.19"
|
|
13
|
+
gem "rubocop-config-prettier", "~> 0.1"
|
|
14
|
+
gem "simplecov"
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2020 Narazaka
|
|
2
|
+
|
|
3
|
+
This software is provided 'as-is', without any express or implied
|
|
4
|
+
warranty. In no event will the authors be held liable for any damages
|
|
5
|
+
arising from the use of this software.
|
|
6
|
+
|
|
7
|
+
Permission is granted to anyone to use this software for any purpose,
|
|
8
|
+
including commercial applications, and to alter it and redistribute it
|
|
9
|
+
freely, subject to the following restrictions:
|
|
10
|
+
|
|
11
|
+
1. The origin of this software must not be misrepresented; you must not
|
|
12
|
+
claim that you wrote the original software. If you use this software
|
|
13
|
+
in a product, an acknowledgment in the product documentation would be
|
|
14
|
+
appreciated but is not required.
|
|
15
|
+
|
|
16
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
|
17
|
+
misrepresented as being the original software.
|
|
18
|
+
|
|
19
|
+
3. This notice may not be removed or altered from any source
|
|
20
|
+
distribution.
|
data/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# RemainTimer
|
|
2
|
+
|
|
3
|
+
A small tool for estimating and displaying the remaining time of batch jobs/tasks
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'remain_timer'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install remain_timer
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
remain_timer = RemainTimer.new
|
|
25
|
+
remain_timer.all_count = all_users.count
|
|
26
|
+
remain_timer.start
|
|
27
|
+
|
|
28
|
+
all_users.find_in_batches do |users|
|
|
29
|
+
remain_timer.remain_time.puts(prefix: "[fetching users]")
|
|
30
|
+
# [fetching users] past: 20:34 / remain: 55:33 / all: 1:16:07 || past: 24000 / remain: 12000 / all: 36000
|
|
31
|
+
... # main process
|
|
32
|
+
remain_timer.progress(users.size)
|
|
33
|
+
end
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Development
|
|
37
|
+
|
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
39
|
+
|
|
40
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
41
|
+
|
|
42
|
+
## Contributing
|
|
43
|
+
|
|
44
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remain_timer.
|
|
45
|
+
|
data/Rakefile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rake/testtask"
|
|
3
|
+
require "yard"
|
|
4
|
+
require "yard/rake/yardoc_task"
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << "test"
|
|
8
|
+
t.libs << "lib"
|
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
YARD::Rake::YardocTask.new
|
|
13
|
+
|
|
14
|
+
task :default => :test
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "remain_timer"
|
|
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
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/remain_timer.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
require "remain_timer/version"
|
|
2
|
+
require "chronic_duration"
|
|
3
|
+
|
|
4
|
+
class RemainTimer
|
|
5
|
+
attr_accessor :all_count, :estimate_laptime_size, :duration_format
|
|
6
|
+
|
|
7
|
+
def initialize(estimate_laptime_size: 20, duration_format: :chrono)
|
|
8
|
+
@laptimes = []
|
|
9
|
+
@estimate_laptime_size = estimate_laptime_size
|
|
10
|
+
@duration_format = duration_format
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def start(count = 0, time = now)
|
|
14
|
+
@laptimes << LapTime.new(count, time)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def progress(count, time = now)
|
|
18
|
+
@laptimes << LapTime.new(@laptimes.last.past_count + count, time)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def remain_time
|
|
22
|
+
laptimes = @estimate_laptime_size ? @laptimes.last(@estimate_laptime_size) : @laptimes
|
|
23
|
+
first_laptime = laptimes.first
|
|
24
|
+
last_laptime = laptimes.last
|
|
25
|
+
past_count = last_laptime.past_count
|
|
26
|
+
past_duration = last_laptime.time - @laptimes.first.time
|
|
27
|
+
period_past_count = last_laptime.past_count - first_laptime.past_count
|
|
28
|
+
period_past_duration = last_laptime.time - first_laptime.time
|
|
29
|
+
if all_count
|
|
30
|
+
remain_count = all_count - past_count
|
|
31
|
+
if period_past_count > 0
|
|
32
|
+
remain_duration = period_past_duration / period_past_count * remain_count
|
|
33
|
+
all_duration = past_duration + remain_duration
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
RemainTime.new(
|
|
37
|
+
all_duration: all_duration,
|
|
38
|
+
past_duration: past_duration,
|
|
39
|
+
remain_duration: remain_duration,
|
|
40
|
+
all_count: all_count,
|
|
41
|
+
past_count: past_count,
|
|
42
|
+
remain_count: remain_count,
|
|
43
|
+
duration_format: duration_format,
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
private
|
|
48
|
+
|
|
49
|
+
def now
|
|
50
|
+
(@use_current ||= Time.respond_to?(:current)) ? Time.current : Time.now
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
LapTime = Struct.new(:past_count, :time)
|
|
54
|
+
|
|
55
|
+
RemainTime =
|
|
56
|
+
Struct.new(
|
|
57
|
+
:all_duration,
|
|
58
|
+
:past_duration,
|
|
59
|
+
:remain_duration,
|
|
60
|
+
:all_count,
|
|
61
|
+
:past_count,
|
|
62
|
+
:remain_count,
|
|
63
|
+
:duration_format,
|
|
64
|
+
keyword_init: true,
|
|
65
|
+
) do
|
|
66
|
+
def to_s
|
|
67
|
+
"past: #{dfmt past_duration} / remain: #{dfmt remain_duration} / all: #{
|
|
68
|
+
dfmt all_duration
|
|
69
|
+
} || past: #{past_count} / remain: #{remain_count || "?"} / all: #{all_count || "?"}"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def puts(prefix: nil, postfix: nil)
|
|
73
|
+
Kernel.puts [prefix, to_s, postfix].compact.join(" ")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def print(prefix: nil, postfix: nil)
|
|
77
|
+
Kernel.print [prefix, to_s, postfix].compact.join(" ")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
private
|
|
81
|
+
|
|
82
|
+
def dfmt(duration)
|
|
83
|
+
duration.nil? ? "?" : ChronicDuration.output(duration, format: duration_format)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative 'lib/remain_timer/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "remain_timer"
|
|
5
|
+
spec.version = RemainTimer::VERSION
|
|
6
|
+
spec.licenses = ["Zlib"]
|
|
7
|
+
spec.authors = ["Narazaka"]
|
|
8
|
+
spec.email = ["info@narazaka.net"]
|
|
9
|
+
|
|
10
|
+
spec.summary = "A small tool for estimating and displaying the remaining time of batch jobs/tasks"
|
|
11
|
+
spec.homepage = "https://github.com/Narazaka/remain_timer"
|
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
13
|
+
|
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
15
|
+
spec.metadata["source_code_uri"] = "https://github.com/Narazaka/remain_timer"
|
|
16
|
+
|
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = "exe"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.add_dependency "chronic_duration", "~> 0.10"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: remain_timer
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Narazaka
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-07-14 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: chronic_duration
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.10'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.10'
|
|
27
|
+
description:
|
|
28
|
+
email:
|
|
29
|
+
- info@narazaka.net
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- ".prettierrc"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- ".rubocop_airbnb.yml"
|
|
38
|
+
- ".travis.yml"
|
|
39
|
+
- Gemfile
|
|
40
|
+
- LICENSE
|
|
41
|
+
- README.md
|
|
42
|
+
- Rakefile
|
|
43
|
+
- bin/console
|
|
44
|
+
- bin/setup
|
|
45
|
+
- lib/remain_timer.rb
|
|
46
|
+
- lib/remain_timer/version.rb
|
|
47
|
+
- remain_timer.gemspec
|
|
48
|
+
homepage: https://github.com/Narazaka/remain_timer
|
|
49
|
+
licenses:
|
|
50
|
+
- Zlib
|
|
51
|
+
metadata:
|
|
52
|
+
homepage_uri: https://github.com/Narazaka/remain_timer
|
|
53
|
+
source_code_uri: https://github.com/Narazaka/remain_timer
|
|
54
|
+
post_install_message:
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 2.3.0
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubygems_version: 3.0.3
|
|
70
|
+
signing_key:
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: A small tool for estimating and displaying the remaining time of batch jobs/tasks
|
|
73
|
+
test_files: []
|