diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index babdd50f7..3fc27c8f2 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -8,7 +8,7 @@ class ExerciseAnswersController < ApplicationController begin q_type = @exercise_question.question_type #试卷的类型 choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : "" - answer_text = params[:answer_text].present? ? params[:answer_text] : "" #为字符串 + answer_text = params[:answer_text].present? ? params[:answer_text].strip : "" #为字符串 if q_type < Exercise::SUBJECTIVE && (q_type != Exercise::MULTIPLE) && choice_id.blank? normal_status(-1,"请选择序号") else diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 58f3a7e71..4ce18b59d 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -361,7 +361,6 @@ class ExerciseQuestionsController < ApplicationController if ex_users_committed.size > 0 ex_users_committed.each do |ex_user| update_objective_score = update_single_score(@exercise_question,ex_user.user_id,standard_answer) - Rails.logger.info("#####_________update_objective_score___________##############{update_objective_score}") if update_objective_score != 0 objective_score = ex_user.objective_score new_objective_score = objective_score + update_objective_score @@ -369,9 +368,6 @@ class ExerciseQuestionsController < ApplicationController total_score = total_score < 0.0 ? 0.0 : total_score ex_user.update_attributes(objective_score:new_objective_score,score:total_score) end - Rails.logger.info("#####_________ex_user.score___________##############{ex_user.score}") - # user = ex_user.user - # objective_score = calculate_student_score(@exercise,user)[:total_score] end end normal_status(0,"试卷更新成功,因标准答案修改,需重新计算学生成绩!") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index d4ecf6d1a..7994e2c6a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -438,8 +438,8 @@ module ExercisesHelper end if q.is_ordered answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map{|a| a.strip.downcase} #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.strip.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 else @@ -448,9 +448,9 @@ module ExercisesHelper end end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map{|a| a.strip.downcase} answers_content.each do |u| - u_answer_text = u.answer_text.downcase + u_answer_text = u.answer_text.strip.downcase if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 u.update_column("score",q_score_2) score2 = score2 + q_score_2 @@ -582,8 +582,8 @@ module ExercisesHelper i_standard_answer += a[:answer_text] end end - i_standard_answer = i_standard_answer.map(&:downcase) - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + i_standard_answer = i_standard_answer.map{|a| a.strip.downcase} + if i_standard_answer.include?(u.answer_text.strip.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score1 = score1 + q_score_2 else @@ -592,7 +592,7 @@ module ExercisesHelper end end else - st_answer_text = standard_answer.pluck(:answer_text).sum.map(&:downcase) + st_answer_text = standard_answer.pluck(:answer_text).sum.map{|a| a.strip.downcase} answers_content.each do |u| u_answer_text = u.answer_text.downcase if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 diff --git a/db/migrate/20190822022306_add_exercise_user_update.rb b/db/migrate/20190822022306_add_exercise_user_update.rb index 059553306..f45e6a8ee 100644 --- a/db/migrate/20190822022306_add_exercise_user_update.rb +++ b/db/migrate/20190822022306_add_exercise_user_update.rb @@ -1,6 +1,7 @@ class AddExerciseUserUpdate < ActiveRecord::Migration[5.2] include ExercisesHelper def change + #2019,8,22添加 exs = Exercise.all.is_exercise_published.where("publish_time > ?",(Time.now - 2.months)).includes(:exercise_questions,:exercise_users) exs.each do |ex| ex_users = ex.exercise_users.exercise_user_committed.where("end_at is not null and end_at > ?",(Time.now - 2.months))