Skip to content

Commit

Permalink
fix total divide by zero
Browse files Browse the repository at this point in the history
  • Loading branch information
glevco committed Jun 7, 2023
1 parent 69151c0 commit 7521949
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions hathor/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def progress(
t_start = time.time()
count = 0
count_log_prev = 0
if total is not None:
if total:
log.info('loading... 0%', progress=0)
else:
log.info('loading...')
Expand All @@ -471,7 +471,7 @@ def progress(
dcount = count - count_log_prev
rate = '?' if dt_log == 0 else dcount / dt_log
kwargs = dict(rate=rate, new=dcount, dt=dt_log, total=count)
if total is not None:
if total:
progress_ = count / total
elapsed_time = t_log - t_start
remaining_time = LogDuration(elapsed_time / progress_ - elapsed_time)
Expand All @@ -491,7 +491,7 @@ def progress(
t_final = time.time()
dt_total = LogDuration(t_final - t_start)
rate = '?' if dt_total == 0 else count / dt_total
if total is not None:
if total:
progress_ = count / total
log.info(f'loaded... {math.floor(progress_ * 100):2.0f}%', progress=progress_, count=count, rate=rate,
total_dt=dt_total)
Expand Down Expand Up @@ -548,7 +548,7 @@ def _tx_progress(iter_tx: Iterator['BaseTransaction'], *, log: 'structlog.stdlib
tx_rate = '?' if dt_log == 0 else dcount / dt_log
ts = datetime.datetime.fromtimestamp(ts_tx)
kwargs = dict(tx_rate=tx_rate, tx_new=dcount, dt=dt_log, total=count, latest_ts=ts, height=h)
if total is not None:
if total:
progress_ = count / total
elapsed_time = t_log - t_start
remaining_time = LogDuration(elapsed_time / progress_ - elapsed_time)
Expand Down

0 comments on commit 7521949

Please sign in to comment.