dev_forum
SylorHuang 5 years ago
parent 88a85bff7d
commit e7da0d9be8

@ -1130,7 +1130,7 @@ class ExercisesController < ApplicationController
@is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0
@student_status = 2 @student_status = 2
# @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者
@exercise_questions = @exercise.exercise_questions.order("question_number ASC") @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC")
@question_status = [] @question_status = []
get_exercise_status = @exercise.get_exercise_status(current_user) get_exercise_status = @exercise.get_exercise_status(current_user)
if @ex_user.present? && @is_teacher_or == 0 if @ex_user.present? && @is_teacher_or == 0

@ -34,7 +34,6 @@ module ExercisesHelper
ques_score = answers_content.select(:score).pluck(:score).sum ques_score = answers_content.select(:score).pluck(:score).sum
end end
if ques_score >= q.question_score #满分作答为正确 if ques_score >= q.question_score #满分作答为正确
ques_score = q.question_score ques_score = q.question_score
stand_answer = 1 stand_answer = 1
@ -663,6 +662,7 @@ module ExercisesHelper
user_score = nil user_score = nil
shixun_type = 0 shixun_type = 0
question_comment = [] question_comment = []
# user_score_pre = nil
if ques_type == 5 if ques_type == 5
exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id)
else else
@ -670,10 +670,26 @@ module ExercisesHelper
end end
if student_status == 2 #当前为老师,或为学生且已提交 if student_status == 2 #当前为老师,或为学生且已提交
user_score_pre = exercise_answers.score_reviewed user_score_pre = exercise_answers.score_reviewed
if ques_type == 4 && user_score_pre.blank? #主观题时且没有大于0的分数时为空 if ques_type == 4 #主观题时且没有大于0的分数时为空
user_score = nil user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil
else elsif ques_type == 5 || ques_type == 3
user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0
else
if exercise_answers.present? #判断题和选择题时,
answer_choice_array = []
exercise_answers.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 #答案一致,多选或单选才给分,答案不对不给分
user_score = q.question_score
else
user_score = 0.0
end
else
user_score = 0.0
end
end end
end end
@ -681,9 +697,9 @@ module ExercisesHelper
user_score = q.question_score user_score = q.question_score
end end
if ques_type <= 2 if ques_type <= 2
answered_content = exercise_answers.pluck(:exercise_choice_id) answered_content = exercise_answers&.pluck(:exercise_choice_id)
elsif ques_type == 3 elsif ques_type == 3
exercise_answers.each do |a| exercise_answers&.each do |a|
u_answer = { u_answer = {
"choice_id":a.exercise_choice_id, "choice_id":a.exercise_choice_id,
"answer_text": a.answer_text "answer_text": a.answer_text
@ -691,7 +707,7 @@ module ExercisesHelper
answered_content.push(u_answer) answered_content.push(u_answer)
end end
elsif ques_type == 4 elsif ques_type == 4
answered_content = exercise_answers.pluck(:answer_text) answered_content = exercise_answers&.pluck(:answer_text)
end end
if ques_type == 5 #存在实训题,及已经做了实训题的 if ques_type == 5 #存在实训题,及已经做了实训题的
if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数 if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数

Loading…
Cancel
Save