From 08af45eda33f0dabe07f13802d548344e20000cb Mon Sep 17 00:00:00 2001 From: Jake Bradford Date: Thu, 11 Jan 2024 13:50:21 +1000 Subject: [PATCH] github-issue-10 fixed timestamp issues --- src/crackling/Crackling.py | 18 +++++++++--------- src/crackling/Helpers.py | 13 ++++++++++++- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/crackling/Crackling.py b/src/crackling/Crackling.py index 3cdd376..ed646cf 100644 --- a/src/crackling/Crackling.py +++ b/src/crackling/Crackling.py @@ -7,7 +7,7 @@ - See config.ini ''' -import ast, csv, joblib, os, re, sys, time, tempfile +import ast, csv, joblib, os, re, sys, time, tempfile, shutil from crackling.Paginator import Paginator from crackling.Batchinator import Batchinator @@ -875,17 +875,17 @@ def processSequence(sequence): printer(f'{len(candidateGuides)} guides evaluated.') - printer('This batch ran in {} (dd hh:mm:ss) or {} seconds'.format( - time.strftime('%d %H:%M:%S', time.gmtime((time.time() - batchStartTime))), - (time.time() - batchStartTime) - )) + batchEndTime = time.time() + timeDelta = batchEndTime - batchStartTime + + printer(f'This batch ran in {elapsedTimeString(batchStartTime, batchEndTime)} (dd hh:mm:ss) or {timeDelta:.3} seconds') batchFileId += 1 - printer('Total run time (dd hh:mm:ss) or {} seconds'.format( - time.strftime('%d %H:%M:%S', time.gmtime((time.time() - startTime))), - (time.time() - startTime) - )) + endTime = time.time() + timeDelta = endTime - startTime + + printer(f'Total run time {elapsedTimeString(startTime, endTime)} (dd hh:mm:ss) or {timeDelta:.3} seconds') sys.stdout.log.close() sys.stderr.log.close() diff --git a/src/crackling/Helpers.py b/src/crackling/Helpers.py index 6424f9a..a6d7b60 100644 --- a/src/crackling/Helpers.py +++ b/src/crackling/Helpers.py @@ -1,7 +1,7 @@ from subprocess import run from datetime import datetime -__all__ = ['rc','transToDNA','AT_percentage','printer','runner'] +__all__ = ['rc','transToDNA','AT_percentage','printer','runner','elapsedTimeString'] # Function that returns the reverse-complement of a given sequence def rc(dna): @@ -40,3 +40,14 @@ def runner(*args, **kwargs): printer(f"| Calling: {args}") run(*args, **kwargs) printer(f"| Finished") + + +# Function that generates a string representing elapsed time +def elapsedTimeString(start_time, end_time): + elapsed_seconds = end_time - start_time + + days, remainder = divmod(elapsed_seconds, 86400) + hours, remainder = divmod(remainder, 3600) + minutes, seconds = divmod(remainder, 60) + + return f"{int(days)} {int(hours):02d}:{int(minutes):02d}:{int(seconds):02d}"