~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/progress.py

  • Committer: Robert Collins
  • Date: 2005-10-19 10:11:57 UTC
  • mfrom: (1185.16.78)
  • mto: This revision was merged to the branch mainline in revision 1470.
  • Revision ID: robertc@robertcollins.net-20051019101157-17438d311e746b4f
mergeĀ fromĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
import sys
40
40
import time
41
41
import os
 
42
from collections import deque
42
43
 
43
44
 
44
45
def _width():
166
167
        self.width = _width()
167
168
        self.start_time = None
168
169
        self.last_update = None
 
170
        self.last_updates = deque()
169
171
    
170
172
 
171
173
    def throttle(self):
179
181
            if interval > 0 and interval < self.MIN_PAUSE:
180
182
                return True
181
183
 
 
184
        self.last_updates.append(now - self.last_update)
182
185
        self.last_update = now
183
186
        return False
184
187
        
206
209
            return 
207
210
        
208
211
        if self.show_eta and self.start_time and total_cnt:
209
 
            eta = get_eta(self.start_time, current_cnt, total_cnt)
 
212
            eta = get_eta(self.start_time, current_cnt, total_cnt,
 
213
                    last_updates = self.last_updates)
210
214
            eta_str = " " + str_tdelta(eta)
211
215
        else:
212
216
            eta_str = ""
280
284
                             delt % 60)
281
285
 
282
286
 
283
 
def get_eta(start_time, current, total, enough_samples=3):
 
287
def get_eta(start_time, current, total, enough_samples=3, last_updates=None, n_recent=10):
284
288
    if start_time is None:
285
289
        return None
286
290
 
302
306
 
303
307
    assert total_duration >= elapsed
304
308
 
 
309
    if last_updates and len(last_updates) >= n_recent:
 
310
        while len(last_updates) > n_recent:
 
311
            last_updates.popleft()
 
312
        avg = sum(last_updates) / float(len(last_updates))
 
313
        time_left = avg * (total - current)
 
314
 
 
315
        old_time_left = total_duration - elapsed
 
316
 
 
317
        # We could return the average, or some other value here
 
318
        return (time_left + old_time_left) / 2
 
319
 
305
320
    return total_duration - elapsed
306
321
 
307
322