diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..68be45660 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1040,6 +1040,7 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise_questions.order("question_number ASC") end # 判断问题是否已回答还是未回答 + @exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0b64cb916..25255de85 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -9,11 +9,32 @@ module ExercisesHelper @ex_obj_array = [] exercise_obj_status.each do |q| if q.question_type == 5 - ques_score = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id).pluck(:score).sum + answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum + answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) end + if q.question_type <= 2 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + ques_score = q.question_score + else + ques_score = 0.0 + end + else + ques_score = 0.0 + end + else + ques_score = answers_content.select(:score).pluck(:score).sum + end + + if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -370,7 +391,8 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + q_score_1 = q.question_score + # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else q_score_1 = 0.0 end