104 lines
3.3 KiB
Python
104 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试自动退出等待状态功能
|
|
"""
|
|
|
|
import sqlite3
|
|
from pathlib import Path
|
|
|
|
def check_current_waiting_state():
|
|
"""检查当前等待状态"""
|
|
print("检查当前等待状态")
|
|
print("=" * 40)
|
|
|
|
try:
|
|
db_path = Path(__file__).parent / "experiments.db"
|
|
db = sqlite3.connect(str(db_path))
|
|
cur = db.cursor()
|
|
|
|
# 查询工单 11223345 的最新实验
|
|
cur.execute("""
|
|
SELECT id, work_order_no, start_ts, end_ts, created_at
|
|
FROM experiments
|
|
WHERE work_order_no = '11223345'
|
|
ORDER BY id DESC
|
|
LIMIT 1
|
|
""")
|
|
|
|
result = cur.fetchone()
|
|
|
|
if result:
|
|
exp_id, work_order, start_ts, end_ts, created_at = result
|
|
|
|
print(f"最新实验记录:")
|
|
print(f" ID: {exp_id}")
|
|
print(f" 工单: {work_order}")
|
|
print(f" 创建: {created_at}")
|
|
print(f" 开始: {start_ts or '未开始'}")
|
|
print(f" 结束: {end_ts or '未结束'}")
|
|
|
|
# 判断状态
|
|
if start_ts and end_ts:
|
|
status = "已完成"
|
|
should_exit = "是"
|
|
elif start_ts:
|
|
status = "进行中"
|
|
should_exit = "否"
|
|
else:
|
|
status = "等待开始"
|
|
should_exit = "否"
|
|
|
|
print(f" 状态: {status}")
|
|
print(f" 应该退出等待: {should_exit}")
|
|
|
|
return exp_id, status, should_exit == "是"
|
|
else:
|
|
print("没有找到工单 11223345 的记录")
|
|
return None, None, False
|
|
|
|
db.close()
|
|
|
|
except Exception as e:
|
|
print(f"ERROR 检查失败: {e}")
|
|
return None, None, False
|
|
|
|
def main():
|
|
print("自动退出等待状态测试")
|
|
print("=" * 50)
|
|
print("目标: 验证实验完成后UI自动退出等待状态")
|
|
print("=" * 50)
|
|
|
|
exp_id, status, should_exit = check_current_waiting_state()
|
|
|
|
print("\n" + "=" * 50)
|
|
print("修复说明:")
|
|
print("1. 添加了 _check_and_exit_waiting_state() 方法")
|
|
print("2. 在状态变化回调中检查实验是否完成")
|
|
print("3. 如果实验已完成,自动退出等待状态")
|
|
|
|
print("\n修复逻辑:")
|
|
print("- 监控器检测到状态变化 -> 刷新实验列表")
|
|
print("- 检查当前等待的实验是否已完成")
|
|
print("- 如果已完成 -> 自动退出等待状态")
|
|
print("- 隐藏等待提示,启用开始工单按钮")
|
|
|
|
if should_exit:
|
|
print("\n当前状态:")
|
|
print(f"✅ 实验 {exp_id} 已完成")
|
|
print("✅ 下次状态变化时应该自动退出等待状态")
|
|
print("\n测试方法:")
|
|
print("1. 重启程序或等待下次状态变化")
|
|
print("2. 观察UI是否自动退出等待状态")
|
|
print("3. 检查等待提示是否消失")
|
|
else:
|
|
print("\n当前状态:")
|
|
print(f"⏳ 实验状态: {status}")
|
|
print("⏳ 暂时不会退出等待状态")
|
|
print("\n可以手动测试:")
|
|
print("1. echo 3 | python quick_test_data.py")
|
|
print("2. echo 2 | python quick_test_data.py")
|
|
print("3. 观察UI是否自动退出等待状态")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|