progressbar 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -76,6 +76,10 @@ The latest version of Ruby/ProgressBar is available at
76
76
  Use :stat_for_file_transfer instead of :stat to display
77
77
  transfered bytes and transfer rate.
78
78
 
79
+ --- ProgressBar#long_running
80
+ Use adaptative running average ton compute ETA, more effective for
81
+ long-running jobs of jobs whose pseed may vary.
82
+
79
83
 
80
84
  ReverseProgressBar class is also available. The
81
85
  functionality is identical to ProgressBar but the direction
@@ -53,6 +53,10 @@ private
53
53
  if @finished_p then elapsed else eta end
54
54
  end
55
55
 
56
+ def fmt_stat_for_long_run
57
+ if @finished_p then elapsed else eta_running_average end
58
+ end
59
+
56
60
  def fmt_stat_for_file_transfer
57
61
  if @finished_p then
58
62
  sprintf("%s %s %s", bytes, transfer_rate, elapsed)
@@ -91,7 +95,7 @@ private
91
95
  sec = t % 60
92
96
  min = (t / 60) % 60
93
97
  hour = t / 3600
94
- sprintf("%02d:%02d:%02d", hour, min, sec);
98
+ sprintf("% 3d:%02d:%02d", hour, min, sec);
95
99
  end
96
100
 
97
101
  # ETA stands for Estimated Time of Arrival.
@@ -101,7 +105,35 @@ private
101
105
  else
102
106
  elapsed = Time.now - @start_time
103
107
  eta = elapsed * @total / @current - elapsed;
104
- sprintf("ETA: %s", format_time(eta))
108
+ sprintf("ETA: %s", format_time(eta))
109
+ end
110
+ end
111
+
112
+ # Compute ETA with running average (better suited to long running tasks)
113
+ def eta_running_average
114
+ now = Time.now
115
+
116
+ # update throughput running average
117
+ if @total > 0 && @eta_previous && @eta_previous_time
118
+ current_elapsed = @current - @eta_previous
119
+ alpha = 0.9 ** current_elapsed
120
+ current_progress = 1.0 * current_elapsed
121
+ current_throughput = current_progress / (now - @eta_previous_time)
122
+ if @eta_throughput
123
+ @eta_throughput = @eta_throughput * alpha + current_throughput * (1-alpha)
124
+ else
125
+ @eta_throughput = current_throughput
126
+ end
127
+ end
128
+
129
+ @eta_previous = @current
130
+ @eta_previous_time = now
131
+
132
+ if @eta_throughput && @eta_throughput > 0
133
+ eta = (@total - @current) / @eta_throughput;
134
+ sprintf("ETA: %s", format_time(eta))
135
+ else
136
+ "ETA: --:--:--"
105
137
  end
106
138
  end
107
139
 
@@ -200,6 +232,10 @@ public
200
232
  @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
201
233
  end
202
234
 
235
+ def long_running
236
+ @format_arguments = [:title, :percentage, :bar, :stat_for_long_run]
237
+ end
238
+
203
239
  def format= (format)
204
240
  @format = format
205
241
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "progressbar"
5
- s.version = "0.9.2"
5
+ s.version = "0.10.0"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Satoru Takabayashi", "Jose Peleteiro"]
8
8
  s.email = ["satoru@0xcc.net", "jose@peleteiro.net"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: progressbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,12 +10,12 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-22 00:00:00.000000000 -02:00
13
+ date: 2012-02-02 00:00:00.000000000 -02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
18
- requirement: &70165027226020 !ruby/object:Gem::Requirement
18
+ requirement: &70119801398300 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: 1.0.0
24
24
  type: :development
25
25
  prerelease: false
26
- version_requirements: *70165027226020
26
+ version_requirements: *70119801398300
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
- requirement: &70165027225560 !ruby/object:Gem::Requirement
29
+ requirement: &70119801397840 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
- version_requirements: *70165027225560
37
+ version_requirements: *70119801397840
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: yard
40
- requirement: &70165027225100 !ruby/object:Gem::Requirement
40
+ requirement: &70119801429620 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ! '>='
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: '0'
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70165027225100
48
+ version_requirements: *70119801429620
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: rake
51
- requirement: &70165027256880 !ruby/object:Gem::Requirement
51
+ requirement: &70119801429160 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ! '>='
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: '0'
57
57
  type: :development
58
58
  prerelease: false
59
- version_requirements: *70165027256880
59
+ version_requirements: *70119801429160
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: simplecov
62
- requirement: &70165027256420 !ruby/object:Gem::Requirement
62
+ requirement: &70119801428700 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ! '>='
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.3.5
68
68
  type: :development
69
69
  prerelease: false
70
- version_requirements: *70165027256420
70
+ version_requirements: *70119801428700
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: bluecloth
73
- requirement: &70165027255960 !ruby/object:Gem::Requirement
73
+ requirement: &70119801428240 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,7 +78,7 @@ dependencies:
78
78
  version: 0.3.5
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *70165027255960
81
+ version_requirements: *70119801428240
82
82
  description: Ruby/ProgressBar is a text progress bar library for Ruby. It can indicate
83
83
  progress with percentage, a progress bar, and estimated remaining time.
84
84
  email:
@@ -95,7 +95,7 @@ files:
95
95
  - Gemfile
96
96
  - Gemfile.lock
97
97
  - LICENSE
98
- - README.rd
98
+ - README.rdoc
99
99
  - Rakefile
100
100
  - lib/progressbar.rb
101
101
  - progressbar.gemspec