竞赛提交增加作品成绩的导出

This commit is contained in:
cxt 2017-01-12 11:14:27 +08:00
parent 231fa56c49
commit ee4d676f11
5 changed files with 186 additions and 69 deletions

View File

@ -97,11 +97,11 @@ class ContestantWorksController < ApplicationController
respond_to do |format|
format.js
format.html
# format.xls {
# filename = "#{@contest.user.lastname.to_s + @contest.user.firstname}_#{@contest.name}_#{@contestwork.name}#{l(:excel_homework_list)}.xls"
# send_data(homework_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
# :filename => filename_for_content_disposition(filename))
# }
format.xls {
filename = "#{@contest.user.show_name.to_s}_#{@contest.name}_#{@contestwork.name}_#{l(:excel_homework_list)}_#{DateTime.parse(Time.now.to_s).strftime('%Y%m%d%H%M%S').to_s}.xls"
send_data(work_score_to_xls(@stundet_works), :type => "text/excel;charset=utf-8; header=present",
:filename => filename_for_content_disposition(filename))
}
end
end
@ -472,4 +472,140 @@ class ContestantWorksController < ApplicationController
def is_logged
redirect_to signin_path unless User.current.logged?
end
#提交成绩导出
def work_score_to_xls items
xls_report = StringIO.new
book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet :name => "work"
blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
sheet1.row(0).default_format = blue
if @contestwork.work_type == 1 #普通作业
#开启在线评审
if @contestwork.online_evaluation
sheet1.row(0).concat([l(:excel_contestant_id),l(:excel_user_name),l(:excel_nickname),l(:excel_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des)])
if @contestwork.work_detail_manual.evaluation_num != -1
num = @contestwork.work_detail_manual.evaluation_num
n = num < (contest_judges @contest).size ? num : (contest_judges @contest).size
else
n = (contest_judges @contest).size
end
for i in 1 .. n do i
sheet1.row(0).concat([l(:label_judge_score, :num => i),l(:label_judge_comment, :num => i)])
end
sheet1.row(0).concat([l(:label_highest_score),l(:label_lowest_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = contestant_work.user.id
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
sheet1[count_row,5] = contestant_work.name
sheet1[count_row,6] = strip_html contestant_work.description if !contestant_work.description.nil?
work_scores = contestant_work_score_record contestant_work
for i in 1 .. n do i
sheet1[count_row,6 + i*2 -1] = (work_scores.nil? || work_scores[i - 1].nil?) ? l(:label_without_score) : work_scores[i - 1].score
sheet1[count_row,6 + i*2] = (work_scores.nil? || work_scores[i - 1].nil?) ? "" : work_scores[i - 1].comment
end
sheet1[count_row,7+2*n] = (work_scores.nil? || work_scores.reorder("score desc").first.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").first.score
sheet1[count_row,8+2*n] = (work_scores.nil? || work_scores.reorder("score desc").last.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").last.score
sheet1[count_row,9+2*n] = contestant_work.work_score.nil? ? l(:label_without_score) : contestant_work.work_score.round(2)
sheet1[count_row,10+2*n] = format_time contestant_work.commit_time
count_row += 1
end
#未开启在线评审
else
sheet1.row(0).concat([l(:excel_contestant_id),l(:excel_user_name),l(:excel_nickname),l(:excel_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = contestant_work.user.id
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
sheet1[count_row,5] = contestant_work.name
sheet1[count_row,6] = strip_html contestant_work.description if !contestant_work.description.nil?
sheet1[count_row,7] = format_time contestant_work.commit_time
count_row += 1
end
end
elsif @contestwork.work_type == 3 #分组作业
if @contestwork.online_evaluation
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school)])
if @contestwork.work_detail_group.base_on_project
sheet1.row(0).concat([l(:excel_homework_project),l(:excel_homework_name),l(:excel_homework_des)])
else
sheet1.row(0).concat([l(:excel_homework_name),l(:excel_homework_des)])
end
if @contestwork.work_detail_manual.evaluation_num != -1
num = @contestwork.work_detail_manual.evaluation_num
n = num < (contest_judges @contest).size ? num : (contest_judges @contest).size
else
n = (contest_judges @contest).size
end
for i in 1 .. n do i
sheet1.row(0).concat([l(:label_judge_score, :num => i),l(:label_judge_comment, :num => i)])
end
sheet1.row(0).concat([l(:label_highest_score),l(:label_lowest_score),l(:excel_f_score),l(:excel_commit_time)])
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = get_contest_group_member_names contestant_work
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
if @contestwork.work_detail_group.base_on_project
sheet1[count_row,5] = (contestant_work.project_id == 0 || contestant_work.project_id.nil?) ? l(:excel_no_project) : contestant_work.project.name
current_column = 6
else
current_column = 5
end
sheet1[count_row,current_column] = contestant_work.name
sheet1[count_row,current_column + 1] = strip_html contestant_work.description if !contestant_work.description.nil?
work_scores = contestant_work_score_record contestant_work
for i in 1 .. n do i
sheet1[count_row,current_column + 1 + i*2 -1] = (work_scores.nil? || work_scores[i - 1].nil?) ? l(:label_without_score) : work_scores[i - 1].score
sheet1[count_row,current_column + 1 + i*2] = (work_scores.nil? || work_scores[i - 1].nil?) ? "" : work_scores[i - 1].comment
end
sheet1[count_row,current_column + 2 +2*n] = (work_scores.nil? || work_scores.reorder("score desc").first.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").first.score
sheet1[count_row,current_column + 3 +2*n] = (work_scores.nil? || work_scores.reorder("score desc").last.nil?) ? l(:label_without_score) : work_scores.reorder("score desc").last.score
sheet1[count_row,current_column + 4 +2*n] = contestant_work.work_score.nil? ? l(:label_without_score) : contestant_work.work_score.round(2)
sheet1[count_row,current_column + 5 +2*n] = format_time contestant_work.commit_time
count_row += 1
end
else
if @contestwork.work_detail_group.base_on_project
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school),l(:excel_homework_project),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
else
sheet1.row(0).concat([l(:excel_group_member),l(:excel_group_leader),l(:excel_group_leader_login),l(:excel_group_leader_mail),l(:excel_school),l(:excel_homework_name),l(:excel_homework_des),l(:excel_commit_time)])
end
count_row = 1
items.each do |contestant_work|
sheet1[count_row,0] = get_contest_group_member_names contestant_work
sheet1[count_row,1] = contestant_work.user.show_name
sheet1[count_row,2] = contestant_work.user.login
sheet1[count_row,3] = contestant_work.user.mail
sheet1[count_row,4] = contestant_work.user.user_extensions.school.nil? ? "" : contestant_work.user.user_extensions.school.name
if @contestwork.work_detail_group.base_on_project
sheet1[count_row,5] = (contestant_work.project_id == 0 || contestant_work.project_id.nil?) ? l(:excel_no_project) : contestant_work.project.name
current_column = 6
else
current_column = 5
end
sheet1[count_row,current_column] = contestant_work.name
sheet1[count_row,current_column + 1] = strip_html contestant_work.description if !contestant_work.description.nil?
sheet1[count_row,current_column + 2] = format_time contestant_work.commit_time
count_row += 1
end
end
end
book.write xls_report
xls_report.string
end
end

View File

@ -4012,6 +4012,23 @@ def get_group_member_names work
result
end
def get_contest_group_member_names work
result = ""
unless work.nil?
work.contestant_work_projects.each do |member|
user = User.where(:id => member.user_id).first
unless user.nil?
if result != ""
result += "#{user.show_name}"
else
result += user.show_name
end
end
end
end
result
end
def course_syllabus_option user = User.current
syllabus_members = SyllabusMember.where("user_id = #{user.id}")
syllabus_ids = syllabus_members.empty? ? "(-1)" : "(" + syllabus_members.map{|mem| mem.syllabus_id}.join(',') + ")"

View File

@ -36,8 +36,7 @@ module ContestantWorksHelper
def contestant_work_score_record work
sql = "SELECT MAX(id) id FROM contestant_work_scores WHERE reviewer_role = 2 AND score IS NOT NULL AND contestant_work_id = #{work.id} GROUP BY user_id"
tea_ts_ids = ContestantWorkScore.find_by_sql sql
tea_ts_ids = tea_ts_ids.empty? ? "(-1)" : "(" + tea_ts_ids.map{|tea| tea.id}.join(",") + ")"
scores = work.contestant_work_scores.where("score IS NULL or reviewer_role = 3 or id in #{tea_ts_ids}").order("updated_at desc")
scores = work.contestant_work_scores.where(:id => tea_ts_ids.map{|tea| tea.id}).order("updated_at desc")
return scores
end

View File

@ -37,51 +37,6 @@
$("#relatePWrap_<%=@contestwork.id %>").toggleClass('relatePWrap');
$("#moreProject_<%=@contestwork.id %>").show();
});
// 匿评弹框提示
<%# if @is_evaluation && !@stundet_works.empty?%>
// $(function(){
// $('#ajax-modal').html('<%#= escape_javascript(render :partial => 'student_work/praise_alert') %>');
// showModal('ajax-modal', '500px');
// $('#ajax-modal').siblings().remove();
// $('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
// "<a href='javascript:' onclick='clickCanel();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
// $('#ajax-modal').parent().css("top","").css("left","");
// $('#ajax-modal').parent().addClass("anonymos");
// });
<%# end%>
// function set_score_rule_submit() {
// if($("#late_penalty_num").val() == ""){
// $("#late_penalty_num").val("0");
// }
// if($("#absence_penalty_num").val() == ""){
// $("#absence_penalty_num").val("0");
// }
// $('#muban_popup_box').find('form').submit();
// hideModal();
// }
// //设置评分规则
// function set_score_rule(){
<!--<%# if @homework.homework_type == 2 %>-->
<!--<%# if @homework.anonymous_comment == 0 %>-->
// var htmlvalue = "<%#= escape_javascript(render :partial => 'homework_common/set_score_rule_pro',:locals => {:homework => @homework, :student_path => true, :user_activity_id => -1,:hw_status => 5}) %>";
// pop_box_new(htmlvalue, 570, 355);
<!--<%# else %>-->
// var htmlvalue = "<%#= escape_javascript(render :partial => 'homework_common/set_score_rule_pro_anon',:locals => {:homework => @homework, :student_path => true, :user_activity_id => -1,:hw_status => 5}) %>";
// pop_box_new(htmlvalue, 500, 285);
<!--<%# end %>-->
<!--<%# else %>-->
<!--<%# if @homework.anonymous_comment == 0 %>-->
// var htmlvalue = "<%#= escape_javascript(render :partial => 'homework_common/set_score_rule_non_pro',:locals => {:homework => @homework, :student_path => true, :user_activity_id => -1,:hw_status => 5}) %>";
// pop_box_new(htmlvalue, 500, 325);
<!--<%# else %>-->
// var htmlvalue = "<%#= escape_javascript(render :partial => 'homework_common/set_score_rule_none_pro_anon',:locals => {:homework => @homework, :student_path => true, :user_activity_id => -1,:hw_status => 5}) %>";
// pop_box_new(htmlvalue, 500, 225);
<!--<%# end %>-->
<!--<%# end %>-->
// }
</script>
<div class="homepageRight mt0 ml10">
@ -116,28 +71,28 @@
<!---menu_r end--->
</div>
<!--div class="hworkInfor"><a href="javascript:void(0);" class="linkBlue">作业信息</a></div-->
<%# if @is_teacher%>
<!--<div class="fr mt5">-->
<!--<ul class="">-->
<!--<li class="pr export_icon_li">-->
<!--<a href="javascript:void(0);" class="export_icon linkBlue2">导出</a>-->
<!--<ul class="hworkMenu" style="top: 30px; left: -100px;">-->
<!--&lt;!&ndash;<li>&ndash;&gt;-->
<!--&lt;!&ndash;<%#= link_to "导出作业成绩", student_work_index_path(:homework => @homework.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => "export_student_work"%>&ndash;&gt;-->
<!--&lt;!&ndash;</li>&ndash;&gt;-->
<% if @is_teacher%>
<div class="fr mt5">
<ul class="">
<li class="pr export_icon_li">
<a href="javascript:void(0);" class="export_icon linkBlue2">导出</a>
<ul class="hworkMenu" style="top: 30px; left: -100px;">
<li>
<%= link_to "导出提交成绩", contestant_works_path(:work => @contestwork.id,:order => @order, :sort => @b_sort, :name => @name, :group => @group, :format => 'xls'),:class=>'hworkExport postTypeGrey', :id => "export_student_work"%>
</li>
<!--<li>-->
<!--<%# if @contestwork.contestant_works.empty?%>-->
<!--<%# if @homework.student_works.empty?%>-->
<!--<%#= link_to "导出作业附件", "javascript:void(0)", class: "hworkExport resourcesGrey", :onclick => "alert('没有学生提交作业,无法下载附件')" %>-->
<!--<%# else%>-->
<!--<%#= link_to "导出作业附件", zipdown_assort_path(obj_class: @contestwork.class, obj_id: @contestwork, format: :json),-->
<!--<%#= link_to "导出作业附件", zipdown_assort_path(obj_class: @homework.class, obj_id: @homework, format: :json),-->
<!--remote: true, class: "hworkExport resourcesGrey", :id => "download_homework_attachments" %>-->
<!--<%# end%>-->
<!--</li>-->
<!--</ul>-->
<!--</li>-->
<!--</ul>-->
<!--</div>-->
<%# end%>
<!--</li> -->
</ul>
</li>
</ul>
</div>
<% end%>
<div class="cl"></div>
</div>

View File

@ -1879,6 +1879,13 @@ zh:
label_contest_delete: 删除竞赛
label_noawards_current: 暂未评奖
excel_contestant_id: 参赛者id
excel_school: 单位
label_judge_score: "评委%{num}评分"
label_judge_comment: "评委%{num}评价"
label_highest_score: 最高得分
label_lowest_score: 最低得分
excel_user_id: 学生id
excel_user_name: 用户名
excel_nickname: 登录名
@ -1890,6 +1897,9 @@ zh:
excel_homework_project: 关联项目
excel_no_project: 无关联项目
excel_group_member: 组员
excel_group_leader: 组长用户名
excel_group_leader_login: 组长登录名
excel_group_leader_mail: 组长电子邮箱
excel_t_score: 教师评分
excel_ta_score: 教辅评分
excel_n_score: 匿名评分