dev_forum
SylorHuang 5 years ago
parent 5b9f9d38f9
commit 6d6098452f

@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController
@paging_type = params[:sort].to_s
end
ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users)
ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids)
if @paging_type == "percent"
@question_result_hash = ques_result_all.sort_by{|s| s[:percent]}

@ -84,12 +84,12 @@ module ExercisesHelper
end
#试卷的统计结果页面计算各题的
def exercise_commit_result(questions,user_ids,commit_users)
def exercise_commit_result(questions,user_ids)
question_infos = []
percent = 0.0
questions.each do |ex|
ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分
ex_answers = ex.exercise_answers
ex_answers = ex.exercise_answers.includes(:exercise_choice)
if ex.question_type != Exercise::PRACTICAL
ques_title = ex.question_title
ques_less_title = nil
@ -115,14 +115,15 @@ module ExercisesHelper
right_users_count = 0 #该问题的回答正确的人数
#计算每个问题的答案人数
commit_users.transaction do
commit_users.each do |user|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
# commit_users.transaction do
#
# end
user_ids.each do |user_id|
answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq
if answer_choice_array.sort == standard_answer
right_users_count += 1
end
end
end
percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0
ex.exercise_choices.each do |c|
right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置

Loading…
Cancel
Save