update time estimate for long running processes

This commit is contained in:
Martin Diehl 2021-06-18 18:14:30 +02:00
parent 70505a6a63
commit 32b5e4dece
2 changed files with 6 additions and 4 deletions

View File

@ -33,9 +33,9 @@ class Grid:
----------
material : numpy.ndarray of shape (:,:,:)
Material indices.
size : list or numpy.ndarray
size : list or numpy.ndarray of shape (3)
Physical size of grid in meter.
origin : list or numpy.ndarray, optional
origin : list or numpy.ndarray of shape (3), optional
Coordinates of grid origin in meter.
comments : list of str, optional
Comments, e.g. history of operations.

View File

@ -588,9 +588,11 @@ class _ProgressBar:
fraction = (iteration+1) / self.total
filled_length = int(self.bar_length * fraction)
if filled_length > int(self.bar_length * self.last_fraction):
bar = '' * filled_length + '' * (self.bar_length - filled_length)
delta_time = datetime.datetime.now() - self.start_time
if filled_length > int(self.bar_length * self.last_fraction) or \
delta_time > datetime.timedelta(minutes=1):
bar = '' * filled_length + '' * (self.bar_length - filled_length)
remaining_time = (self.total - (iteration+1)) * delta_time / (iteration+1)
remaining_time -= datetime.timedelta(microseconds=remaining_time.microseconds) # remove μs
sys.stderr.write(f'\r{self.prefix} {bar} {fraction:>4.0%} ETA {remaining_time}')