From a81d7e660962726e2eb778b912e4bb0b17af846f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 13 Nov 2019 16:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E7=A9=BA=E5=A1=AB=E7=A9=BA=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0229755e2..3301330b5 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -165,7 +165,6 @@ module ExercisesHelper end elsif ex.question_type == Exercise::COMPLETION #填空题 effictive_users_count = effictive_users.pluck(:user_id).uniq.size - ex_ordered = ex.is_ordered null_standard_answer = ex.exercise_standard_answers null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text @@ -178,7 +177,7 @@ module ExercisesHelper null_stand_choice.each_with_index do |s,index| s_choice_text = null_stand_text[index] user_count = 0 - user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.pluck(:user_id).uniq.size + user_count = user_count + effictive_users.where("exercise_choice_id = ? and answer_text = ?",s,s_choice_text).pluck(:user_id).uniq.size # user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.size answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3)) answer_option = { @@ -196,19 +195,7 @@ module ExercisesHelper # cycled_stand = {} null_stand_text.uniq.each_with_index do |stand, index| user_count = 0 - # if cycled_stand.length > 0 && cycled_stand.keys.include?(stand) - # cycled_stand.store(stand, cycled_stand["#{stand}"]) - # user_count = cycled_stand["#{stand}"] - # calculate_user_count = 0 - # else - # user_count = user_count + effictive_users.select{|answer| answer.answer_text == stand }.pluck(:user_id).uniq.size - # cycled_stand.store(stand, user_count) - # calculate_user_count = user_count - # end - user_count = user_count + effictive_users.select{|answer| answer.answer_text == stand }.pluck(:user_id).uniq.size - # cycled_stand.store(stand, user_count) - # calculate_user_count = user_count - + user_count = user_count + effictive_users.where("answer_text = ?",stand).pluck(:user_id).uniq.size answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3)) answer_option = { :choice_position => index+1, @@ -227,7 +214,7 @@ module ExercisesHelper # percent = commit_user_ids > 0 ? (all_user_count / commit_user_ids.to_f).round(3)*100 : 0.0 - user_wrong_count = (effictive_users_count - all_user_count) + user_wrong_count = effictive_users.where("score < 0").size if effictive_users_count > 0 && user_wrong_count >= 0 wrong_percent = (user_wrong_count / effictive_users_count.to_f ).round(3)