|
|
|
@ -4,14 +4,14 @@ class StudentWorkController < ApplicationController
|
|
|
|
|
include ApplicationHelper
|
|
|
|
|
require 'bigdecimal'
|
|
|
|
|
require "base64"
|
|
|
|
|
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students]
|
|
|
|
|
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test,:program_test_ex,:set_score_rule,:forbidden_anonymous_comment,:delete_work,:new_student_work_project,:student_work_project,:cancel_relate_project,:search_course_students]
|
|
|
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work,:retry_work,:revise_attachment]
|
|
|
|
|
before_filter :member_of_course, :only => [:new, :create, :show, :add_score, :praise_student_work]
|
|
|
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
|
|
|
|
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :set_score_rule, :forbidden_anonymous_comment]
|
|
|
|
|
before_filter :is_logged, :only => [:index]
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
###
|
|
|
|
|
def program_test
|
|
|
|
|
is_test = params[:is_test] == 'true'
|
|
|
|
|
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
|
|
|
@ -48,13 +48,102 @@ class StudentWorkController < ApplicationController
|
|
|
|
|
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
|
|
|
|
resultObj[:index] = student_work.student_work_tests.count
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
render :json => resultObj
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
$test_result = {}
|
|
|
|
|
$test_status = {}
|
|
|
|
|
#根据传入的tIndex确定是第几次测试
|
|
|
|
|
def program_test_ex
|
|
|
|
|
is_test = params[:is_test] == 'true'
|
|
|
|
|
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T'),tseq:1,tcount:1} #保存每测试一次返回的结果
|
|
|
|
|
|
|
|
|
|
student_work = find_or_save_student_work(is_test)
|
|
|
|
|
|
|
|
|
|
resultObj[:tcount] = @homework.homework_tests.size
|
|
|
|
|
|
|
|
|
|
unless student_work
|
|
|
|
|
resultObj[:status] = 100
|
|
|
|
|
else
|
|
|
|
|
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
|
|
|
|
#找到第index个测试的输入输出
|
|
|
|
|
index = params[:tIndex].to_i
|
|
|
|
|
resultObj[:tseq] = index
|
|
|
|
|
test = @homework.homework_tests[index - 1]
|
|
|
|
|
|
|
|
|
|
#请求测试
|
|
|
|
|
result = test_realtime_ex(test, params[:src])
|
|
|
|
|
logger.debug result
|
|
|
|
|
|
|
|
|
|
#-1 默认值 0全部正确并结束 2 超时 -2 编译错误
|
|
|
|
|
resultObj[:status] = -1
|
|
|
|
|
resultObj[:results] = result["results"][0] #本次测试结果
|
|
|
|
|
resultObj[:error_msg] = result["error_msg"] #编译错误时的信息
|
|
|
|
|
|
|
|
|
|
if result["status"].to_i == -2 #编译错误
|
|
|
|
|
resultObj[:status] = -2
|
|
|
|
|
elsif result["results"][0]["status"].to_i == 2
|
|
|
|
|
resultObj[:status] = 2
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
unless student_work.save
|
|
|
|
|
resultObj[:status] = 200
|
|
|
|
|
else
|
|
|
|
|
|
|
|
|
|
#索引
|
|
|
|
|
work_id = student_work.id
|
|
|
|
|
|
|
|
|
|
#测试第一个时初始化下全局变量
|
|
|
|
|
if index == 1
|
|
|
|
|
$test_result[work_id] = [] #保存本次测试的结果 输入输出
|
|
|
|
|
$test_status[work_id] = 0 #保存本次测试的结果 正确还是错误
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if result["status"].to_i == -2
|
|
|
|
|
$test_result[work_id] = [result["error_msg"]]
|
|
|
|
|
$test_status[work_id] = -2
|
|
|
|
|
else
|
|
|
|
|
#存下每次的结果 只有每次都为0才全部正确
|
|
|
|
|
$test_status[work_id] = result["status"] != 0 ? result["status"]:$test_status[work_id]
|
|
|
|
|
$test_result[work_id][index - 1] = resultObj[:results]
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
student_work.name = params[:title]
|
|
|
|
|
student_work.description = params[:src]
|
|
|
|
|
|
|
|
|
|
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 resultObj[:status] == 2 || resultObj[:status] == -2 || index == @homework.homework_tests.size
|
|
|
|
|
if $test_status[work_id] == 0
|
|
|
|
|
resultObj[:status] = 0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
student_work_test = student_work.student_work_tests.build(status: $test_status[work_id],
|
|
|
|
|
results: $test_result[work_id],src: params[:src])
|
|
|
|
|
student_work.save
|
|
|
|
|
resultObj[:time] = student_work_test.created_at.to_s(:db)
|
|
|
|
|
resultObj[:index] = student_work.student_work_tests.count
|
|
|
|
|
|
|
|
|
|
$test_result[work_id] = nil
|
|
|
|
|
$test_status[work_id] = nil
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#渲染返回结果
|
|
|
|
|
render :json => resultObj
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
# 作业消息状态更新
|
|
|
|
|
@homework.course_messages.each do |homework_message|
|
|
|
|
@ -986,7 +1075,6 @@ class StudentWorkController < ApplicationController
|
|
|
|
|
student_work
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_realtime(student_work, src)
|
|
|
|
|
url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json"
|
|
|
|
|
|
|
|
|
@ -1010,6 +1098,28 @@ class StudentWorkController < ApplicationController
|
|
|
|
|
JSON.parse(res.body)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def test_realtime_ex(test, src)
|
|
|
|
|
url = "#{Redmine::Configuration['judge_server']}api/realtime_test.json"
|
|
|
|
|
|
|
|
|
|
factor = []
|
|
|
|
|
factor << {input: test.input, output: test.output}
|
|
|
|
|
|
|
|
|
|
solutions = {
|
|
|
|
|
src:src,
|
|
|
|
|
language:@homework.homework_detail_programing.language,
|
|
|
|
|
factor: factor
|
|
|
|
|
}
|
|
|
|
|
uri = URI(url)
|
|
|
|
|
body = solutions.to_json
|
|
|
|
|
res = Net::HTTP.new(uri.host, uri.port).start do |client|
|
|
|
|
|
request = Net::HTTP::Post.new(uri.path)
|
|
|
|
|
request.body = body
|
|
|
|
|
request["Content-Type"] = "application/json"
|
|
|
|
|
client.request(request)
|
|
|
|
|
end
|
|
|
|
|
JSON.parse(res.body)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#成绩计算
|
|
|
|
|
def set_final_score homework,student_work
|
|
|
|
|
if homework && homework.homework_detail_manual
|
|
|
|
|