mirror of
https://github.com/deepmodeling/Uni-Lab-OS
synced 2026-03-29 16:53:12 +00:00
refactor: 升级编译器共享工具库(logger_util, unit_parser, vessel_parser, resource_helper)
- logger_util: 重写debug_print,支持自动检测调用模块并设置前缀 - unit_parser: 新增parse_temperature_input,统一温度字符串解析 - vessel_parser: 新增find_connected_heatchill,统一加热设备查找 - resource_helper: 新增update_vessel_volume/get_resource_liquid_volume等共享函数 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,36 +1,57 @@
|
||||
# 🆕 创建进度日志动作
|
||||
"""编译器共享日志工具"""
|
||||
|
||||
import inspect
|
||||
import logging
|
||||
from typing import Dict, Any
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
# 模块名到前缀的映射
|
||||
_MODULE_PREFIXES = {
|
||||
"add_protocol": "[ADD]",
|
||||
"adjustph_protocol": "[ADJUSTPH]",
|
||||
"clean_vessel_protocol": "[CLEAN_VESSEL]",
|
||||
"dissolve_protocol": "[DISSOLVE]",
|
||||
"dry_protocol": "[DRY]",
|
||||
"evacuateandrefill_protocol": "[EVACUATE]",
|
||||
"evaporate_protocol": "[EVAPORATE]",
|
||||
"filter_protocol": "[FILTER]",
|
||||
"heatchill_protocol": "[HEATCHILL]",
|
||||
"hydrogenate_protocol": "[HYDROGENATE]",
|
||||
"pump_protocol": "[PUMP]",
|
||||
"recrystallize_protocol": "[RECRYSTALLIZE]",
|
||||
"reset_handling_protocol": "[RESET]",
|
||||
"run_column_protocol": "[RUN_COLUMN]",
|
||||
"separate_protocol": "[SEPARATE]",
|
||||
"stir_protocol": "[STIR]",
|
||||
"wash_solid_protocol": "[WASH_SOLID]",
|
||||
"vessel_parser": "[VESSEL_PARSER]",
|
||||
"unit_parser": "[UNIT_PARSER]",
|
||||
"resource_helper": "[RESOURCE_HELPER]",
|
||||
}
|
||||
|
||||
def debug_print(message, prefix="[UNIT_PARSER]"):
|
||||
"""调试输出"""
|
||||
|
||||
def debug_print(message, prefix=None):
|
||||
"""调试输出 — 自动根据调用模块设置前缀"""
|
||||
if prefix is None:
|
||||
frame = inspect.currentframe()
|
||||
caller = frame.f_back if frame else None
|
||||
module_name = ""
|
||||
if caller:
|
||||
module_name = caller.f_globals.get("__name__", "")
|
||||
# 取最后一段作为模块短名
|
||||
module_name = module_name.rsplit(".", 1)[-1]
|
||||
prefix = _MODULE_PREFIXES.get(module_name, f"[{module_name.upper()}]")
|
||||
logger = logging.getLogger("unilabos.compile")
|
||||
logger.info(f"{prefix} {message}")
|
||||
|
||||
|
||||
def action_log(message: str, emoji: str = "📝", prefix="[HIGH-LEVEL OPERATION]") -> Dict[str, Any]:
|
||||
"""创建一个动作日志 - 支持中文和emoji"""
|
||||
try:
|
||||
full_message = f"{prefix} {emoji} {message}"
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": full_message,
|
||||
"progress_message": full_message
|
||||
}
|
||||
"""创建一个动作日志"""
|
||||
full_message = f"{prefix} {emoji} {message}"
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": full_message,
|
||||
"progress_message": full_message
|
||||
}
|
||||
except Exception as e:
|
||||
# 如果emoji有问题,使用纯文本
|
||||
safe_message = f"{prefix} {message}"
|
||||
|
||||
return {
|
||||
"action_name": "wait",
|
||||
"action_kwargs": {
|
||||
"time": 0.1,
|
||||
"log_message": safe_message,
|
||||
"progress_message": safe_message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user