diff --git a/MDANSE/Src/MDANSE/Framework/Jobs/JobStatus.py b/MDANSE/Src/MDANSE/Framework/Jobs/JobStatus.py index e9c70311e5..741c0e2121 100644 --- a/MDANSE/Src/MDANSE/Framework/Jobs/JobStatus.py +++ b/MDANSE/Src/MDANSE/Framework/Jobs/JobStatus.py @@ -16,7 +16,7 @@ import collections import pickle -import datetime +import time import os import threading import time @@ -36,11 +36,8 @@ def __init__(self, job): self._state = JobState() self._state["pid"] = PLATFORM.pid() self._state["type"] = job.__class__.__name__ - self._state["start"] = datetime.datetime.strftime( - datetime.datetime.today(), "%d-%m-%Y %H:%M:%S" - ) + self._state["start"] = str(time.time()) self._state["elapsed"] = "N/A" - self._state["eta"] = "N/A" self._state["current_step"] = 0 self._state["n_steps"] = 0 self._state["progress"] = 0 @@ -87,10 +84,8 @@ def update_status(self): self._state["elapsed"] = self.elapsedTime self._state["current_step"] = self.currentStep if self._nSteps is not None: - self._state["eta"] = self.eta self._state["progress"] = 100 * self.currentStep / self.nSteps else: - self._eta = "N/A" self._state["progress"] = 0 self.save_status() diff --git a/MDANSE/Src/MDANSE/Framework/Status.py b/MDANSE/Src/MDANSE/Framework/Status.py index 46568971a2..9596bc4598 100644 --- a/MDANSE/Src/MDANSE/Framework/Status.py +++ b/MDANSE/Src/MDANSE/Framework/Status.py @@ -16,25 +16,11 @@ import abc -import datetime +import time import numpy as np -def total_seconds(td): - return (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10.0**6 - - -def convert_duration(seconds): - """ - Convert a duration in seconds in days, hours, minutes and seconds - """ - - d = datetime.datetime(1, 1, 1) + datetime.timedelta(seconds=seconds) - - return (d.day - 1, d.hour, d.minute, d.second) - - class Status(object, metaclass=abc.ABCMeta): """ This class defines an interface for status objects. @@ -48,9 +34,8 @@ def __init__(self): self._nSteps = None self._finished = False self._stopped = False - self._startTime = datetime.datetime.today() - self._deltas = [self._startTime] - self._eta = "N/A" + self._startTime = time.time() + self._deltas = [self._startTime, self._startTime + 1.0] self._elapsedTime = "N/A" self._lastRefresh = self._startTime @@ -76,11 +61,7 @@ def currentStep(self): @property def elapsedTime(self): - return self._elapsedTime - - @property - def eta(self): - return self._eta + return str(self._deltas[1] - self._deltas[0]) def finish(self): self._finished = True @@ -91,7 +72,7 @@ def get_current_step(self): return self._currentStep def get_elapsed_time(self): - return self._elapsedTime + return self.elapsedTime def get_number_of_steps(self): return self._nSteps @@ -121,7 +102,6 @@ def start(self, nSteps, rate=None): self.start_status() def stop(self): - self._eta = "N/A" self._stopped = True self.stop_status() @@ -131,24 +111,11 @@ def update(self, force=False): self._currentStep += 1 - lastUpdate = datetime.datetime.today() + lastUpdate = time.time() - self._deltas.append(lastUpdate) + self._deltas[1] = lastUpdate - if force or (total_seconds(lastUpdate - self._lastRefresh) > 5): + if force or ((lastUpdate - self._lastRefresh) > 5): self._lastRefresh = lastUpdate - if self._nSteps is not None: - self._elapsedTime = "%02dd:%02dh:%02dm:%02ds" % convert_duration( - total_seconds(datetime.datetime.today() - self._startTime) - ) - duration = [ - total_seconds(self._deltas[i + 1] - self._deltas[i]) - for i in range(self._currentStep) - ] - duration = np.median(duration) * (self._nSteps - self._currentStep) - duration = datetime.timedelta(seconds=round(duration)) - duration = convert_duration(total_seconds(duration)) - self._eta = "%02dd:%02dh:%02dm:%02ds" % duration - self.update_status()