导出学生作业成绩列表

This commit is contained in:
cxt 2016-01-29 11:02:57 +08:00
parent c942c843b9
commit e9a7f6f826
2 changed files with 49 additions and 9 deletions

View File

@ -321,11 +321,12 @@ class CoursesController < ApplicationController
def export_course_member_excel
@all_members = student_homework_score(0,0,0,"desc")
@homeworks = @course.homework_commons.order("created_at desc")
filename="#{@course.teacher.lastname.to_s + @course.teacher.firstname.to_s }_#{@course.name}_#{@course.time.to_s + @course.term}#{l(:excel_member_list)}";
respond_to do |format|
format.xls {
send_data(member_to_xls(@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present",
send_data(member_to_xls(@homeworks,@course,@all_members,@course.course_groups), :type => "text/excel;charset=utf-8; header=present",
:filename => filename_for_content_disposition("#{filename}.xls"))
}
end
@ -963,7 +964,7 @@ class CoursesController < ApplicationController
sql_select = ""
if groupid == 0
sql_select = "SELECT members.*,(
SELECT SUM(student_works.final_score)
SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))
FROM student_works,homework_commons
WHERE student_works.homework_common_id = homework_commons.id
AND homework_commons.course_id = #{@course.id}
@ -975,7 +976,7 @@ class CoursesController < ApplicationController
WHERE members.course_id = #{@course.id} ORDER BY score #{score_sort_by}"
else
sql_select = "SELECT members.*,(
SELECT SUM(student_works.final_score)
SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))
FROM student_works,homework_commons
WHERE student_works.homework_common_id = homework_commons.id
AND homework_commons.course_id = #{@course.id}
@ -1009,16 +1010,54 @@ class CoursesController < ApplicationController
end
def member_to_xls members,groups
def member_to_xls homeworks, course, members,groups
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "student"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
#sheet1.row(0).default_format = blue
#sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_class),l(:excel_f_score),l(:excel_commit_time)])
sheet1[0,0] = "课程编号"
sheet1[0,1] = course.id
sheet1[1,0] = "课程学期"
sheet1[1,1] = course.time.to_s+""+course.term
sheet1[2,0] = "课程名称"
sheet1[2,1] = course.name
sheet1[3,0] = "教师团队"
sheet1[3,1] = (searchTeacherAndAssistant course).map{|member| member.user.show_name}.join('、')
sheet1[4,0] = "主讲教师"
sheet1[4,1] = course.teacher.show_name
sheet1[5,0] = "排名"
sheet1[5,1] = "学生姓名"
sheet1[5,2] = "昵称"
sheet1[5,3] = "学号"
for i in 0 ... homeworks.count
sheet1[5,i+4] = ""+(i+1).to_s+""
end
sheet1[5,homeworks.count+4] = "总成绩"
sheet1[5,0] = "排名"
sheet1[5,0] = "排名"
count_row = 6
members.each_with_index do |member, i|
sheet1[count_row,0]= i+1
sheet1[count_row,1] = member.user.lastname.to_s + member.user.firstname.to_s
sheet1[count_row,2] = member.user.login
sheet1[count_row,3] = member.user.user_extensions.student_id
homeworks.each_with_index do |homework, j|
student_works = homework.student_works.where("user_id = #{member.user.id}")
if student_works.empty?
sheet1[count_row,j+4] = format("%0.2f",0)
else
final_score = student_works.first.final_score.nil? ? 0 : student_works.first.final_score
score = final_score - student_works.first.absence_penalty - student_works.first.late_penalty
sheet1[count_row,j+4] = format("%0.2f",score <0 ? 0:score)
end
end
sheet1[count_row,homeworks.count+4] = format("%0.2f",member.score.nil? ? 0:member.score.to_s)
count_row += 1
end
sheet1.row(0).concat([l(:excel_user_id),l(:excel_user_name),l(:excel_nickname),l(:excel_student_id),l(:excel_mail),l(:excel_homework_score)])
count_row = 1
=begin
group0 = CourseGroup.new();
group0.id = 0;
group0.name = l(:excel_member_with_out_class)
@ -1040,6 +1079,7 @@ class CoursesController < ApplicationController
end
end
end
=end
book.write xls_report
xls_report.string
end

View File

@ -795,7 +795,7 @@ module CoursesHelper
# 学生按作业总分排序取前8个
def hero_homework_score(course, score_sort_by)
sql_select = "SELECT members.*,(
SELECT SUM(student_works.final_score)
SELECT SUM(IF(student_works.final_score is null,null,student_works.final_score - student_works.absence_penalty - student_works.late_penalty))
FROM student_works,homework_commons
WHERE student_works.homework_common_id = homework_commons.id
AND homework_commons.course_id = #{course.id}