- Removed obsolete command-line test parameters from `run_cli.py` to streamline functionality. - Introduced a new `ocr_preprocess.py` module for unified OCR image preprocessing, enhancing recognition stability. - Updated various components to utilize the new preprocessing function, improving code organization and readability. - Adjusted configuration values in `config.json` for better performance and consistency. - Added comprehensive technical documentation for the Douyin project, detailing code modification standards and operational guidelines. - Cleaned up excessive blank lines across multiple files to enhance overall readability.
53 lines
914 B
Python
53 lines
914 B
Python
"""操作追踪装饰器:自动记录函数耗时与操作信息"""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from functools import wraps
|
|
|
|
from .performance_tracker import PerformanceTracker
|
|
from .action_logger import ActionLogger
|
|
_perf = PerformanceTracker()
|
|
_logger = ActionLogger()
|
|
|
|
def track_action(name: str = ""):
|
|
def decorator(func):
|
|
@wraps(func)
|
|
def wrapper(*args, **kwargs):
|
|
timer = _perf.start_timer(name or func.__name__)
|
|
t0 = time.time()
|
|
try:
|
|
result = func(*args, **kwargs)
|
|
return result
|
|
finally:
|
|
elapsed = _perf.end_timer(timer)
|
|
elapsed = elapsed if elapsed is not None else time.time() - t0
|
|
_logger.log_step(name or func.__name__, elapsed=elapsed)
|
|
return wrapper
|
|
return decorator
|
|
|
|
__all__ = ["track_action"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|