87 lines
2.7 KiB
Python
87 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
检查当前等待状态
|
||
"""
|
||
|
||
import sqlite3
|
||
from pathlib import Path
|
||
|
||
def check_waiting_state():
|
||
"""检查当前等待状态的实验"""
|
||
print("检查等待状态")
|
||
print("=" * 40)
|
||
|
||
try:
|
||
db_path = Path(__file__).parent / "experiments.db"
|
||
db = sqlite3.connect(str(db_path))
|
||
cur = db.cursor()
|
||
|
||
# 查询所有工单112233的记录
|
||
cur.execute("""
|
||
SELECT id, work_order_no, start_ts, end_ts, created_at, remark
|
||
FROM experiments
|
||
WHERE work_order_no = '112233'
|
||
ORDER BY id DESC
|
||
""")
|
||
|
||
results = cur.fetchall()
|
||
|
||
if results:
|
||
print("工单 112233 的所有实验记录:")
|
||
for row in results:
|
||
exp_id, work_order, start_ts, end_ts, created_at, remark = row
|
||
print(f" ID: {exp_id}")
|
||
print(f" 工单号: {work_order}")
|
||
print(f" 创建时间: {created_at}")
|
||
print(f" 开始时间: {start_ts or '未开始'}")
|
||
print(f" 结束时间: {end_ts or '未结束'}")
|
||
print(f" 备注: {remark or '无'}")
|
||
|
||
# 判断状态
|
||
if start_ts and end_ts:
|
||
status = "已完成"
|
||
elif start_ts:
|
||
status = "进行中"
|
||
else:
|
||
status = "等待开始"
|
||
print(f" 状态: {status}")
|
||
print("-" * 30)
|
||
|
||
# 查询最新的等待开始的实验
|
||
cur.execute("""
|
||
SELECT id, work_order_no, start_ts, end_ts, created_at, remark
|
||
FROM experiments
|
||
WHERE start_ts IS NULL
|
||
ORDER BY id DESC
|
||
LIMIT 5
|
||
""")
|
||
|
||
waiting_results = cur.fetchall()
|
||
|
||
if waiting_results:
|
||
print("\n当前等待开始的实验:")
|
||
for row in waiting_results:
|
||
exp_id, work_order, start_ts, end_ts, created_at, remark = row
|
||
print(f" ID: {exp_id} - 工单: {work_order} - 创建: {created_at}")
|
||
else:
|
||
print("\n没有等待开始的实验")
|
||
|
||
db.close()
|
||
|
||
except Exception as e:
|
||
print(f"ERROR 检查失败: {e}")
|
||
|
||
def main():
|
||
print("等待状态检查工具")
|
||
print("=" * 50)
|
||
|
||
check_waiting_state()
|
||
|
||
print("\n分析:")
|
||
print("1. 如果工单112233有多个记录,UI可能显示的是错误的记录")
|
||
print("2. 如果有等待开始的实验,那就是UI显示的记录")
|
||
print("3. 监控器应该监控最新创建的等待实验")
|
||
|
||
if __name__ == "__main__":
|
||
main()
|