|
|
@ -355,9 +355,9 @@ module ExercisesHelper
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
exercise_questions.each do |q|
|
|
|
|
exercise_questions.each do |q|
|
|
|
|
if q.question_type != 5
|
|
|
|
if q.question_type != 5
|
|
|
|
answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案
|
|
|
|
answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案
|
|
|
|
else
|
|
|
|
else
|
|
|
|
answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案
|
|
|
|
answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if q.question_type <= 2 #为选择题或判断题时
|
|
|
|
if q.question_type <= 2 #为选择题或判断题时
|
|
|
|
if answers_content.present? #学生有回答时
|
|
|
|
if answers_content.present? #学生有回答时
|
|
|
@ -369,11 +369,11 @@ module ExercisesHelper
|
|
|
|
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
|
|
|
|
standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个
|
|
|
|
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
|
|
|
|
if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分
|
|
|
|
if standard_answer.count > 0
|
|
|
|
if standard_answer.count > 0
|
|
|
|
q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。
|
|
|
|
multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。
|
|
|
|
else
|
|
|
|
else
|
|
|
|
q_score_1 = 0.0
|
|
|
|
multi_each_score = 0.0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
answers_content.update_all(:score => q_score_1)
|
|
|
|
answers_content.update_all(:score => multi_each_score)
|
|
|
|
score1 = score1 + q.question_score
|
|
|
|
score1 = score1 + q.question_score
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -424,7 +424,7 @@ module ExercisesHelper
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
|
|
|
|
ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id)
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里
|
|
|
|
cha_path = challenge_path exercise_cha.challenge&.path
|
|
|
|
cha_path = challenge_path(exercise_cha.challenge&.path)
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
|
|
|
|
game_challenge = game.game_codes.search_challenge_path(cha_path)&.first
|
|
|
|
if game_challenge.present?
|
|
|
|
if game_challenge.present?
|
|
|
|
game_code = game_challenge
|
|
|
|
game_code = game_challenge
|
|
|
@ -682,16 +682,26 @@ module ExercisesHelper
|
|
|
|
def get_exercise_left_time(exercise,user)
|
|
|
|
def get_exercise_left_time(exercise,user)
|
|
|
|
ex_time = exercise.time
|
|
|
|
ex_time = exercise.time
|
|
|
|
user_left_time = nil
|
|
|
|
user_left_time = nil
|
|
|
|
|
|
|
|
time_now_i = Time.now.to_i
|
|
|
|
if ex_time > 0
|
|
|
|
if ex_time > 0
|
|
|
|
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
|
|
|
|
exercise_user = exercise.exercise_users.find_by(user_id:user.id)
|
|
|
|
time_mill = ex_time * 60 #转为秒
|
|
|
|
time_mill = ex_time * 60 #转为秒
|
|
|
|
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
|
|
|
|
exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0
|
|
|
|
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0
|
|
|
|
exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0
|
|
|
|
if (exercise_user_start + time_mill) > exercise_end_time
|
|
|
|
#用户未开始答题时,即exercise_user_start为0
|
|
|
|
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
|
|
|
|
if exercise_user_start == 0
|
|
|
|
|
|
|
|
if (exercise_end_time - time_now_i) > time_mill
|
|
|
|
|
|
|
|
user_left_time = time_mill
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
user_left_time = (exercise_end_time < time_now_i) ? nil : (exercise_end_time - time_now_i)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if (exercise_user_start + time_mill) > exercise_end_time
|
|
|
|
|
|
|
|
time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
exercise_user_left_time = time_now_i - exercise_user_start #用户已回答的时间
|
|
|
|
|
|
|
|
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
|
|
|
|
end
|
|
|
|
end
|
|
|
|
exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间
|
|
|
|
|
|
|
|
user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
user_left_time
|
|
|
|
user_left_time
|
|
|
|
end
|
|
|
|
end
|
|
|
|