|
|
@ -55,8 +55,31 @@ class StudentWorkController < ApplicationController
|
|
|
|
render :json => resultObj
|
|
|
|
render :json => resultObj
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#行尾空格替换成□
|
|
|
|
|
|
|
|
def space_replace_1(str)
|
|
|
|
|
|
|
|
for i in 0 .. str.size
|
|
|
|
|
|
|
|
tChar = str[i]
|
|
|
|
|
|
|
|
if tChar != ' ' && tChar != "\n"
|
|
|
|
|
|
|
|
sFlag = false
|
|
|
|
|
|
|
|
eFlag = false
|
|
|
|
|
|
|
|
elsif tChar == ' ' && sFlag == false
|
|
|
|
|
|
|
|
tStart = i
|
|
|
|
|
|
|
|
sFlag = true
|
|
|
|
|
|
|
|
elsif tChar == "\n"
|
|
|
|
|
|
|
|
tEnd = i - 1
|
|
|
|
|
|
|
|
if sFlag == true
|
|
|
|
|
|
|
|
for j in tStart .. tEnd
|
|
|
|
|
|
|
|
str[j] = "□"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
sFlag = false
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#由于负载问题 不要使用全局变量
|
|
|
|
#由于负载问题 不要使用全局变量
|
|
|
|
#根据传入的tIndex确定是第几次测试
|
|
|
|
#根据传入的tIndex确定是第几次测试
|
|
|
|
|
|
|
|
#之后如果觉得很卡 可以改成将结果传回JS再以参数形式传回来
|
|
|
|
def program_test_ex
|
|
|
|
def program_test_ex
|
|
|
|
is_test = params[:is_test] == 'true'
|
|
|
|
is_test = params[:is_test] == 'true'
|
|
|
|
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果
|
|
|
|
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1,testid:1} #保存每测试一次返回的结果
|
|
|
@ -78,10 +101,13 @@ class StudentWorkController < ApplicationController
|
|
|
|
result = test_realtime_ex(test, params[:src])
|
|
|
|
result = test_realtime_ex(test, params[:src])
|
|
|
|
|
|
|
|
|
|
|
|
if result["status"].to_i != -2
|
|
|
|
if result["status"].to_i != -2
|
|
|
|
result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
|
|
|
#result["results"].first['output'] = result["results"].first['output'].gsub(" ","□")
|
|
|
|
result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
|
|
|
#result["results"].first['result'] = result["results"].first['result'].gsub(" ","□")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
space_replace_1(result["results"].first['output'])
|
|
|
|
|
|
|
|
space_replace_1(result["results"].first['result'])
|
|
|
|
|
|
|
|
|
|
|
|
logger.debug result
|
|
|
|
logger.debug result
|
|
|
|
|
|
|
|
|
|
|
|
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
|
|
|
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
|
|
@ -108,7 +134,7 @@ class StudentWorkController < ApplicationController
|
|
|
|
student_work.late_penalty = 0
|
|
|
|
student_work.late_penalty = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#每次都要把数据存到数据库中
|
|
|
|
#每次从数据库取出上次的结果加上本次的结果再存入数据库
|
|
|
|
status = result["status"]
|
|
|
|
status = result["status"]
|
|
|
|
if index == 1
|
|
|
|
if index == 1
|
|
|
|
student_work_test = student_work.student_work_tests.build(status: status,
|
|
|
|
student_work_test = student_work.student_work_tests.build(status: status,
|
|
|
|