feat: add problem name distribution and problem×class matrix to statistics
This commit is contained in:
@@ -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],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user