|
|
|
@ -14,19 +14,19 @@ namespace :excellent_course_exercise do
|
|
|
|
|
course = Course.find_by(id: course_id)
|
|
|
|
|
|
|
|
|
|
course.exercises.each_with_index do |exercise, index|
|
|
|
|
|
# if exercise.exercise_users.where(commit_status: 1).count == 0
|
|
|
|
|
if exercise.exercise_users.where(commit_status: 1).count == 0
|
|
|
|
|
# 第一个试卷的参与人数和通过人数都是传的数据,后续的随机
|
|
|
|
|
if index == 0
|
|
|
|
|
members = course.students.order("id asc").limit(participant_count)
|
|
|
|
|
update_exercise_user(exercise, members, pass_count)
|
|
|
|
|
else
|
|
|
|
|
new_participant_count = rand((participant_count - 423)..participant_count)
|
|
|
|
|
new_pass_count = rand((new_participant_count - 113)..new_participant_count)
|
|
|
|
|
new_participant_count = rand((participant_count - 20)..participant_count)
|
|
|
|
|
new_pass_count = rand((new_participant_count - 30)..new_participant_count)
|
|
|
|
|
|
|
|
|
|
members = course.students.order("id asc").limit(new_participant_count)
|
|
|
|
|
update_exercise_user(exercise, members, new_pass_count)
|
|
|
|
|
end
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -36,14 +36,15 @@ namespace :excellent_course_exercise do
|
|
|
|
|
# index < pass_count 之前的学生都是通关的,之后的未通过
|
|
|
|
|
members.each_with_index do |member, index|
|
|
|
|
|
exercise_user = exercise.exercise_users.where(user_id: member.user_id).take
|
|
|
|
|
if exercise_question_ids.length == 20
|
|
|
|
|
question_length = exercise_question_ids.length
|
|
|
|
|
if question_length == 20
|
|
|
|
|
rand_num = index < pass_count - 1 ? rand(15..20) : rand(1..10)
|
|
|
|
|
elsif exercise_question_ids.length == 17
|
|
|
|
|
elsif question_length == 17
|
|
|
|
|
rand_num = index < pass_count - 1 ? rand(12..17) : rand(1..9)
|
|
|
|
|
elsif exercise_question_ids.length == 39
|
|
|
|
|
elsif question_length == 39
|
|
|
|
|
rand_num = index < pass_count - 1 ? rand(30..39) : rand(1..18)
|
|
|
|
|
else
|
|
|
|
|
rand_num = exercise_question_ids.length
|
|
|
|
|
rand_num = index < pass_count - 1 ? rand((question_length-3)..question_length) : rand(1..(question_length-8))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if exercise_user && exercise_user.commit_status == 0
|
|
|
|
|