ver3.0 #1
Merged
hnu202326010204
merged 10 commits from yangyixuan_branch into hufan_branch 3 months ago
@ -1,5 +1,4 @@
|
||||
src/frontend/src/vendor/
|
||||
src/venv/
|
||||
src/backend/__pycache__/
|
||||
/dist/
|
||||
/src/backend
|
||||
src/fronted
|
||||
@ -0,0 +1,54 @@
|
||||
# backend/paper_scoring.py
|
||||
|
||||
from . import paper_act
|
||||
def finalize_quiz(session_id: str) -> dict:
|
||||
"""计算分数并构造每题详情。"""
|
||||
|
||||
# 直接访问 paper_act 模块的私有会话存储
|
||||
s = paper_act._sessions.get(session_id)
|
||||
if not s:
|
||||
return {"success": False, "message": "无效会话"}
|
||||
|
||||
correct = 0
|
||||
total = len(s["questions"])
|
||||
|
||||
# --- 1. 计分循环(确保正确性)---
|
||||
# 在这个循环中,我们同时构造详情,以确保数据一致性
|
||||
details = []
|
||||
|
||||
for q in s["questions"]:
|
||||
qid = q.get("id")
|
||||
user_ans = s["answers"].get(qid)
|
||||
correct_ans = q.get("answer")
|
||||
|
||||
# 核心修复:强制转换为字符串进行比较,确保浮点数问题不会影响选项字母
|
||||
correct_ans_str = str(correct_ans).strip()
|
||||
user_ans_str = str(user_ans).strip()
|
||||
|
||||
# 判定题目是否正确
|
||||
is_correct = False
|
||||
if user_ans_str and user_ans_str == correct_ans_str:
|
||||
is_correct = True
|
||||
correct += 1 # 计分逻辑:只有正确才加分
|
||||
|
||||
# 构造每题详情(这里才是前端详情界面的数据来源)
|
||||
details.append({
|
||||
"id": qid,
|
||||
"text": q.get("text"),
|
||||
"options": q.get("options"),
|
||||
"user_answer": user_ans_str or "未作答",
|
||||
"correct_answer": correct_ans_str,
|
||||
"is_correct": is_correct, # 【新字段】用于前端判断显示“正确”或“错误”
|
||||
})
|
||||
|
||||
# 计算分数 (百分制,取整)
|
||||
score = int(correct / total * 100) if total else 0
|
||||
|
||||
# 返回结果
|
||||
return {
|
||||
"success": True,
|
||||
"score": score,
|
||||
"correct": correct,
|
||||
"total": total,
|
||||
"details": details
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) Evan You
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
---
|
||||
This file is bundled with Vue's ESM build inside this project for full offline distribution.
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue