Skip to content

Commit

Permalink
Remove the calculation of formatted time string from Status
Browse files Browse the repository at this point in the history
  • Loading branch information
MBartkowiakSTFC committed Apr 8, 2024
1 parent fd5b841 commit 2180750
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 48 deletions.
9 changes: 2 additions & 7 deletions MDANSE/Src/MDANSE/Framework/Jobs/JobStatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import collections
import pickle
import datetime
import time
import os
import threading
import time
Expand All @@ -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
Expand Down Expand Up @@ -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()
49 changes: 8 additions & 41 deletions MDANSE/Src/MDANSE/Framework/Status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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()

0 comments on commit 2180750

Please sign in to comment.