tiny_eta 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/tiny_eta.rb +38 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a67e335df4b6df5f98705c220ab51a214af310bffde49feb6685228852c96c80
|
4
|
+
data.tar.gz: 9f05a43486bed958b949ef23cd35358c02fe7a1a29b12a652deed7c4e9ff505b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f7c9ee316300a4618a92133ab728c1266d5a39f06f06bdb880eb905ad4cbec30ac3596d868ac96c019305801758989a992b985f3737015a28b562d7991ca21f
|
7
|
+
data.tar.gz: 923a8cd621bad25c85517c729b84f3bcbeb6272d7970a6b31af20e143c4fdcac812034411fb434e214cef85a87422390193d19cd5ac70cd20c713fdc2d254f99
|
data/lib/tiny_eta.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# this module provides a simple way to get an ETA for a task, given:
|
2
|
+
# - elapsed time, in seconds
|
3
|
+
# - percentage complete (Float in the range of 0.0..1.0)
|
4
|
+
module TinyEta
|
5
|
+
SECONDS_PER_DAY = (60 * 60 * 24)
|
6
|
+
SECONDS_PER_HOUR = (60 * 60)
|
7
|
+
SECONDS_PER_MINUTE = 60
|
8
|
+
|
9
|
+
# returns a string with "DDd HH:MM:SS", where:
|
10
|
+
# - DD is the number of days
|
11
|
+
# - HH is the number of hours
|
12
|
+
# - MM is the number of minutes
|
13
|
+
# - SS is the number of seconds
|
14
|
+
#
|
15
|
+
# NOTE: if ETA is less than a day, then DD will be excluded, whereas HH:MM:SS
|
16
|
+
# will always be shown
|
17
|
+
#
|
18
|
+
# elapsed: the number of seconds elapsed (Integer or Float)
|
19
|
+
# percent_complete: 0.0..1.0 - the percent completion (Float)
|
20
|
+
def self.eta(elapsed, percent_complete)
|
21
|
+
percent_remaining = (1.0 - percent_complete)
|
22
|
+
remaining_time = ((elapsed / percent_complete) * percent_remaining).round
|
23
|
+
puts remaining_time
|
24
|
+
|
25
|
+
days = (remaining_time / SECONDS_PER_DAY.to_f).to_i
|
26
|
+
remaining_time -= days * SECONDS_PER_DAY
|
27
|
+
|
28
|
+
hours = (remaining_time / SECONDS_PER_HOUR.to_f).to_i
|
29
|
+
remaining_time -= hours * SECONDS_PER_HOUR
|
30
|
+
|
31
|
+
minutes = (remaining_time / SECONDS_PER_MINUTE.to_f).to_i
|
32
|
+
remaining_time -= minutes * SECONDS_PER_MINUTE
|
33
|
+
|
34
|
+
seconds = remaining_time
|
35
|
+
|
36
|
+
"#{days > 0 ? "#{days}d " : ''}#{hours.to_s.rjust(2, '0')}:#{minutes.to_s.rjust(2, '0')}:#{seconds.to_s.rjust(2, '0')}"
|
37
|
+
end
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tiny_eta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff Lunt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a quick way to get a human-friendly ETA for a task
|
14
|
+
email: jefflunt@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/tiny_eta.rb
|
20
|
+
homepage: https://github.com/jefflunt/tiny_eta
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.4.1
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: want to know approximately how long something will take to complete, and
|
43
|
+
nothing else? then this library is for you
|
44
|
+
test_files: []
|