#!/usr/bin/env python # -*- coding: utf-8 -*- """ 创建一个测试实验用于验证脚本执行功能 """ import sqlite3 import json from pathlib import Path from datetime import datetime, timedelta def create_test_experiment(): """创建一个已结束的测试实验""" print("=" * 60) print("创建测试实验") print("=" * 60) db_path = Path(__file__).parent / "experiments.db" try: # 加载默认配置 config_path = Path(__file__).parent / "default.json" if config_path.exists(): with open(config_path, 'r', encoding='utf-8') as f: config_json = f.read() else: config_json = "{}" # 创建测试实验 start_time = (datetime.now() - timedelta(hours=4)).isoformat(timespec='seconds') end_time = datetime.now().isoformat(timespec='seconds') conn = sqlite3.connect(str(db_path)) cursor = conn.cursor() cursor.execute(""" INSERT INTO experiments (start_ts, end_ts, config_json, work_order_no, executor, remark, created_at, is_paused, is_terminated) VALUES (?, ?, ?, ?, ?, ?, ?, 0, 0) """, ( start_time, end_time, config_json, "TEST_SCRIPT_001", "测试员", "脚本执行测试实验", datetime.now().isoformat(timespec='seconds') )) exp_id = cursor.lastrowid conn.commit() conn.close() print(f"\n✅ 成功创建测试实验") print(f" 实验 ID: {exp_id}") print(f" 工单号: TEST_SCRIPT_001") print(f" 开始时间: {start_time}") print(f" 结束时间: {end_time}") print(f" 脚本数据: 未保存(待执行)") print("\n" + "=" * 60) print("测试步骤:") print("=" * 60) print("1. 启动程序: python main.py") print("2. 在「实验历史」标签页找到工单号 TEST_SCRIPT_001") print("3. 点击「保存数据」按钮") print("4. 等待数据保存完成") print("5. 点击「生成报告」按钮验证数据是否正确使用") except Exception as e: print(f"❌ 创建失败: {e}") import traceback traceback.print_exc() if __name__ == "__main__": create_test_experiment()