Skip to content

Commit 1b47fad

Browse files
committed
⚡ [Enhance] TCLogbar: add start_count and elapsed_count, to log progress with offset
1 parent 3736dcb commit 1b47fad

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/tclogger/bars.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__(
2626
self,
2727
count: int = 0,
2828
total: int = None,
29+
start_count: int = 0,
2930
head: str = "",
3031
desc: str = "",
3132
cols: int = 35,
@@ -42,6 +43,7 @@ def __init__(
4243
):
4344
self.count = count
4445
self.total = total
46+
self.start_count = start_count
4547
self.head = head
4648
self.desc = desc
4749
self.cols = cols
@@ -72,6 +74,9 @@ def is_num(self, num: Union[int, float]):
7274
def is_grouped(self):
7375
return self.group is not None and self.node_idx is not None
7476

77+
def elapsed_count(self):
78+
return self.count - self.start_count
79+
7580
def move_cursor(self):
7681
self.cursor.move(row=self.line_height - 1)
7782
self.cursor.erase_line()
@@ -162,17 +167,21 @@ def update(
162167
elif (
163168
self.is_num(self.total)
164169
and self.is_num(self.count)
165-
and self.count > 0
166-
and self.total - self.count >= 0
170+
and self.elapsed_count() > 0
171+
and self.total - self.elapsed_count() >= 0
167172
):
168173
self.remain_seconds = (
169-
dt_seconds * (self.total - self.count) / self.count
174+
dt_seconds
175+
* (self.total - self.elapsed_count())
176+
/ self.elapsed_count()
170177
)
171178
else:
172179
self.remain_seconds = None
173180

174181
if self.is_num(self.count) and self.count > 0 and dt_seconds > 0:
175-
self.iter_per_second = round(self.count / dt_seconds, ndigits=1)
182+
self.iter_per_second = round(
183+
self.elapsed_count() / dt_seconds, ndigits=1
184+
)
176185
else:
177186
self.iter_per_second = None
178187

@@ -308,6 +317,9 @@ def set_total(self, total: int = None):
308317
def set_count(self, count: int = None):
309318
self.count = count
310319

320+
def set_start_count(self, start_count: int = None):
321+
self.start_count = start_count
322+
311323
def increment(self, increment: int = None):
312324
self.count += increment
313325

0 commit comments

Comments
 (0)