From b5ea3a60ca8536d65972cdea58025ed39778681c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:03:01 +0800 Subject: [PATCH] fixbug --- app/helpers/exercises_helper.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index f5d341aae..8b0ad2ad5 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,17 +113,35 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - - #计算每个问题的答案人数 - # commit_users.transaction do - # + # if ex.question_type == Exercise::MULTIPLE #多选题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # else #单选题和判断题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end # end user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + if ex.question_type == Exercise::MULTIPLE + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + else + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + if [answer_choice_array] == standard_answer + right_users_count += 1 + end 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| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置