75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""
|
||
|
|
检查监控器是否在运行
|
||
|
|
"""
|
||
|
|
|
||
|
|
import sqlite3
|
||
|
|
import os
|
||
|
|
|
||
|
|
def check_experiment_status():
|
||
|
|
"""检查实验状态"""
|
||
|
|
print("🔍 检查实验状态")
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 连接数据库
|
||
|
|
db_path = "experiments.db"
|
||
|
|
if not os.path.exists(db_path):
|
||
|
|
print("❌ 数据库文件不存在")
|
||
|
|
return
|
||
|
|
|
||
|
|
conn = sqlite3.connect(db_path)
|
||
|
|
cursor = conn.cursor()
|
||
|
|
|
||
|
|
# 查询当前工单的状态
|
||
|
|
cursor.execute("""
|
||
|
|
SELECT id, work_order_no, start_ts, end_ts, created_at
|
||
|
|
FROM experiments
|
||
|
|
WHERE work_order_no = '1234'
|
||
|
|
ORDER BY id DESC
|
||
|
|
LIMIT 1
|
||
|
|
""")
|
||
|
|
|
||
|
|
record = cursor.fetchone()
|
||
|
|
|
||
|
|
if not record:
|
||
|
|
print("❌ 没有找到工单1234的记录")
|
||
|
|
else:
|
||
|
|
exp_id, work_order, start_ts, end_ts, created_at = record
|
||
|
|
print(f"📊 工单1234的状态:")
|
||
|
|
print(f" 实验ID: {exp_id}")
|
||
|
|
print(f" 工单号: {work_order}")
|
||
|
|
print(f" 开始时间: {start_ts or '未开始'}")
|
||
|
|
print(f" 结束时间: {end_ts or '未结束'}")
|
||
|
|
print(f" 创建时间: {created_at}")
|
||
|
|
|
||
|
|
# 判断状态
|
||
|
|
if start_ts and end_ts:
|
||
|
|
print(" 🔴 状态: 已完成")
|
||
|
|
elif start_ts and not end_ts:
|
||
|
|
print(" 🟡 状态: 进行中")
|
||
|
|
else:
|
||
|
|
print(" 🟠 状态: 等待开始")
|
||
|
|
print(" 💡 这个状态下监控器应该正在运行")
|
||
|
|
|
||
|
|
conn.close()
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"❌ 检查失败: {e}")
|
||
|
|
|
||
|
|
def main():
|
||
|
|
print("监控器运行状态检查")
|
||
|
|
print("=" * 30)
|
||
|
|
|
||
|
|
check_experiment_status()
|
||
|
|
|
||
|
|
print("\n💡 测试建议:")
|
||
|
|
print("1. 确认程序界面显示'等待实验开始'")
|
||
|
|
print("2. 在监控器运行期间写入状态变化:")
|
||
|
|
print(" echo 3 | python quick_test_data.py # 写入状态1")
|
||
|
|
print(" (等待5-10秒)")
|
||
|
|
print(" echo 2 | python quick_test_data.py # 写入状态0")
|
||
|
|
print("3. 观察程序界面是否更新开始/结束时间")
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|