Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(frontend): fix progressbar and route table
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhxiao committed Sep 24, 2019
1 parent 9a65e4f commit 84e6779
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
13 changes: 7 additions & 6 deletions gnes/client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,30 @@ def __init__(self, bar_len: int = 20, task_name: str = ''):

def update(self):
self.num_bars += 1
if (self.num_bars + 1) % self.bar_len == 0:
sys.stdout.write('\n')
sys.stdout.write('\r')
elapsed = time.perf_counter() - self.start_time
elapsed_str = colored('elapsed', 'yellow')
speed_str = colored('speed', 'yellow')
num_bars = self.num_bars % self.bar_len
num_bars = self.bar_len if not num_bars and self.num_bars else max(num_bars, 1)

sys.stdout.write(
'{:>10} [{:<{}}] {:>8}: {:3.1f}s {:>8}: {:3.1f} batch/s'.format(
colored(self.task_name, 'cyan'),
colored('=' * int(self.num_bars % self.bar_len), 'green'),
colored('=' * num_bars, 'green'),
self.bar_len + 9,
elapsed_str,
elapsed,
speed_str,
self.num_bars / elapsed,
))

if num_bars == self.bar_len:
sys.stdout.write('\n')
sys.stdout.flush()
sys.stdout.write('\r')

def __enter__(self):
self.start_time = time.perf_counter()
self.num_bars = 0
self.num_bars = -1
self.update()
return self

Expand Down
6 changes: 3 additions & 3 deletions gnes/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,14 @@ def _path_import(absolute_path):
return module, spec


def make_route_table(routes, exclude_frontend: bool = False, jitter: float = 1e-8):
def make_route_table(routes, include_frontend: bool = False, jitter: float = 1e-8):
route_time = []
if exclude_frontend:
if include_frontend:
total_duration = get_duration(routes[0].start_time, routes[0].end_time) + jitter
else:
total_duration = get_duration(routes[0].start_time, routes[-1].end_time) + jitter
sum_duration = 0
for k in routes[(1 if exclude_frontend else 0):]:
for k in routes:
d = get_duration(k.start_time, k.end_time)
route_time.append((k.service, d))
sum_duration += d
Expand Down
2 changes: 1 addition & 1 deletion gnes/service/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def remove_envelope(self, m: 'gnes_pb2.Message'):
m.envelope.routes[0].end_time.GetCurrentTime()
if self.args.route_table:
self.logger.info('route: %s' % router2str(m))
self.logger.info('route table: \n%s' % make_route_table(m.envelope.routes, exclude_frontend=True))
self.logger.info('route table: \n%s' % make_route_table(m.envelope.routes, include_frontend=True))
if self.args.dump_route:
self.args.dump_route.write(MessageToJson(m.envelope, indent=0).replace('\n', '') + '\n')
self.args.dump_route.flush()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ def test_progressbar5(self):
with ProgressBar(task_name='test', bar_len=self.bar_len) as pb:
for j in range(5 * self.bar_len):
pb.update()
time.sleep(.05)

def test_progressbar1(self):
# should be single line
with ProgressBar(task_name='test', bar_len=self.bar_len) as pb:
for j in range(self.bar_len):
pb.update()
time.sleep(.1)
time.sleep(.05)

0 comments on commit 84e6779

Please sign in to comment.