|
|
|
@ -70,13 +70,13 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
|
|
|
|
|
question_standard_answer.save
|
|
|
|
|
if standard_answer.count > 1 && ques_type == 0 #当标准答案数大于1,且不为多选时,修改为多选
|
|
|
|
|
@exercise_question.update_attribute("question_type",1)
|
|
|
|
|
elsif standard_answer.count == 1 && ques_type == 1
|
|
|
|
|
@exercise_question.update_attribute("question_type",0)
|
|
|
|
|
if standard_answer.count > 1 && ques_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选
|
|
|
|
|
@exercise_question.update_attribute("question_type",Exercise::MULTIPLE)
|
|
|
|
|
elsif standard_answer.count == 1 && ques_type == Exercise::MULTIPLE
|
|
|
|
|
@exercise_question.update_attribute("question_type",Exercise::SINGLE)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elsif ques_type == 2 #这个为判断题
|
|
|
|
|
elsif ques_type == Exercise::JUDGMENT #这个为判断题
|
|
|
|
|
choices_array = params[:question_choices] #判断的选项,对/错等等
|
|
|
|
|
choices_count= choices_array.count
|
|
|
|
|
(1..choices_count).each do |c|
|
|
|
|
@ -95,7 +95,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
|
|
|
|
|
question_standard_answer.save
|
|
|
|
|
elsif ques_type == 3 #填空题,每空的参考答案有多个,那么以位置对应
|
|
|
|
|
elsif ques_type == Exercise::COMPLETION #填空题,每空的参考答案有多个,那么以位置对应
|
|
|
|
|
standard_answer = params[:standard_answers]
|
|
|
|
|
standard_answer.each do |a|
|
|
|
|
|
null_choice_id = a[:choice_id]
|
|
|
|
@ -110,7 +110,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
question_standard_answer.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elsif ques_type == 4 #简答题
|
|
|
|
|
elsif ques_type == Exercise::SUBJECTIVE #简答题
|
|
|
|
|
if params[:standard_answers].present? && params[:standard_answers].reject(&:blank?).count > 0
|
|
|
|
|
standard_answer = params[:standard_answers]
|
|
|
|
|
standard_answer.each do |a|
|
|
|
|
@ -122,7 +122,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
question_standard_answer.save
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
elsif ques_type == 5 #实训题
|
|
|
|
|
elsif ques_type == Exercise::PRACTICAL #实训题
|
|
|
|
|
shixun = Shixun.find_by(id: params[:shixun_id])
|
|
|
|
|
shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组
|
|
|
|
|
shixun_name = params[:shixun_name] || shixun.name
|
|
|
|
@ -225,7 +225,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
#试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案
|
|
|
|
|
@exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案
|
|
|
|
|
if standard_answer.present?
|
|
|
|
|
if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个
|
|
|
|
|
if @exercise_question.question_type <= Exercise::JUDGMENT #选择题/判断题,标准答案为一个或多个
|
|
|
|
|
exercise_standard_choices = @exercise_answers_array.pluck(:exercise_choice_id) #问题以前的全部标准答案选项位置
|
|
|
|
|
common_standard_choices = standard_answer & exercise_standard_choices # 传入的标准答案的选项位置和以前的并集,即表示不用做更改的
|
|
|
|
|
old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉
|
|
|
|
@ -244,12 +244,12 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
if standard_answer.count > 1 && @exercise_question.question_type == 0 #当标准答案数大于1,且不为多选时,修改为多选
|
|
|
|
|
@exercise_question.update_attribute("question_type",1)
|
|
|
|
|
elsif standard_answer.count == 1 && @exercise_question.question_type == 1
|
|
|
|
|
@exercise_question.update_attribute("question_type",0)
|
|
|
|
|
if standard_answer.count > 1 && @exercise_question.question_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选
|
|
|
|
|
@exercise_question.update_attribute("question_type",Exercise::MULTIPLE)
|
|
|
|
|
elsif standard_answer.count == 1 && @exercise_question.question_type == Exercise::MULTIPLE
|
|
|
|
|
@exercise_question.update_attribute("question_type",Exercise::SINGLE)
|
|
|
|
|
end
|
|
|
|
|
elsif @exercise_question.question_type == 3 #填空题
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::COMPLETION #填空题
|
|
|
|
|
old_ex_answer = @exercise_question.exercise_standard_answers #当前问题的全部标准答案
|
|
|
|
|
old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_choice_id).uniq #全部的答案数组序号
|
|
|
|
|
new_ex_answer_choice_ids = standard_answer.map {|a| a[:choice_id]}.uniq #新传入的答案数组序号
|
|
|
|
@ -321,7 +321,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if @exercise_question.question_type == 4 #主观题
|
|
|
|
|
if @exercise_question.question_type == Exercise::SUBJECTIVE #主观题
|
|
|
|
|
main_standard_answer = standard_answer.present? ? standard_answer.first : nil
|
|
|
|
|
if @exercise_answers_array.present?
|
|
|
|
|
@exercise_answers_array.first.update_attribute("answer_text",main_standard_answer)
|
|
|
|
@ -333,7 +333,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
|
|
|
|
|
question_standard_answer.save
|
|
|
|
|
end
|
|
|
|
|
elsif @exercise_question.question_type == 5
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::PRACTICAL
|
|
|
|
|
question_score = 0
|
|
|
|
|
shixun_name = params[:shixun_name] || @exercise_question.shixun_name
|
|
|
|
|
@exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index|
|
|
|
|
@ -347,7 +347,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
|
|
|
|
|
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
|
|
|
|
|
|
|
|
|
|
if @exercise.exercise_status == 2
|
|
|
|
|
if @exercise.exercise_status == Exercise::PUBLISHED
|
|
|
|
|
ex_users_committed = @exercise.exercise_users.exercise_user_committed
|
|
|
|
|
if ex_users_committed.size > 0
|
|
|
|
|
ex_users_committed.each do |ex_user|
|
|
|
|
@ -375,7 +375,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
begin
|
|
|
|
|
opr = params[:opr]
|
|
|
|
|
current_q_p = @exercise_question.question_number.to_i #问题的当前位置
|
|
|
|
|
if @exercise.exercise_status.to_i == 1
|
|
|
|
|
if @exercise.exercise_status.to_i == Exercise::UNPUBLISHED
|
|
|
|
|
if opr.present?
|
|
|
|
|
if opr.to_s == "up"
|
|
|
|
|
last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题
|
|
|
|
@ -457,7 +457,7 @@ 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 == 3 #当为填空题,更新问题的总分,
|
|
|
|
|
if @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
|
|
|
|
@ -468,8 +468,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
@exercise_current_user.update_attributes(ex_scores)
|
|
|
|
|
ex_answers.update_all(:score => each_right_score) #所有的正确选项需重新更新
|
|
|
|
|
elsif @exercise_question.question_type == 4 #当为主观题时
|
|
|
|
|
if ex_answers.present?
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::SUBJECTIVE #当为主观题时
|
|
|
|
|
if ex_answers.exists?
|
|
|
|
|
ex_answers_old_score = ex_answers.first.score > 0.0 ? ex_answers.first.score : 0.0 #原分数小于0,取0
|
|
|
|
|
new_sub_score = ex_subj_score - ex_answers_old_score + @c_score #原全部主观题总分减去原该主观题得分再加调分后的分数,即为当前全部主观题得分
|
|
|
|
|
ex_answers.first.update_attribute("score",@c_score)
|
|
|
|
@ -481,7 +481,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
:answer_text => ""
|
|
|
|
|
}
|
|
|
|
|
ExerciseAnswer.create(answer_option)
|
|
|
|
|
new_sub_score = @c_score
|
|
|
|
|
new_sub_score = ex_subj_score + @c_score
|
|
|
|
|
end
|
|
|
|
|
total_scores = ex_obj_score + new_sub_score
|
|
|
|
|
ex_scores = {
|
|
|
|
@ -490,8 +490,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
}
|
|
|
|
|
@exercise_current_user.update_attributes(ex_scores)
|
|
|
|
|
|
|
|
|
|
elsif @exercise_question.question_type == 5
|
|
|
|
|
# ex_answers = @exercise_question.exercise_shixun_answers.search_shixun_answers("user_id",@user_id).search_shixun_answers("exercise_shixun_challenge_id",@shixun_a_id)
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::PRACTICAL
|
|
|
|
|
ex_answers = @exercise_question.exercise_shixun_answers.where(user_id:@user_id,exercise_shixun_challenge_id:@shixun_a_id)
|
|
|
|
|
|
|
|
|
|
if ex_answers.present? #当为实训题时
|
|
|
|
@ -622,13 +621,13 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def check_exercise_status
|
|
|
|
|
normal_status(-1,"不能更改试卷问题!") if @exercise.exercise_status != 1
|
|
|
|
|
normal_status(-1,"不能更改试卷问题!") if @exercise.exercise_status != Exercise::UNPUBLISHED
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#更新时不能修改的内容
|
|
|
|
|
def cannot_change_column
|
|
|
|
|
#已发布的/已截止的/评阅中的状态时,不能修改分数,不能增删问题和答案,不能修改标准答案,可以修改选项内容/题目内容,这里仅指单个问题
|
|
|
|
|
if @exercise.exercise_status != 1
|
|
|
|
|
if @exercise.exercise_status != Exercise::UNPUBLISHED
|
|
|
|
|
question_score = @exercise_question.question_score #原来的分数
|
|
|
|
|
update_question_score = params[:question_score].to_f.round(1) #传入的分数
|
|
|
|
|
choices_count = @exercise_question.exercise_choices.size #原来的选项个数
|
|
|
|
@ -641,12 +640,12 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
elsif update_choices_count != choices_count #选项个数有修改
|
|
|
|
|
normal_status(-1,"已发布/已截止,不允许增删答案!")
|
|
|
|
|
elsif standard_answer.present?
|
|
|
|
|
if @exercise_question.question_type == 3
|
|
|
|
|
if @exercise_question.question_type == Exercise::COMPLETION
|
|
|
|
|
exercise_answers_text = standard_answer.map{|a| a[:answer_text]}.sum.uniq
|
|
|
|
|
unless (standard_answer.count == exercise_choice_ids.count) && (standard_answers_text.count == exercise_answers_text.count)
|
|
|
|
|
normal_status(-1,"已发布/已截止,不允许增删标准答案!")
|
|
|
|
|
end
|
|
|
|
|
elsif @exercise_question.question_type == 4
|
|
|
|
|
elsif @exercise_question.question_type == Exercise::SUBJECTIVE
|
|
|
|
|
unless standard_answers_text.count == standard_answer.count
|
|
|
|
|
normal_status(-1,"已发布/已截止,不允许增删标准答案!")
|
|
|
|
|
end
|
|
|
|
@ -663,13 +662,13 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
normal_status(-1,"用户不存在!")
|
|
|
|
|
elsif @c_score.blank?
|
|
|
|
|
normal_status(-1,"分数不能为空!")
|
|
|
|
|
elsif @exercise_question.question_type <= 1 || @exercise_question.question_type == 2
|
|
|
|
|
elsif @exercise_question.question_type <= Exercise::JUDGMENT
|
|
|
|
|
normal_status(-1,"选择题/判断题不能调分!")
|
|
|
|
|
elsif params[:comment].present? && params[:comment].length > 100
|
|
|
|
|
normal_status(-1,"评语不能超过100个字符!")
|
|
|
|
|
else
|
|
|
|
|
@shixun_a_id = params[:shixun_challenge_id]
|
|
|
|
|
if @exercise_question.question_type == 5 #当为实训题时,为关卡的分数
|
|
|
|
|
if @exercise_question.question_type == Exercise::PRACTICAL #当为实训题时,为关卡的分数
|
|
|
|
|
@shixun_challenge = @exercise_question.exercise_shixun_challenges.cha_id_find(@shixun_a_id)
|
|
|
|
|
if @shixun_challenge.present?
|
|
|
|
|
@old_ques_score = @shixun_challenge.first.question_score
|
|
|
|
|