diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 39d793b5a..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -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]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0cfcd5336..f5d341aae 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -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,12 +115,13 @@ 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 - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end + # 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 percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 458d31989..5a0dc8a37 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -3,7 +3,7 @@ class UserExtension < ApplicationRecord enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 } belongs_to :user, touch: true - belongs_to :school + belongs_to :school, optional: true belongs_to :department, optional: true def identity_text