From 05e72f5f66fabd898b7d69db3942f3164184cdbd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 08:56:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1=E9=A1=B5?= =?UTF-8?q?=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/controllers/exercises_controller.rb | 6 ++++-- app/helpers/exercises_helper.rb | 18 ++++++++++-------- app/models/course.rb | 16 +++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..89e781425 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1329,8 +1329,6 @@ class ExercisesController < ApplicationController @exercise_all_users = @exercise.exercise_users ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) - @exercise_users_list = @exercise.all_exercise_users(current_user.id) - @course_all_members_count = @exercise_users_list.size #班级的选择 if params[:exercise_group_id].present? @@ -1338,6 +1336,10 @@ class ExercisesController < ApplicationController exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?) @exercise_all_users = @exercise.exercise_users.exercise_commit_users(user_ids) + @course_all_members_count = @exercise_all_users.size + else + @exercise_users_list = @exercise.all_exercise_users(current_user.id) + @course_all_members_count = @exercise_users_list.size end @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index dfb6e4237..def163038 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -88,11 +88,11 @@ module ExercisesHelper question_infos = [] percent = 0.0 questions.each do |ex| - ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers.includes(:exercise_choice) + ex_total_score = user_ids.size * ex&.question_score #该试卷的已回答的总分 if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil + ex_answers = ex.exercise_answers effictive_users = ex_answers.search_answer_users("user_id",user_ids) else ques_title = ex.shixun.name @@ -121,12 +121,14 @@ module ExercisesHelper end end else #单选题和判断题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position - if [answer_choice_array] == standard_answer - right_users_count += 1 - end - end + standard_answer_choice_id = ex.exercise_choices.find_by(choice_position: standard_answer.first)&.id + right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position + # if [answer_choice_array] == 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 diff --git a/app/models/course.rb b/app/models/course.rb index b2835fc21..26672afc2 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -310,15 +310,13 @@ class Course < ApplicationRecord #获取试卷/问卷已发布的班级id,名称和人数。当为统一设置时,显示全部,否则只显示当前已发布的班级信息 def get_ex_published_course(common_ids) teacher_power_courses = [] - if course_groups.present? - common_ids.each do |i| - if i == 0 - student_count = students.where(course_group_id:i).count - teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count} - else - course_group_name = course_groups.find_by(id:i) - teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count} - end + publish_groups = course_groups.where(id: common_ids) + if common_ids.include?(0) + teacher_power_courses << {course_name:"未分班", course_id: 0, student_count: none_group_count} + end + if publish_groups.present? + publish_groups.each do |group| + teacher_power_courses << {course_name: group&.name,course_id: group&.id, student_count: group&.course_members_count} end end teacher_power_courses