"""
测试考试记录API
"""
import asyncio
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from app.services.exam_service import ExamService
from app.core.config import settings

async def test_exam_records():
    """测试获取考试记录"""
    # 创建数据库连接
    engine = create_async_engine(
        settings.SQLALCHEMY_DATABASE_URI,
        echo=True,
        future=True
    )
    
    async_session = sessionmaker(
        engine, class_=AsyncSession, expire_on_commit=False
    )
    
    async with async_session() as db:
        # 测试user_id=5的考试记录
        print("\n========== 测试user_id=5的考试记录 ==========")
        records = await ExamService.get_exam_records(
            db=db,
            user_id=5,
            page=1,
            size=10
        )
        
        print(f"\n总记录数: {records['total']}")
        print(f"当前页: {records['page']}")
        print(f"每页数量: {records['size']}")
        print(f"总页数: {records['pages']}")
        print(f"\n记录列表:")
        
        for item in records['items']:
            print(f"\nID: {item['id']}")
            print(f"  考试名称: {item['exam_name']}")
            print(f"  课程名称: {item['course_name']}")
            print(f"  得分: {item['score']}")
            print(f"  正确率: {item['accuracy']}%")
            print(f"  正确数: {item['correct_count']}")
            print(f"  错题数: {item['wrong_count']}")
            print(f"  用时: {item['duration_seconds']}秒")
            print(f"  分题型统计: {len(item['question_type_stats'])}种题型")

if __name__ == "__main__":
    asyncio.run(test_exam_records())

