-
Notifications
You must be signed in to change notification settings - Fork 1
/
HelperFunctions.py
51 lines (41 loc) · 1.25 KB
/
HelperFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 20 14:41:07 2022
@author: Ani Chattaraj
"""
import sys
from time import time
def ProgressBar(jobName, progress, length=40):
'''
Parameters
----------
jobName : string
Name of the job given by user.
progress : float
progress of the job to be printed as percentage.
length : interger
prints the length of the progressbar. The default is 40.
Returns
-------
None.
'''
completionIndex = round(progress*length)
msg = "\r{} : [{}] {}%".format(jobName, "*"*completionIndex + "-"*(length-completionIndex), round(progress*100))
if progress >= 1: msg += "\r\n"
sys.stdout.write(msg)
sys.stdout.flush()
def displayExecutionTime(func):
"""
This decorator (function) will calculate the time needed to execute a task
"""
def wrapper(*args, **kwrgs):
t1 = time()
func(*args, **kwrgs)
t2 = time()
delta = t2 - t1
if delta < 60:
print("Execution time : {:.4f} seconds".format(delta))
else:
t_min, t_sec = int(delta/60), round(delta%60)
print(f"Execution time : {t_min} mins {t_sec} secs")
return wrapper