试卷统计列表的优化

dev_forum
cxt 6 years ago
parent 4043de1dd0
commit 4482276cbd

@ -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

Loading…
Cancel
Save