def _print_progress(self, event): """Print a progress based on the information on a GeneralEvent.""" if event.indeterminate: # indeterminate, no progress to be shown return prefix = """ --> {phase_name} {current_phase}/{target}""".format( phase_name=event.phase_name, current_phase=min(event.total_phases, event.current_phase + 1), target=event.total_phases, ) elapsed = datetime.now() - self._start_time statuses = self._get_legends() suffix = """{runtime} {statuses}""".format(statuses=statuses, runtime=format_running_time(elapsed.seconds)) pb = ProgressBar( total=100, prefix=prefix, suffix=suffix, decimals=0, length=self.bar_length, fill=self.filled_bar_char, zfill=self.empty_bar_char, file=self._out, ) pb.print_progress_bar(event.progress * 100)
def test_format_running_time(self): tests = [ { "seconds": 0, "expected": "Running time: 0 seconds" }, { "seconds": 1, "expected": "Running time: 1 seconds" }, { "seconds": 100, "expected": "Running time: 1 minutes 40 seconds" }, { "seconds": 10000, "expected": "Running time: 2 hours 46 minutes 40 seconds", }, # noqa { "seconds": 100000, "expected": "Running time: 1 days 3 hours 46 minutes 40 seconds", }, # noqa { "seconds": 100000000, "expected": "Running time: 1157 days 9 hours 46 minutes 40 seconds", }, # noqa ] for t in tests: self.assertEqual(t["expected"], format_running_time(t["seconds"]))
def _print_progress(self, event): """Print a progress based on the information on a GeneralEvent.""" if event.indeterminate: # indeterminate, no progress to be shown return current_phase = min(event.total_phases, event.current_phase + 1) elapsed = datetime.now() - self._start_time nphase = f" {current_phase}/{event.total_phases}" bar_format = " {desc} |{bar}| {percentage:3.0f}% {unit}" tqdm.write(f" --> {event.phase_name}", file=self._out) tqdm.write("\n", end="", file=self._out) with tqdm(total=100, ncols=100, bar_format=bar_format, file=self._out) as pbar: pbar.set_description_str(nphase, refresh=False) pbar.unit = "{runtime}".format( runtime=format_running_time(elapsed.seconds)) pbar.update(event.progress * 100) tqdm.write("\n", end="", file=self._out) tqdm.write(self._get_legends(), file=self._out)
def _on_ticker(self): runtime = self._run_model.get_runtime() self.running_time.setText(format_running_time(runtime))