From 97229718991fbb9258a57083fea301c25be6941e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 15:30:25 +0800 Subject: [PATCH] fixbug --- app/helpers/exercises_helper.rb | 10 ++++++---- app/models/game.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b10dc128b..32e5d1bfc 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,7 +89,7 @@ module ExercisesHelper percent = 0.0 questions.includes(:exercise_choices).each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers.includes(:exercise_choice) + ex_answers = ex.exercise_answers if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -111,18 +111,20 @@ module ExercisesHelper question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 + ex_choices = ex.exercise_choices standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - user_ids.each do |user_id| - answer_choice_array = ex.exercise_choices.where(id:effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}).pluck(:choice_position).uniq + ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq + # answer_choice_array = ex_choices.where(id:ex_choice_ids).pluck(:choice_position) + answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - ex.exercise_choices.each do |c| + ex_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) answer_users_count = answer_this_choice.size diff --git a/app/models/game.rb b/app/models/game.rb index eed425ea6..002116748 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -31,7 +31,7 @@ class Game < ApplicationRecord # 根据得分比例来算实际得分(试卷、实训作业) def real_score score - final_score == challenge.score ? score : (final_score.to_f / challenge.score) * score + (final_score.to_f / challenge.all_score) * score end # 判断实训是否全部通关