main
Lyanling 2 months ago
parent 875b4ae9cf
commit 2be1529eee

@ -72,10 +72,10 @@ def roll_call(request):
# 当教师点击“开始点名”按钮时
if request.method == 'POST':
try:
data = json.loads(request.body) # 从请求中读取 JSON 数据
data = json.loads(request.body)
if data.get('start_roll_call') == 'true':
# 设置权重:总分越高,被点名的概率越低
weights = [1 / (student.score + 1) for student in students] # 根据分数调整被点名概率
weights = [1 / (student.score + 500) for student in students] # 根据分数调整被点名概率
selected_student = random.choices(students, weights=weights, k=1)[0] # 随机选择一个学生
request.session['selected_student_id'] = selected_student.student_id # 存储被点名学生的ID到session中
return JsonResponse({"message": "点名成功", "student_id": selected_student.student_id, "student_name": selected_student.name})

Loading…
Cancel
Save