-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
39 lines (31 loc) · 1.27 KB
/
util.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
from dataclasses import fields
import logging
import time
logger = logging.getLogger(__name__)
def time_function(func):
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
class_name = args[0].__class__.__name__ if args and hasattr(args[0], '__class__') else 'N/A'
logger.info(f"{class_name}.{func.__name__} executed in {end_time - start_time} seconds")
return result
return wrapper
def async_time_function(func):
async def wrapper(*args, **kwargs):
start_time = time.time()
result = await func(*args, **kwargs) # Await the async function
end_time = time.time()
class_name = args[0].__class__.__name__ if args and hasattr(args[0], '__class__') else 'N/A'
logger.info(f"{class_name}.{func.__name__} executed in {end_time - start_time} seconds")
return result
return wrapper
def setup_logging():
# Set up basic configuration for the logging system
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)
def get_dataclass_fields(data_cls):
return {field.name: field.type for field in fields(data_cls)}