python_arango_ogm.utils.time_util

 1from datetime import datetime
 2from contextlib import contextmanager
 3from timeit import default_timer as timer
 4import sys
 5
 6SQL_DATE_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ"
 7EPI_SQL_DATE_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
 8
 9NINETEEN_SEVENTY = datetime(1970, 1, 1)
10
11@contextmanager
12def time_and_log(name: str, silent: bool = False):
13  """Time and log block (using `with` statement)"""
14
15  if not silent:
16    caption = name if name else 'operation'
17    print(f"[{caption}] Starting...")
18    sys.stdout.flush()
19  started_at = timer()
20  yield()
21  elapsed = timer() - started_at
22  if not silent:
23    print(f"[{caption}] Processed in in {elapsed:.2f}s.")
24    sys.stdout.flush()
25  return elapsed
SQL_DATE_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ'
EPI_SQL_DATE_FORMAT = '%Y-%m-%d %H:%M:%S.%f'
NINETEEN_SEVENTY = datetime.datetime(1970, 1, 1, 0, 0)
@contextmanager
def time_and_log(name: str, silent: bool = False):
12@contextmanager
13def time_and_log(name: str, silent: bool = False):
14  """Time and log block (using `with` statement)"""
15
16  if not silent:
17    caption = name if name else 'operation'
18    print(f"[{caption}] Starting...")
19    sys.stdout.flush()
20  started_at = timer()
21  yield()
22  elapsed = timer() - started_at
23  if not silent:
24    print(f"[{caption}] Processed in in {elapsed:.2f}s.")
25    sys.stdout.flush()
26  return elapsed

Time and log block (using with statement)