feat:增加考试接口
This commit is contained in:
@@ -99,12 +99,12 @@ exam_prompt = """
|
|||||||
- single:单选题,answer 长度为 1
|
- single:单选题,answer 长度为 1
|
||||||
- multiple:多选题,answer 长度 ≥ 2
|
- multiple:多选题,answer 长度 ≥ 2
|
||||||
- question:题干内容
|
- question:题干内容
|
||||||
- options:选项数组,固定 4 项,格式为 ["A. xxx", "B. xxx", "C. xxx", "D. xxx"]
|
- options:选项数组,固定 4 项,格式为 ["选项A内容", "选项B内容", "选项C内容", "选项D内容"]
|
||||||
- answer:正确答案编号数组,如 ["A"] 或 ["A", "C"]
|
- answer:正确答案编号数组,如 ["A"] 或 ["A", "C"]
|
||||||
- select:用户选择,永远为空数组 []
|
- select:用户选择,永远为空数组 []
|
||||||
|
|
||||||
【约束】
|
【约束】
|
||||||
1. 仅返回 JSON 数组,不要任何说明、注释或 Markdown。
|
1. 仅返回纯 JSON,禁止输出 Markdown、代码块、注释或任何说明文字。必须返回一个 JSON 数组,不得以对象包裹。JSON 必须是合法格式,可被程序直接解析。
|
||||||
2. 单选题的 answer 只能包含一个选项。
|
2. 单选题的 answer 只能包含一个选项。
|
||||||
3. 多选题的 answer 至少包含两个选项。
|
3. 多选题的 answer 至少包含两个选项。
|
||||||
4. 选项必须具有区分度,不能有明显错误或重复。
|
4. 选项必须具有区分度,不能有明显错误或重复。
|
||||||
@@ -115,12 +115,12 @@ exam_prompt = """
|
|||||||
{
|
{
|
||||||
"id": 1,
|
"id": 1,
|
||||||
"type": "single",
|
"type": "single",
|
||||||
"question": "下列关于光的传播说法正确的是?",
|
"question": "题目内容",
|
||||||
"options": [
|
"options": [
|
||||||
"A. 光在同种均匀介质中沿直线传播",
|
"选项A内容",
|
||||||
"B. 光在真空中的传播速度为 3×10⁸ m/s",
|
"选项B内容",
|
||||||
"C. 光在不同介质中传播速度相同",
|
"选项C内容",
|
||||||
"D. 光不能在真空中传播"
|
"选项D内容"
|
||||||
],
|
],
|
||||||
"answer": ["A"],
|
"answer": ["A"],
|
||||||
"select": []
|
"select": []
|
||||||
@@ -128,12 +128,12 @@ exam_prompt = """
|
|||||||
{
|
{
|
||||||
"id": 2,
|
"id": 2,
|
||||||
"type": "multiple",
|
"type": "multiple",
|
||||||
"question": "下列哪些属于可再生能源?",
|
"question": "题目内容",
|
||||||
"options": [
|
"options": [
|
||||||
"A. 太阳能",
|
"选项A内容",
|
||||||
"B. 煤炭",
|
"选项B内容",
|
||||||
"C. 风能",
|
"选项C内容",
|
||||||
"D. 天然气"
|
"选项D内容"
|
||||||
],
|
],
|
||||||
"answer": ["A", "C"],
|
"answer": ["A", "C"],
|
||||||
"select": []
|
"select": []
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ class PracticeRecord(AuditBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class ExamRecord(AuditBase):
|
||||||
|
subject = Column(String(45), nullable=False)
|
||||||
|
total_count = Column(Integer, nullable=False)
|
||||||
|
correct_count = Column(Integer, nullable=False)
|
||||||
|
wrong_count = Column(Integer, nullable=False)
|
||||||
|
|
||||||
|
|
||||||
class Mistake(AuditBase):
|
class Mistake(AuditBase):
|
||||||
subject = Column(String(45), nullable=False)
|
subject = Column(String(45), nullable=False)
|
||||||
module = Column(String(45), nullable=False)
|
module = Column(String(45), nullable=False)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
from .agent import router as agent_router
|
from .agent import router as agent_router
|
||||||
from .library import router as library_router
|
from .library import router as library_router
|
||||||
from .practice import router as practice_router
|
from .practice import router as practice_router
|
||||||
|
from .exam import router as exam_router
|
||||||
from .mistake import router as mistake_router
|
from .mistake import router as mistake_router
|
||||||
|
|
||||||
routers = [
|
routers = [
|
||||||
agent_router,
|
agent_router,
|
||||||
library_router,
|
library_router,
|
||||||
practice_router,
|
practice_router,
|
||||||
|
exam_router,
|
||||||
mistake_router,
|
mistake_router,
|
||||||
]
|
]
|
||||||
|
|||||||
13
routers/exam.py
Normal file
13
routers/exam.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
from fastapi import APIRouter, Depends
|
||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from database import get_db
|
||||||
|
from schemas.exam import ExamRecordRequest
|
||||||
|
from service import exam_service
|
||||||
|
|
||||||
|
router = APIRouter(prefix="/exam", tags=["Exam"])
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/record", response_model=bool)
|
||||||
|
async def add_record(data: ExamRecordRequest, db: AsyncSession = Depends(get_db), ):
|
||||||
|
return await exam_service.add_record(db, data)
|
||||||
16
schemas/exam.py
Normal file
16
schemas/exam.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class ExamRecordRequest(BaseModel):
|
||||||
|
subject: str
|
||||||
|
totalCount: int
|
||||||
|
correctCount: int
|
||||||
|
wrongCount: int
|
||||||
|
|
||||||
|
|
||||||
|
class ExamRecordResponse(ExamRecordRequest):
|
||||||
|
id: int
|
||||||
|
createTime: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
from_attributes = True
|
||||||
18
service/exam_service.py
Normal file
18
service/exam_service.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||||||
|
|
||||||
|
from models.library import ExamRecord
|
||||||
|
from schemas.exam import ExamRecordRequest
|
||||||
|
|
||||||
|
|
||||||
|
async def add_record(db: AsyncSession, data: ExamRecordRequest) -> bool:
|
||||||
|
record = ExamRecord(
|
||||||
|
subject=data.subject,
|
||||||
|
total_count=data.totalCount,
|
||||||
|
correct_count=data.correctCount,
|
||||||
|
wrong_count=data.wrongCount,
|
||||||
|
)
|
||||||
|
|
||||||
|
db.add(record)
|
||||||
|
await db.commit()
|
||||||
|
|
||||||
|
return True
|
||||||
Reference in New Issue
Block a user