-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (29 loc) · 1009 Bytes
/
utils.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
import datetime
import logging
def benchmark(msg, f, *args):
start = datetime.datetime.now()
result = f(*args)
elapsed = datetime.datetime.now() - start
if(msg is not None):
logging.info(msg.format(hhmmssms_from_ms(elapsed.total_seconds() * 1000)))
return result
def parse_boolean(value):
if(value is None):
return None
elif (value == 'Yes'):
return True
return False
def key_from_dict_query(dict):
return dict['query'] + ', '.join(dict['params'])
def is_none(value):
return value is None or value == 'NONE'
def upper(value):
if(value is None):
return None
return str(value).upper().strip()
def hhmmssms_from_ms(value):
milliseconds = (int) (value % 1000)
seconds = (int) ((value / 1000) % 60)
minutes = (int) (((value / 1000) / 60) % 60)
hours = (int) ((((value / 1000) / 60) / 60) % 24)
return '{:02d}:{:02d}:{:02d}.{:03d}'.format(hours, minutes, seconds, milliseconds)