From 242371161075464cc2a4d685767f186ccc019775 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 13 Nov 2019 19:39:20 +0800 Subject: [PATCH] dd --- app/helpers/exercises_helper.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index ca1e01d40..1e0fc7d88 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -175,16 +175,18 @@ module ExercisesHelper all_user_count = 0 if ex_ordered - all_null_stand_choice = null_standard_answer.pluck(:exercise_choice_id,:answer_text) - all_null_stand_choice.each_with_index do |s,index| - # s_choice_text = null_stand_text[index] + all_user_answers = effictive_users.pluck(:answer_text) + 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.where("exercise_choice_id = ? and answer_text = ?",s[0],s[1]).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 + + # 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 = { :choice_position => index+1, - :choice_text => s[1], + :choice_text => s_choice_text, :choice_users_count => user_count, :choice_percent => answer_percent.round(2).to_s, :right_answer => true @@ -192,6 +194,7 @@ module ExercisesHelper question_answer_infos.push(answer_option) all_user_count += user_count standard_answer_count += 1 + all_user_answers = all_user_answers - [s] end else # cycled_stand = {}