From 4482276cbd2f067364a16d75423b91b260c1155d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Jul 2019 17:08:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 5ec9bcad4..6f30ba6c3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -103,9 +103,9 @@ module ExercisesHelper end effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 - ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 end @@ -116,15 +116,21 @@ module ExercisesHelper right_users_count = 0 #该问题的正确率 if ex.question_type == Exercise::MULTIPLE #多选题 - user_ids.each do |user_id| - 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.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 + right_user_ids = user_ids + standard_answer.each do |choice_position| + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first.id + right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) end + right_users_count = right_user_ids.size + # user_ids.each do |user_id| + # 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.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 else #单选题和判断题 - standard_answer_choice_id = ex.exercise_choices.find_by(choice_position: standard_answer.first)&.id + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first.id right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size end @@ -157,13 +163,7 @@ module ExercisesHelper user_count = 0 s_choice_text = null_stand_text[index] if ex_ordered #有序排列 - user_ids.each do |u| - user_answers = ex_answers.where(user_id:u,exercise_choice_id:s).select(:answer_text) - user_answers_choice = user_answers.exists? ? user_answers&.first&.answer_text.to_s : "" - if s_choice_text == user_answers_choice - user_count += 1 - end - end + user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.size else user_count = user_count + effictive_users.select{|answer| answer.answer_text == s_choice_text }.size #回答了标准答案的用户 end