|
|
|
@ -494,6 +494,7 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
def adjust_score
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
ex_all_scores = @exercise.exercise_questions.pluck(:question_score).sum
|
|
|
|
|
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) #当前用户答案的得分
|
|
|
|
@ -501,9 +502,11 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
if ex_answers.present? #学生有回答时 取学生的答题得分,否则0分
|
|
|
|
|
answer_choice_array = []
|
|
|
|
|
ex_answers.each do |a|
|
|
|
|
|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
|
|
|
|
|
if a.try(:exercise_choice).try(:choice_position).present?
|
|
|
|
|
answer_choice_array.push(a&.exercise_choice&.choice_position) #学生答案的位置
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
user_answer_content = answer_choice_array.sort
|
|
|
|
|
user_answer_content = answer_choice_array.reject(&:blank?).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
|
|
|
|
@ -535,6 +538,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
total_scores = new_obj_score + ex_subj_score
|
|
|
|
|
if total_scores < 0.0
|
|
|
|
|
total_scores = 0.0
|
|
|
|
|
elsif total_scores > ex_all_scores
|
|
|
|
|
total_scores = ex_all_scores
|
|
|
|
|
end
|
|
|
|
|
ex_scores = {
|
|
|
|
|
:objective_score => new_obj_score,
|
|
|
|
@ -563,6 +568,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
total_scores = new_obj_score + ex_subj_score
|
|
|
|
|
if total_scores < 0.0
|
|
|
|
|
total_scores = 0.0
|
|
|
|
|
elsif total_scores > ex_all_scores
|
|
|
|
|
total_scores = ex_all_scores
|
|
|
|
|
end
|
|
|
|
|
ex_scores = {
|
|
|
|
|
:objective_score => new_obj_score,
|
|
|
|
@ -587,6 +594,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
total_scores = ex_obj_score + new_sub_score
|
|
|
|
|
if total_scores < 0.0
|
|
|
|
|
total_scores = 0.0
|
|
|
|
|
elsif total_scores > ex_all_scores
|
|
|
|
|
total_scores = ex_all_scores
|
|
|
|
|
end
|
|
|
|
|
ex_scores = {
|
|
|
|
|
:subjective_score => new_sub_score,
|
|
|
|
@ -615,6 +624,8 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
total_scores = new_obj_score + ex_subj_score
|
|
|
|
|
if total_scores < 0.0
|
|
|
|
|
total_scores = 0.0
|
|
|
|
|
elsif total_scores > ex_all_scores
|
|
|
|
|
total_scores = ex_all_scores
|
|
|
|
|
end
|
|
|
|
|
ex_scores = {
|
|
|
|
|
:objective_score => new_obj_score,
|
|
|
|
@ -623,23 +634,26 @@ class ExerciseQuestionsController < ApplicationController
|
|
|
|
|
@exercise_current_user.update_attributes(ex_scores)
|
|
|
|
|
end
|
|
|
|
|
comments = params[:comment]
|
|
|
|
|
question_comment = @exercise_question.exercise_answer_comments.first
|
|
|
|
|
question_comment = @exercise_question.exercise_answer_comments&.first
|
|
|
|
|
|
|
|
|
|
if question_comment.present?
|
|
|
|
|
comment_option = {
|
|
|
|
|
:comment => comments.present? ? comments : question_comment.comment,
|
|
|
|
|
:comment => comments,
|
|
|
|
|
:score => @c_score,
|
|
|
|
|
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil
|
|
|
|
|
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
|
|
|
|
|
:user_id => current_user.id
|
|
|
|
|
}
|
|
|
|
|
question_comment.update_attributes(comment_option)
|
|
|
|
|
@exercise_comments = question_comment
|
|
|
|
|
else
|
|
|
|
|
ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)
|
|
|
|
|
comment_option = {
|
|
|
|
|
:user_id => current_user.id,
|
|
|
|
|
:comment => comments,
|
|
|
|
|
:score => @c_score,
|
|
|
|
|
:exercise_question_id => @exercise_question.id,
|
|
|
|
|
:exercise_shixun_answer_id => @shixun_a_id.present? ? @shixun_a_id : nil,
|
|
|
|
|
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil
|
|
|
|
|
:exercise_answer_id => ex_answer_comment_id
|
|
|
|
|
}
|
|
|
|
|
@exercise_comments = ExerciseAnswerComment.new(comment_option)
|
|
|
|
|
@exercise_comments.save
|
|
|
|
|