- Implemented enhanced PDF parsing with V2 parser for better question extraction - Added improved question formatting and display components - Integrated question navigation and progress tracking features - Added JSON export functionality for paper questions - Enhanced image extraction and association with questions - Improved database configuration with environment variables - Updated UI with responsive question cards and navigation sidebar - Added mathematical symbol rendering and question type detection Co-authored-by: Qwen-Coder <[email protected]>
123 lines
4.0 KiB
Python
123 lines
4.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
测试试卷拆分API
|
|
"""
|
|
|
|
import requests
|
|
import json
|
|
|
|
# API基础URL
|
|
BASE_URL = "http://localhost:8888"
|
|
|
|
def test_split_api():
|
|
"""测试拆分API"""
|
|
print("🧪 测试试卷拆分API...")
|
|
|
|
# 1. 先登录获取token
|
|
login_data = {
|
|
"username": "admin", # 尝试默认管理员账户
|
|
"password": "admin" # 尝试默认密码
|
|
}
|
|
|
|
try:
|
|
# 尝试登录
|
|
print("📝 尝试登录...")
|
|
login_response = requests.post(f"{BASE_URL}/api/auth/login", json=login_data)
|
|
|
|
if login_response.status_code == 200:
|
|
login_result = login_response.json()
|
|
token = login_result.get("access_token")
|
|
print(f"✅ 登录成功,获取到token")
|
|
else:
|
|
print(f"❌ 登录失败: {login_response.status_code}")
|
|
print(f"响应内容: {login_response.text}")
|
|
return
|
|
|
|
# 2. 调用拆分API
|
|
print("\n🔧 调用拆分API...")
|
|
headers = {
|
|
"Authorization": f"Bearer {token}",
|
|
"Content-Type": "application/json"
|
|
}
|
|
|
|
split_response = requests.post(f"{BASE_URL}/api/papers/1/split", headers=headers)
|
|
|
|
print(f"API响应状态码: {split_response.status_code}")
|
|
|
|
if split_response.status_code == 200:
|
|
split_result = split_response.json()
|
|
print(f"✅ 拆分成功!")
|
|
print(f"识别题目数量: {split_result.get('total_questions', 0)}")
|
|
print(f"处理方法: {split_result.get('stats', {}).get('method', 'unknown')}")
|
|
|
|
# 显示部分题目信息
|
|
questions = split_result.get('questions', [])
|
|
if questions:
|
|
print(f"\n前3道题目:")
|
|
for i, q in enumerate(questions[:3]):
|
|
print(f" 题目{i+1}: {q.get('number')} - {q.get('type')}")
|
|
print(f" 题干: {q.get('text', '')[:50]}...")
|
|
else:
|
|
print(f"❌ 拆分失败: {split_response.status_code}")
|
|
print(f"错误信息: {split_response.text}")
|
|
try:
|
|
error_detail = split_response.json()
|
|
print(f"详细错误: {error_detail}")
|
|
except:
|
|
pass
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ 无法连接到后端服务,请确保后端正在运行")
|
|
except Exception as e:
|
|
print(f"❌ 测试异常: {e}")
|
|
|
|
def check_existing_questions():
|
|
"""检查现有题目"""
|
|
print("\n📊 检查数据库中的题目...")
|
|
|
|
try:
|
|
# 先登录获取token
|
|
login_data = {
|
|
"username": "admin",
|
|
"password": "admin"
|
|
}
|
|
|
|
login_response = requests.post(f"{BASE_URL}/api/auth/login", json=login_data)
|
|
if login_response.status_code == 200:
|
|
token = login_response.json().get("access_token")
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
else:
|
|
print("无法获取token,跳过题目检查")
|
|
return
|
|
|
|
# 获取题目列表
|
|
questions_response = requests.get(f"{BASE_URL}/api/questions?paper_id=1", headers=headers)
|
|
|
|
if questions_response.status_code == 200:
|
|
questions = questions_response.json()
|
|
print(f"数据库中试卷1的题目数量: {len(questions)}")
|
|
|
|
if questions:
|
|
print("题目列表:")
|
|
for i, q in enumerate(questions[:5]):
|
|
print(f" {i+1}. ID:{q.get('id')}, 题号:{q.get('question_number')}, 类型:{q.get('question_type')}")
|
|
else:
|
|
print("数据库中没有题目")
|
|
else:
|
|
print(f"获取题目列表失败: {questions_response.status_code}")
|
|
|
|
except Exception as e:
|
|
print(f"检查题目失败: {e}")
|
|
|
|
if __name__ == "__main__":
|
|
print("🎯 试卷拆分API测试")
|
|
print("=" * 50)
|
|
|
|
# 检查现有题目
|
|
check_existing_questions()
|
|
|
|
# 测试拆分API
|
|
test_split_api()
|
|
|
|
# 再次检查题目
|
|
check_existing_questions() |