课堂的成绩导出优化

dev_forum
SylorHuang 5 years ago
parent d991c52d10
commit b3dadf5a84

@ -1180,15 +1180,27 @@ class CoursesController < ApplicationController
course_main_info = [course_1,course_2,course_3,course_4,course_5,course_6,course_7] course_main_info = [course_1,course_2,course_3,course_4,course_5,course_6,course_7]
course_group_info_head = %w(序号 分班名称 邀请码 学生数量) course_group_info_head = %w(序号 分班名称 邀请码 学生数量)
course_group_info_body = [] course_group_info_body = []
if course.course_groups.present? none_group_counts = course.none_group_count
#当有未分班时,应该也做个统计
if none_group_counts > 0
none_group_index = 2
no_group_array = [1,"未分班",course.invite_code,none_group_counts]
course_group_info_body.push(no_group_array)
else
none_group_index = 1
end
if course.course_groups.exists?
course.course_groups.each_with_index do |group, index| course.course_groups.each_with_index do |group, index|
group_index = (index+1) group_index = (index+none_group_index)
group_name = group.name group_name = group.name
group_code = group.invite_code group_code = group.invite_code
group_count = group.course_members_count group_count = group.course_members_count
group_array = [group_index,group_name,group_code,group_count] group_array = [group_index,group_name,group_code,group_count]
course_group_info_body.push(group_array) course_group_info_body.push(group_array)
end end
end end
course_group_info = [course_group_info_head,course_group_info_body] course_group_info = [course_group_info_head,course_group_info_body]
@course_info += [course_info_title,course_main_info,course_group_info] @course_info += [course_info_title,course_main_info,course_group_info]
@ -1256,7 +1268,7 @@ class CoursesController < ApplicationController
#实训作业 #实训作业
if shixun_homeworks.size > 0 if shixun_homeworks.size > 0
shixun_homeworks.each do |s| shixun_homeworks&.includes(:score_student_works).each do |s|
user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work.nil? if user_student_work.nil?
h_score = 0.0 #该作业的得分为0 h_score = 0.0 #该作业的得分为0
@ -1272,7 +1284,7 @@ class CoursesController < ApplicationController
#普通作业 #普通作业
if common_homeworks.size > 0 if common_homeworks.size > 0
common_homeworks.each do |c| common_homeworks&.includes(:score_student_works).each do |c|
user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work_1.nil? if user_student_work_1.nil?
h_score_1 = 0.0 #该作业的得分为0 h_score_1 = 0.0 #该作业的得分为0
@ -1288,7 +1300,7 @@ class CoursesController < ApplicationController
#分组作业 #分组作业
if group_homeworks.size > 0 if group_homeworks.size > 0
group_homeworks.each do |g| group_homeworks&.includes(:score_student_works).each do |g|
user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答
if user_student_work_3.nil? if user_student_work_3.nil?
h_score_3 = 0.0 #该作业的得分为0 h_score_3 = 0.0 #该作业的得分为0
@ -1304,7 +1316,7 @@ class CoursesController < ApplicationController
#毕设作业 #毕设作业
if tasks.size > 0 if tasks.size > 0
tasks.each do |task| tasks&.includes(:score_graduation_works).each do |task|
graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first
if graduation_work.nil? if graduation_work.nil?
t_score = 0.0 t_score = 0.0
@ -1320,7 +1332,7 @@ class CoursesController < ApplicationController
#试卷 #试卷
if exercises.size > 0 if exercises.size > 0
exercises.each do |ex| exercises&.includes(:score_exercise_users).each do |ex|
exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first
if exercise_work.nil? if exercise_work.nil?
e_score = 0.0 e_score = 0.0
@ -1363,7 +1375,7 @@ class CoursesController < ApplicationController
count_4 = tasks.size count_4 = tasks.size
count_5 = exercises.size count_5 = exercises.size
#实训作业 #实训作业
shixun_homeworks.each_with_index do |s,index| shixun_homeworks&.includes(:score_student_works).each_with_index do |s,index|
all_student_works = s.score_student_works #该实训题的全部用户回答 all_student_works = s.score_student_works #该实训题的全部用户回答
title_no = index.to_i + 1 title_no = index.to_i + 1
student_work_to_xlsx(all_student_works,s) student_work_to_xlsx(all_student_works,s)
@ -1373,7 +1385,7 @@ class CoursesController < ApplicationController
end end
#普通作业 #普通作业
common_homeworks.each_with_index do |c,index| common_homeworks&.includes(:score_student_works).each_with_index do |c,index|
all_student_works = c.score_student_works #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + index.to_i + 1 title_no = count_1 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
@ -1385,7 +1397,7 @@ class CoursesController < ApplicationController
end end
#分组作业 #分组作业
group_homeworks.each_with_index do |c,index| group_homeworks&.includes(:score_student_works).each_with_index do |c,index|
all_student_works = c.score_student_works #当前用户的对该作业的回答 all_student_works = c.score_student_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + index.to_i + 1 title_no = count_1 + count_2 + index.to_i + 1
student_work_to_xlsx(all_student_works,c) student_work_to_xlsx(all_student_works,c)
@ -1395,23 +1407,21 @@ class CoursesController < ApplicationController
end end
#毕设任务 #毕设任务
tasks.each_with_index do |c,index| tasks&.includes(:score_graduation_works).each_with_index do |c,index|
all_student_works = c.score_graduation_works #当前用户的对该作业的回答 all_student_works = c.score_graduation_works #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + index.to_i + 1
graduation_work_to_xlsx(all_student_works,c,current_user) graduation_work_to_xlsx(all_student_works,c,current_user)
work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30)
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [work_name,@head_cells_column,@task_cells_column] work_content = [work_name,@head_cells_column,@task_cells_column]
@task_work_arrays.push(work_content) @task_work_arrays.push(work_content)
end end
#试卷的导出 #试卷的导出
exercises.each_with_index do |c,index| exercises&.includes(:score_exercise_users).each_with_index do |c,index|
all_student_works = c.score_exercise_users #当前用户的对该作业的回答 all_student_works = c.score_exercise_users #当前用户的对该作业的回答
title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1
get_export_users(c,course,all_student_works) get_export_users(c,course,all_student_works)
work_name = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30) work_name = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30)
# work_content = [work_name,@work_head_cells,@work_cells_column]
work_content = [work_name,@table_columns,@user_columns] work_content = [work_name,@table_columns,@user_columns]
@exercise_work_arrays.push(work_content) @exercise_work_arrays.push(work_content)
end end

@ -103,7 +103,7 @@ class Course < ApplicationRecord
# 未分班的学生数 # 未分班的学生数
def none_group_count def none_group_count
course_members.where(role: 4, course_group_id: 0).count course_members.where(role: 4, course_group_id: 0).size
end end
def course_member(user_id) def course_member(user_id)

Loading…
Cancel
Save