From 29afe02630781fc034e2223441f06257fe975849 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 13 Nov 2019 15:42:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BF=AE=E6=94=B9=E5=A1=AB?= =?UTF-8?q?=E7=A9=BA=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 57c4c1aae..6d95f7c6f 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -178,7 +178,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.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.distinct.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 = { @@ -193,18 +193,21 @@ module ExercisesHelper standard_answer_count += 1 end else - cycled_stand = {} - null_stand_text.each_with_index do |stand, index| + # 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 + # 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 }.distinct.size + # cycled_stand.store(stand, user_count) + # calculate_user_count = user_count answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3)) answer_option = { @@ -215,7 +218,7 @@ module ExercisesHelper :right_answer => true } question_answer_infos.push(answer_option) - all_user_count += calculate_user_count + all_user_count += user_count standard_answer_count += 1 end end