多选题的调分

dev_cs
cxt 5 years ago
parent 6f68c79f18
commit 2366b4d590

@ -497,7 +497,38 @@ class ExerciseQuestionsController < ApplicationController
ex_obj_score = @exercise_current_user.objective_score #全部客观题得分
ex_subj_score = @exercise_current_user.subjective_score < 0.0 ? 0.0 : @exercise_current_user.subjective_score #全部主观题得分
ex_answers = @exercise_question.exercise_answers.search_answer_users("user_id",@user_id) #当前用户答案的得分
if @exercise_question.question_type == Exercise::COMPLETION #当为填空题,更新问题的总分,
if @exercise_question.question_type == Exercise::MULTIPLE
if ex_answers.present? #学生有回答时 取学生的答题得分否则0分
answer_choice_array = []
ex_answers.each do |a|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
end
user_answer_content = answer_choice_array.sort
standard_answer = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).sort
if standard_answer.size == 1 # 老数据需要判断学生答题是否正确, 正确取原题得分否则是0分
standard_answer = standard_answer.first.to_s.split("").map(&:to_i).sort
if user_answer_content == standard_answer
ex_answer_old = @exercise_question.question_score
else
ex_answer_old = 0
end
else # 新多选题只需取第一条答题记录的得分
ex_answer_old = ex_answers.first.score > 0 ? ex_answers.first.score : 0
end
else
ex_answer_old = 0
end
new_obj_score = ex_obj_score - ex_answer_old + @c_score
total_scores = new_obj_score + ex_subj_score
ex_scores = {
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
ex_answers.update_all(:score => @c_score) #所有的正确选项需重新更新
elsif @exercise_question.question_type == Exercise::COMPLETION #当为填空题,更新问题的总分,
ex_answer_old = ex_answers.score_reviewed.pluck(:score).sum #每一关的得分总和
each_right_score = (@c_score / ex_answers.count.to_f) #调分后,平均每关的分数
new_obj_score = ex_obj_score - ex_answer_old + @c_score
@ -579,7 +610,7 @@ class ExerciseQuestionsController < ApplicationController
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("没有权限")
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
@ -703,8 +734,8 @@ class ExerciseQuestionsController < ApplicationController
normal_status(-1,"用户不存在!")
elsif @c_score.blank?
normal_status(-1,"分数不能为空!")
elsif @exercise_question.question_type <= Exercise::JUDGMENT
normal_status(-1,"题/判断题不能调分!")
elsif @exercise_question.question_type == Exercise::SINGLE || @exercise_question.question_type == Exercise::JUDGMENT
normal_status(-1,"选题/判断题不能调分!")
elsif params[:comment].present? && params[:comment].length > 100
normal_status(-1,"评语不能超过100个字符!")
else

Binary file not shown.
Loading…
Cancel
Save