diff --git a/app/routes/students.py b/app/routes/students.py index 20b5d8b..8dba774 100644 --- a/app/routes/students.py +++ b/app/routes/students.py @@ -432,6 +432,25 @@ def get_student_statistics(): "problem_count": len(class_problems) }) + # 各问题名称分布 + problem_name_dist = {} + for p in problems: + name = p.problem.name if p.problem else f"问题{p.problem_id}" + if name not in problem_name_dist: + problem_name_dist[name] = 0 + problem_name_dist[name] += 1 + # 排序:数量多的在前 + problem_name_dist = dict(sorted(problem_name_dist.items(), key=lambda x: x[1], reverse=True)) + + # 问题×班级矩阵 + problem_class_matrix = [] + for p_name in problem_name_dist.keys(): + row = {"problem_name": p_name} + for c in classes: + count = sum(1 for p in problems if (p.problem.name if p.problem else f"问题{p.problem_id}") == p_name and p.student.class_id == c.id) + row[f"class_{c.id}"] = count + problem_class_matrix.append(row) + return jsonify({ "total_students": total_students, "total_problems": len(problems), @@ -440,4 +459,7 @@ def get_student_statistics(): "class_student_count": class_student_count, "class_problem_count": class_problem_count, "problem_level_matrix": matrix, + "problem_name_distribution": problem_name_dist, + "problem_class_matrix": problem_class_matrix, + "classes": [{"id": c.id, "name": c.name} for c in classes], }) diff --git a/app/templates/statistics.html b/app/templates/statistics.html index 3299c41..d700e81 100644 --- a/app/templates/statistics.html +++ b/app/templates/statistics.html @@ -81,6 +81,31 @@ + +