-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_utils.py
More file actions
28 lines (23 loc) · 833 Bytes
/
common_utils.py
File metadata and controls
28 lines (23 loc) · 833 Bytes
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
import re
import time
from functools import wraps
def normalize_department_name(
department_name: str
) -> str:
"""
Normalizes a department name by replacing non-breaking spaces
and multiple consecutive spaces with a single space.
:param department_name: The department name to normalize.
:return: A normalized department name with single spaces.
"""
return re.sub(r'\s+', ' ', department_name.replace('\u00A0', ' ')).strip()
def async_timeit(func):
@wraps(func)
async def wrapper(*args, **kwargs):
start_time = time.perf_counter()
result = await func(*args, **kwargs)
end_time = time.perf_counter()
elapsed_time = end_time - start_time
print(f"{func.__name__} executed in {elapsed_time:.4f} seconds")
return result
return wrapper