diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 04189af6a..2c70757fa 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -437,6 +437,7 @@ class ExerciseController < ApplicationController @uncomplete_question = get_uncomplete_question(@exercise, User.current) # 获取改学生的考试得分 @score = calculate_student_score(@exercise, User.current) + # @score = 100 if @uncomplete_question.count < 1 # 查看是否有已提交记录 eu = get_exercise_user(@exercise.id, User.current.id) @@ -461,22 +462,38 @@ class ExerciseController < ApplicationController # 计算学生得分 def calculate_student_score(exercise, user) score = 0 + score1 = 0 + score2 = 0 + score3 = 0 exercise_qustions = exercise.exercise_questions exercise_qustions.each do |question| answer = get_user_answer(question, user) standard_answer = get_user_standard_answer(question, user) - # 问答题有多个答案 - if question.question_type == 3 - if standard_answer.include?(answer.exercise_choice_id) - score += question.question_score unless question.question_score.empty? - end - else - if answer.exercise_choice_id == standard_answer.exercise_choice_id - score += question.question_score unless question.question_score.empty? + unless answer.nil? + # 问答题有多个答案 + if question.question_type == 3 + if standard_answer.include?(answer.first.answer_text) + score1 = score+ question.question_score unless question.question_score.nil? + end + elsif question.question_type == 1 + if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id + score2 = score + question.question_score unless question.question_score.nil? + end + else + ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) + arr = [] + ecs.each do |ec| + arr << ec.exercise_choice.choice_position + end + arr.sort + arr = arr.join("") + if arr.to_i == standard_answer.exercise_choice_id + score3 = score + question.question_score unless question.question_score.nil? + end end end end - score + score = score1 + score2 + score3 end private @@ -495,7 +512,7 @@ class ExerciseController < ApplicationController uncomplete_question = [] all_questions.each do |question| answers = get_user_answer(question, user) - if answers.nil? || answers.count < 1 + if answers.nil? uncomplete_question << question end end @@ -504,6 +521,7 @@ class ExerciseController < ApplicationController # 获取当前学生回答问题的答案 def get_user_answer(question,user) + # user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") user_answer end @@ -516,7 +534,7 @@ class ExerciseController < ApplicationController standard_answer << answer.answer_text end else - standard_answer = question.exercise_standard_answers + standard_answer = question.exercise_standard_answers.first end standard_answer end diff --git a/app/views/exercise/_exercise_teacher.html.erb b/app/views/exercise/_exercise_teacher.html.erb index 606b14aae..a3f6380cf 100644 --- a/app/views/exercise/_exercise_teacher.html.erb +++ b/app/views/exercise/_exercise_teacher.html.erb @@ -54,7 +54,7 @@
">

多选题

- <% mcq_question_list.each_with_index do |exercise_question, index| %> + <% mcq_question_list.each_with_index do |exercise_question, list_index| %>