From 2a015e05dc8a65bff8c31466385f3ed90af1f2be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Sun, 30 Nov 2025 23:12:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=94=E5=9B=9E=E9=A6=96?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 1847 ++------------------------------------ public/completion.html | 306 +++++++ public/quiz-results.html | 672 ++++++++++++++ public/quiz.html | 800 +++++++++++++++++ 4 files changed, 1836 insertions(+), 1789 deletions(-) create mode 100644 public/completion.html create mode 100644 public/quiz-results.html create mode 100644 public/quiz.html diff --git a/main.py b/main.py index ddca02a..d2129f4 100644 --- a/main.py +++ b/main.py @@ -193,6 +193,7 @@ async def save_answers(request: SaveAnswersRequest): question_id = answer.get('questionId') or answer.get('question_id', '') question_text = answer.get('questionText') or answer.get('question_text', '') question_type = answer.get('questionType') or answer.get('question_type', '') + options = answer.get('options', {}) # 获取选项数据 is_correct = user_answer == correct_answer score = answer.get('score', 0) if is_correct else 0 @@ -205,7 +206,8 @@ async def save_answers(request: SaveAnswersRequest): 'userAnswer': user_answer, 'correctAnswer': correct_answer, 'isCorrect': is_correct, - 'score': score + 'score': score, + 'options': options # 保存选项数据 }) # 将整个答题数据保存为JSON @@ -524,49 +526,40 @@ async def get_quiz_results(session_id: str): # 合并题目数据和答题结果 detailed_results = [] for i, answer in enumerate(answers_data): - # 找到对应的题目 - question = None - for q in selected_questions: - if q['questionId'] == answer['questionId']: - question = q - break + # 优先使用保存的选项数据 + options = answer.get('options', {}) - # 如果找不到完整题目数据,使用答题数据中的基本信息 - if not question: - detailed_results.append({ - 'questionNumber': i + 1, - 'questionText': answer['questionText'], - 'questionType': answer['questionType'], - 'options': {}, # 空选项,因为没有完整题目数据 - 'userAnswer': answer['userAnswer'], - 'correctAnswer': answer['correctAnswer'], - 'isCorrect': answer['isCorrect'], - 'score': answer['score'], - 'questionId': answer['questionId'] - }) - else: - # 获取所有选项 - options = {} - labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] - for label in labels: - for key in question: - # 使用正则表达式来匹配选项键 - import re - if re.sub(r'\s+', '', key).find(f'选项{label}') != -1: - options[label] = question[key] - break + # 如果保存的选项数据为空,尝试从Excel数据中获取 + if not options: + # 找到对应的题目 + question = None + for q in selected_questions: + if q['questionId'] == answer['questionId']: + question = q + break - detailed_results.append({ - 'questionNumber': i + 1, - 'questionText': question['题干'], - 'questionType': question['questionType'], - 'options': options, - 'userAnswer': answer['userAnswer'], - 'correctAnswer': answer['correctAnswer'], - 'isCorrect': answer['isCorrect'], - 'score': answer['score'], - 'questionId': answer['questionId'] - }) + if question: + # 获取所有选项 + labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] + for label in labels: + for key in question: + # 使用正则表达式来匹配选项键 + import re + if re.sub(r'\s+', '', key).find(f'选项{label}') != -1: + options[label] = question[key] + break + + detailed_results.append({ + 'questionNumber': i + 1, + 'questionText': answer['questionText'], + 'questionType': answer['questionType'], + 'options': options, # 使用保存的选项数据或重新获取的数据 + 'userAnswer': answer['userAnswer'], + 'correctAnswer': answer['correctAnswer'], + 'isCorrect': answer['isCorrect'], + 'score': answer['score'], + 'questionId': answer['questionId'] + }) conn.close() @@ -684,8 +677,13 @@ async def quiz_results_page(session_id: str, request: Request): raise HTTPException(status_code=404, detail="会话不存在") # 生成答题结果页面 - html_content = generate_quiz_results_page(session_data, session_id) - return Response(content=html_content, media_type="text/html; charset=utf-8") + return templates.TemplateResponse("quiz-results.html", { + "request": request, + "session_id": session_id, + "student_name": session_data['name'], + "school": session_data['school'], + "grade": session_data['grade'] + }) except HTTPException: raise @@ -715,802 +713,25 @@ async def quiz_page(session_id: str, request: Request): # 检查会话状态 if session_data['status'] in ['completed', 'can_regenerate']: # 显示完成状态页面 - html_content = generate_completion_page(session_data, session_id) + return templates.TemplateResponse("completion.html", { + "request": request, + "session_id": session_id, + "student_name": session_data['name'], + "school": session_data['school'], + "grade": session_data['grade'], + "total_score": session_data['total_score'] or 0, + "completed_at": session_data['completed_at'] or '未知时间' + }) else: # 显示答题页面 - html_content = generate_quiz_page(session_data, session_id) - - return Response(content=html_content, media_type="text/html; charset=utf-8") + return templates.TemplateResponse("quiz.html", { + "request": request, + "session_id": session_id, + "student_name": session_data['name'], + "school": session_data['school'], + "grade": session_data['grade'] + }) -def generate_quiz_page(session_data: sqlite3.Row, session_id: str) -> str: - """生成答题页面HTML""" - questions_config = json.loads(session_data['questions_config']) - student_name = session_data['name'] - school = session_data['school'] - grade = session_data['grade'] - - return f''' - - - - - {student_name} - 学科能力测评 - - - -
-
-

🎯 学科能力测评

