Skip to content

Commit

Permalink
平均処理時間を記録する
Browse files Browse the repository at this point in the history
  • Loading branch information
itkr committed Sep 2, 2015
1 parent d8ef61f commit 3a7551e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions progress_bar.py
Expand Up @@ -15,6 +15,9 @@ def __init__(self, max_num, unit_num=1):
self.current_num = 0
self.started_at = None
self.finished_at = None
self.updated_at = None
self.last_lap = 0
self.average_lap = 0

@classmethod
def iteration(cls, iterable, call_back, unit_num=1):
Expand Down Expand Up @@ -44,7 +47,15 @@ def forward(self):
def back(self):
self.update(self.current_num - self.unit_num)

def _lap(self):
now = datetime.now()
current_lap = (self.updated_at - now).total_seconds()
self.average_lap = (self.last_lap + current_lap) / 2
self.last_lap = current_lap
self.updated_at = now

def update(self, num):
self._lap()
self.current_num = max(0, min(self.max_num, num))

def start(self):
Expand Down

0 comments on commit 3a7551e

Please sign in to comment.