|
|
|
@ -15,7 +15,7 @@ module ExercisesHelper
|
|
|
|
|
answers_content = q.exercise_answers.select{|answer| answer.user_id == user_id}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if q_type <= Exercise::JUDGMENT
|
|
|
|
|
if q_type <= Exercise::JUDGMENT || q_type == Exercise::PROGRAM
|
|
|
|
|
if answers_content.present? #学生有回答时,分数已经全部存到exercise_answer 表,多选题直接取第一个值,单选题和判断题选最后一个值(考虑并发)
|
|
|
|
|
ques_score = q_type == Exercise::MULTIPLE ? answers_content.first.score : answers_content.last.score
|
|
|
|
|
ques_score = ques_score < 0 ? 0.0 : ques_score
|
|
|
|
@ -454,6 +454,7 @@ module ExercisesHelper
|
|
|
|
|
score1 = 0.0 #选择题/判断题
|
|
|
|
|
score2 = 0.0 #填空题
|
|
|
|
|
score5 = 0.0 #实训题
|
|
|
|
|
score6 = 0.0 #编程题
|
|
|
|
|
ques_stand = [] #问题是否正确
|
|
|
|
|
exercise_end_time = end_time || Time.now
|
|
|
|
|
exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges)
|
|
|
|
@ -608,6 +609,34 @@ module ExercisesHelper
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elsif q.question_type == 6 #编程题
|
|
|
|
|
if answers_content.present?
|
|
|
|
|
score6 += answers_content.first.score
|
|
|
|
|
else
|
|
|
|
|
hack = q.hack
|
|
|
|
|
hack_user = hack&.hack_user_lastest_codes&.find_by(user_id: user.id)
|
|
|
|
|
if hack_user.present?
|
|
|
|
|
last_passed_code = hack_user.hack_user_codes.where("status = 0 and created_at < '#{exercise_end_time}'").last
|
|
|
|
|
if last_passed_code.present?
|
|
|
|
|
pro_score = q.question_score
|
|
|
|
|
code_content = last_passed_code.code
|
|
|
|
|
else
|
|
|
|
|
pro_score = 0
|
|
|
|
|
code_content = hack_user.hack_user_codes.where("created_at < '#{exercise_end_time}'").last&.code
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
pro_score = 0
|
|
|
|
|
code_content = nil
|
|
|
|
|
end
|
|
|
|
|
pro_option = {
|
|
|
|
|
:exercise_question_id => q.id,
|
|
|
|
|
:user_id => user.id,
|
|
|
|
|
:score => pro_score.round(1),
|
|
|
|
|
:answer_text => code_content
|
|
|
|
|
}
|
|
|
|
|
ExerciseAnswer.create(pro_option)
|
|
|
|
|
score6 += pro_score
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum
|
|
|
|
|
if user_scores > 0.0
|
|
|
|
@ -629,7 +658,7 @@ module ExercisesHelper
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
total_score = score1 + score2 + score5
|
|
|
|
|
total_score = score1 + score2 + score5 + score6
|
|
|
|
|
{
|
|
|
|
|
"total_score":total_score.round(1),
|
|
|
|
|
"stand_status":ques_stand
|
|
|
|
@ -923,10 +952,10 @@ module ExercisesHelper
|
|
|
|
|
elsif ques_type == 4
|
|
|
|
|
answered_content = exercise_answers&.pluck(:answer_text)
|
|
|
|
|
end
|
|
|
|
|
if ques_type == 5 #存在实训题,及已经做了实训题的
|
|
|
|
|
if ques_type == 5 || ques_type == 6 #存在实训题,及已经做了实训题的
|
|
|
|
|
if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数
|
|
|
|
|
shixun_type = 2
|
|
|
|
|
elsif ex_status == 2 && q.exercise_shixun_answers.present? #试卷未截止,且用户已回答的,则能看到答题的状态
|
|
|
|
|
elsif ex_status == 2 && (q.exercise_shixun_answers.present? || q.exercise_answers.present?) #试卷未截止,且用户已回答的,则能看到答题的状态
|
|
|
|
|
shixun_type =1
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|