-

请认真回答以下问题

-
- -
-
-
-
姓名
-
{student_name}
-
-
-
学校
-
{school}
-
-
-
年级
-
{grade}
-
-
-
选题范围
-
正在加载...
-
-
-
- -
-
-
- -
-
正在加载题目...
-
- -
-
-
🎉
-
0分
-
测评完成!
-
- -
-
-
-
-
-
智能分析报告生成中
-
系统正在基于您的答题情况,AI正在深度分析并生成个性化学习建议...
-
-
- -
-
-
-
-
-
- AI正在分析中... -
- -
- - 📊 立即查看答题结果 - -
- 💡 您现在就可以查看详细的答题情况,AI报告生成完成后将在这里显示 -
-
-
-
-
-
- - - -''' @app.post("/api/report-callback", response_model=ApiResponse) async def report_callback(request: ReportCallbackRequest): @@ -1586,959 +807,7 @@ async def report_callback(request: ReportCallbackRequest): print(f"❌ 回调处理失败: {e}") raise HTTPException(status_code=500, detail=f"回调处理失败: {str(e)}") -def generate_completion_page(session_data: sqlite3.Row, session_id: str) -> str: - """生成答题完成页面HTML""" - student_name = session_data['name'] - school = session_data['school'] - grade = session_data['grade'] - total_score = session_data['total_score'] or 0 - completed_at = session_data['completed_at'] or '未知时间' - - return f''' - - - - - {student_name} - 测评已完成 - - - -
-
-

测评已完成!

- -
-
- 姓名: - {student_name} -
-
- 学校: - {school} -
-
- 年级: - {grade} -
-
- 完成时间: - {completed_at} -
-
- -
-
{total_score} 分
-
本次测评得分
-
- -
- 恭喜您完成了本次学科能力测评!
- 系统正在为您生成详细的个性化报告,请稍后查看。 -
- - - - - - -
- -''' -def generate_quiz_results_page(session_data: sqlite3.Row, session_id: str) -> str: - """生成答题结果详情页面HTML""" - student_name = session_data['name'] - school = session_data['school'] - grade = session_data['grade'] - - return f''' - - - - - {student_name} - 答题结果详情 - - - -
-
-

📊 答题结果详情

-

查看每道题的答题情况和正确答案

-
- -
-
-
-
姓名
-
{student_name}
-
-
-
学校
-
{school}
-
-
-
年级
-
{grade}
-
-
-
选题范围
-
正在加载...
-
-
-
- -
-
-
正在计算...
-
- 得分 / ...分 -
-
-
测评成绩
-
- 0 题正确 / - 0 题已答 - (共 0 题) - (正确率: 0%) -
-
- -
-
正在加载答题结果...
-
- -
- - -
-
- - - -''' if __name__ == "__main__": import uvicorn diff --git a/public/completion.html b/public/completion.html new file mode 100644 index 0000000..cd72f77 --- /dev/null +++ b/public/completion.html @@ -0,0 +1,306 @@ + + + + + + {{student_name}} - 测评已完成 + + + +
+
+

测评已完成!

+ +
+
+ 姓名: + {{student_name}} +
+
+ 学校: + {{school}} +
+
+ 年级: + {{grade}} +
+
+ 完成时间: + {{completed_at}} +
+
+ +
+
{{total_score}} 分
+
本次测评得分
+
+ +
+ 恭喜您完成了本次学科能力测评!
+ 系统正在为您生成详细的个性化报告,请稍后查看。 +
+ + + + + + +
+ + \ No newline at end of file diff --git a/public/quiz-results.html b/public/quiz-results.html new file mode 100644 index 0000000..3e5ddd1 --- /dev/null +++ b/public/quiz-results.html @@ -0,0 +1,672 @@ + + + + + + {{student_name}} - 答题结果详情 + + + +
+
+

📊 答题结果详情

+

查看每道题的答题情况和正确答案

+
+ +
+
+
+
姓名
+
{{student_name}}
+
+
+
学校
+
{{school}}
+
+
+
年级
+
{{grade}}
+
+
+
选题范围
+
正在加载...
+
+
+
+ +
+
+
正在计算...
+
+ 得分 / ...分 +
+
+
测评成绩
+
+ 0 题正确 / + 0 题已答 + (共 0 题) + (正确率: 0%) +
+
+ + +
+
+ +
+
正在加载答题结果...
+
+
+ + + + \ No newline at end of file diff --git a/public/quiz.html b/public/quiz.html new file mode 100644 index 0000000..af6a222 --- /dev/null +++ b/public/quiz.html @@ -0,0 +1,800 @@ + + + + + + {{student_name}} - 学科能力测评 + + + +
+
+

🎯 学科能力测评

+

请认真回答以下问题

+
+ +
+
+
+
姓名
+
{{student_name}}
+
+
+
学校
+
{{school}}
+
+
+
年级
+
{{grade}}
+
+
+
选题范围
+
正在加载...
+
+
+
+ +
+
+
+ +
+
正在加载题目...
+
+ +
+
+
🎉
+
0分
+
测评完成!
+
+ +
+
+
+
+
+
智能分析报告生成中
+
系统正在基于您的答题情况,AI正在深度分析并生成个性化学习建议...
+
+
+ +
+
+
+
+
+
+ AI正在分析中... +
+ +
+ + 📊 立即查看答题结果 + +
+ 💡 您现在就可以查看详细的答题情况,AI报告生成完成后将在这里显示 +
+
+
+
+
+
+ + + + \ No newline at end of file