试卷统计页的优化

dev_forum
cxt 6 years ago
parent 14300893f6
commit 05e72f5f66

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

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

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

Loading…
Cancel
Save