-
Notifications
You must be signed in to change notification settings - Fork 0
/
GlobalFunctions.py
31 lines (23 loc) · 1.03 KB
/
GlobalFunctions.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
import functools
import time
import SwPrint
def print_run_time(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
func_without_datetime = ['_xlsx_import', '_xls_import', '_csv_import', 'save_to_xlsx', 'save_to_csv']
SwPrint.SwPrint.print(f'done in {generate_time_string(time.time() - start_time)}',
without_datetime=func.__name__ in func_without_datetime)
return result
return wrapper
def print(*args, only_debug=False, end='\n'):
if SwPrint.SwPrint._start_time == '':
SwPrint.SwPrint(debug=False, prj_name='')
SwPrint.SwPrint.print(*args, only_debug=only_debug, end=end)
def generate_time_string(duration):
hours, min, sec = duration // 3600, duration % 3600 // 60, duration % 60
text = f'{round(sec, 1)} seconds'
if min: text = f"{int(min)} minute{'s' if min > 1 else ''} {text}"
if hours: text = f"{int(hours)} hour{'s' if hours > 1 else ''} {text}"
return text