|
|
@ -3,13 +3,43 @@ class StudentWorkController < ApplicationController
|
|
|
|
include StudentWorkHelper
|
|
|
|
include StudentWorkHelper
|
|
|
|
require 'bigdecimal'
|
|
|
|
require 'bigdecimal'
|
|
|
|
require "base64"
|
|
|
|
require "base64"
|
|
|
|
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
|
|
|
before_filter :find_homework, :only => [:new, :index, :create, :student_work_absence_penalty, :absence_penalty_list, :evaluation_list, :program_test]
|
|
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
|
|
|
before_filter :find_work, :only => [:edit, :update, :show, :destroy, :add_score, :praise_student_work]
|
|
|
|
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
|
|
|
before_filter :member_of_course, :only => [:index, :new, :create, :show, :add_score, :praise_student_work]
|
|
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
|
|
|
before_filter :author_of_work, :only => [:edit, :update, :destroy]
|
|
|
|
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
|
|
|
before_filter :teacher_of_course, :only => [:student_work_absence_penalty, :absence_penalty_list, :evaluation_list]
|
|
|
|
protect_from_forgery :except => :set_program_score
|
|
|
|
protect_from_forgery :except => :set_program_score
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
###
|
|
|
|
|
|
|
|
def program_test
|
|
|
|
|
|
|
|
resultObj = {status: 0, results: [], error_msg: ''}
|
|
|
|
|
|
|
|
student_work = find_or_save_student_work
|
|
|
|
|
|
|
|
unless student_work
|
|
|
|
|
|
|
|
resultObj[:status] = 100
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
if @homework.homework_type == 2 && @homework.homework_detail_programing
|
|
|
|
|
|
|
|
result = test_realtime(student_work, params[:src])
|
|
|
|
|
|
|
|
logger.debug result
|
|
|
|
|
|
|
|
resultObj[:status] = result["status"]
|
|
|
|
|
|
|
|
resultObj[:results] = result["results"]
|
|
|
|
|
|
|
|
resultObj[:error_msg] = result["error_msg"]
|
|
|
|
|
|
|
|
results = result["results"]
|
|
|
|
|
|
|
|
if result["status"].to_i == -2 #编译错误
|
|
|
|
|
|
|
|
results = [result["error_msg"]]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
student_work.student_work_tests.build(status: result["status"], results: results)
|
|
|
|
|
|
|
|
unless student_work.save
|
|
|
|
|
|
|
|
resultObj[:status] = 200
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
resultObj[:status] = result["status"].to_i
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render :json => resultObj
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
def index
|
|
|
|
#设置作业对应的forge_messages表的viewed字段
|
|
|
|
#设置作业对应的forge_messages表的viewed字段
|
|
|
|
query_student_work = @homework.course_messages
|
|
|
|
query_student_work = @homework.course_messages
|
|
|
@ -102,14 +132,9 @@ class StudentWorkController < ApplicationController
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def new
|
|
|
|
def new
|
|
|
|
student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
|
|
|
@student_work = @homework.student_works.where("user_id = ?",User.current.id).first
|
|
|
|
if student_work.nil?
|
|
|
|
if @student_work.nil?
|
|
|
|
@stundet_work = StudentWork.new
|
|
|
|
@student_work = StudentWork.new
|
|
|
|
respond_to do |format|
|
|
|
|
|
|
|
|
format.html
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
render_403
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -584,4 +609,44 @@ class StudentWorkController < ApplicationController
|
|
|
|
book.write xls_report
|
|
|
|
book.write xls_report
|
|
|
|
xls_report.string
|
|
|
|
xls_report.string
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def find_or_save_student_work
|
|
|
|
|
|
|
|
student_work = @homework.student_works.where(user_id: User.current.id).first
|
|
|
|
|
|
|
|
if student_work.nil?
|
|
|
|
|
|
|
|
@homework.student_works.build(
|
|
|
|
|
|
|
|
name: params[:title],
|
|
|
|
|
|
|
|
description: params[:src],
|
|
|
|
|
|
|
|
user_id: User.current.id
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
unless @homework.save
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
student_work = @homework.student_works.where(user_id: User.current.id).first
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
student_work
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_realtime(student_work, src)
|
|
|
|
|
|
|
|
url = "http://192.168.41.130:3000/api/realtime_test.json"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
factor = []
|
|
|
|
|
|
|
|
@homework.homework_tests.each do |test|
|
|
|
|
|
|
|
|
factor << {input: test.input, output: test.output}
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
end
|