diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 589f232c5..3497e9fdd 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -81,6 +81,7 @@ class StudentWorkController < ApplicationController #根据传入的tIndex确定是第几次测试 #之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来 def program_test_ex + tStarttime = Time.now is_test = params[:is_test] == 'true' @@ -106,108 +107,123 @@ class StudentWorkController < ApplicationController tEndtime = Time.now tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" - - #status 0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 + #status 0:答案正确 -5program_test_ex 函数出错 -4judge代码出错 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 + resultObj[:status] = -3 CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>-3,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - end - if result["status"].to_i != -2 - #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") - #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") - space_replace_1(result["results"].first['output']) - space_replace_1(result["results"].first['result']) + rescue + #-4 judge代码 出错 + logger.debug "program_test_error 1" + resultObj[:status] = -4 + tmpstatus = -4 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id) end - logger.debug result + begin + if resultObj[:status] != -3 && resultObj[:status] != -4 + if result["status"].to_i != -2 + #result["results"].first['output'] = result["results"].first['output'].gsub(" ","□") + #result["results"].first['result'] = result["results"].first['result'].gsub(" ","□") + space_replace_1(result["results"].first['output']) + space_replace_1(result["results"].first['result']) + end - #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 - resultObj[:status] = -1 - resultObj[:results] = result["results"].first #本次测试结果 - if result["status"].to_i == -2 #编译错误 - result["error_msg"] = result["error_msg"][0..2047] - end - resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 + logger.debug result - #该状态用于存入CodeTests - tmpstatus = -1 - if result["status"].to_i == -2 #编译错误 - resultObj[:results] = result["error_msg"] - resultObj[:status] = -2 - tmpstatus = -2 - elsif result["results"][0]["status"].to_i == 2 - resultObj[:status] = 2 - tmpstatus = 2 - end + #-1 默认值 0全部正确并结束 2 超时 -2 编译错误 + resultObj[:status] = -1 + resultObj[:results] = result["results"].first #本次测试结果 + # if result["status"].to_i == -2 #编译错误 + result["error_msg"] = result["error_msg"][0..2047] + # end + resultObj[:error_msg] = result["error_msg"] #编译错误时的信息 - if result["status"] == 0 - tmpstatus = 0 - end + #该状态用于存入CodeTests + tmpstatus = -1 + if result["status"].to_i == -2 #编译错误 + resultObj[:results] = result["error_msg"] + resultObj[:status] = -2 + tmpstatus = -2 + elsif result["results"][0]["status"].to_i == 2 + resultObj[:status] = 2 + tmpstatus = 2 + end - unless student_work.save - resultObj[:status] = 200 - else - student_work.name = params[:title] - student_work.description = params[:src] + if result["status"] == 0 + tmpstatus = 0 + end - if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") - student_work.late_penalty = @homework.late_penalty - else - student_work.late_penalty = 0 - end + unless student_work.save + resultObj[:status] = 200 + else + student_work.name = params[:title] + student_work.description = params[:src] - #每次从数据库取出上次的结果加上本次的结果再存入数据库 - if result["status"].to_i != -2 - result["results"].first['user_wait'] = tUsedtime + if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") + student_work.late_penalty = @homework.late_penalty + else + student_work.late_penalty = 0 + end - if result["results"][0]["status"].to_i == 2 - result["status"] = 2 + #每次从数据库取出上次的结果加上本次的结果再存入数据库 + if result["status"].to_i != -2 + result["results"].first['user_wait'] = tUsedtime + + if result["results"][0]["status"].to_i == 2 + result["status"] = 2 + end + end + + status = result["status"] + if index == 1 + student_work_test = student_work.student_work_tests.build(status: status, + results: [resultObj[:results]],src: params[:src]) + student_work_test.save! + resultObj[:testid] = student_work_test.id + else + #先从数据库取出result + student_work_test = StudentWorkTest.find(params[:testid]) + results = student_work_test.results + results << resultObj[:results] + student_work_test.results = results + student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) + student_work_test.save! + status = student_work_test.status + resultObj[:testid] = student_work_test.id + end + + #超时或编译错误则直接返回了并存入数据库 + if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size + if status == 0 + resultObj[:status] = 0 + end + student_work.save! + resultObj[:time] = student_work_test.created_at.to_s(:db) + resultObj[:index] = student_work.student_work_tests.count + end + + #将每次用户等待时间都存起来以便管理界面显示用 + tEndtime = Time.now + tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 + logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" + + time_used = 0 + if result["status"].to_i != -2 + #至少一毫秒 + time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] + end + #0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) end end - - status = result["status"] - if index == 1 - student_work_test = student_work.student_work_tests.build(status: status, - results: [resultObj[:results]],src: params[:src]) - student_work_test.save! - resultObj[:testid] = student_work_test.id - else - #先从数据库取出result - student_work_test = StudentWorkTest.find(params[:testid]) - results = student_work_test.results - results << resultObj[:results] - student_work_test.results = results - student_work_test.status = (result["status"] != 0 ? result["status"] : student_work_test.status) - student_work_test.save! - status = student_work_test.status - resultObj[:testid] = student_work_test.id - end - - #超时或编译错误则直接返回了并存入数据库 - if resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size - if status == 0 - resultObj[:status] = 0 - end - student_work.save! - resultObj[:time] = student_work_test.created_at.to_s(:db) - resultObj[:index] = student_work.student_work_tests.count - end - - #将每次用户等待时间都存起来以便管理界面显示用 - tEndtime = Time.now - tUsedtime = (tEndtime.to_i-tStarttime.to_i)*1000+(tEndtime.usec - tStarttime.usec)/1000 - logger.debug "program_test_ex user wait time = #{tUsedtime} 毫秒" - - time_used = 0 - if result["status"].to_i != -2 - #至少一毫秒 - time_used = result["results"].first['time_used'] == 0 ? 1:result["results"].first['time_used'] - end - #0:答案正确 -3http超时 -2:编译错误 -1:答案错误 2:程序运行超时 - CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>time_used,:wait_time=>tUsedtime,:student_work_id=>student_work.id) - - #渲染返回结果 - render :json => resultObj + rescue + #-5 program_test_ex 函数出错 + logger.debug "program_test_error 2" + resultObj[:status] = -5 + tmpstatus = -5 + CodeTests.create(:homework_id=>@homework.id,:language=>@homework.homework_detail_programing.language,:status=>tmpstatus,:time_used=>0,:wait_time=>0,:student_work_id=>student_work.id) end + #渲染返回结果 + render :json => resultObj end end end diff --git a/app/views/admin/code_work_tests.html.erb b/app/views/admin/code_work_tests.html.erb index 64c3a41e1..2013bd322 100644 --- a/app/views/admin/code_work_tests.html.erb +++ b/app/views/admin/code_work_tests.html.erb @@ -24,8 +24,8 @@
<%= count>0 ? "#{count}" :"0" %> 回复 diff --git a/app/views/users/_course_boardlist.html.erb b/app/views/users/_course_boardlist.html.erb index c92d117ee..bf23d9a97 100644 --- a/app/views/users/_course_boardlist.html.erb +++ b/app/views/users/_course_boardlist.html.erb @@ -45,8 +45,8 @@
<%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %>
<%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>activity.description, :maxheight=>54, :maxwordsnum=>100} %>
<%= count>0 ? "#{count}" : "0" %>回复|<%= get_praise_num(activity) > 0 ? "#{get_praise_num(activity)}" : "0" %>赞
diff --git a/app/views/users/_project_boardlist.html.erb b/app/views/users/_project_boardlist.html.erb index 5f61d26ef..928d682d8 100644 --- a/app/views/users/_project_boardlist.html.erb +++ b/app/views/users/_project_boardlist.html.erb @@ -45,8 +45,8 @@<%=render :partial =>"users/intro_content_ex", :locals=>{:user_activity_id =>activity.id, :content=>content, :maxheight=>54, :maxwordsnum=>100} %>
<%= project.project_score.issue_num %>问题| <%= project.project_score.attach_num %>资源