模拟答题记入数据库
This commit is contained in:
parent
9e9f373a76
commit
be29bcc8bd
|
@ -14,8 +14,8 @@ class StudentWorkController < ApplicationController
|
||||||
def program_test
|
def program_test
|
||||||
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')}
|
resultObj = {status: 0, results: [], error_msg: '', time: Time.now.strftime('%Y-%m-%d %T')}
|
||||||
unless is_test
|
|
||||||
student_work = find_or_save_student_work
|
student_work = find_or_save_student_work(is_test)
|
||||||
|
|
||||||
unless student_work
|
unless student_work
|
||||||
resultObj[:status] = 100
|
resultObj[:status] = 100
|
||||||
|
@ -43,24 +43,7 @@ class StudentWorkController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
resultObj[:status] = result["status"].to_i
|
|
||||||
resultObj[:time] = Time.now.strftime('%Y-%m-%d %T')
|
|
||||||
resultObj[:index] = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
render :json => resultObj
|
render :json => resultObj
|
||||||
|
@ -640,13 +623,14 @@ class StudentWorkController < ApplicationController
|
||||||
xls_report.string
|
xls_report.string
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_save_student_work
|
def find_or_save_student_work(is_test)
|
||||||
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?
|
||||||
@homework.student_works.build(
|
@homework.student_works.build(
|
||||||
name: params[:title],
|
name: params[:title],
|
||||||
description: params[:src],
|
description: params[:src],
|
||||||
user_id: User.current.id
|
user_id: User.current.id,
|
||||||
|
is_test: is_test
|
||||||
)
|
)
|
||||||
unless @homework.save
|
unless @homework.save
|
||||||
else
|
else
|
||||||
|
|
|
@ -401,7 +401,7 @@ class UsersController < ApplicationController
|
||||||
homework_detail_programing = HomeworkDetailPrograming.new
|
homework_detail_programing = HomeworkDetailPrograming.new
|
||||||
homework.homework_detail_programing = homework_detail_programing
|
homework.homework_detail_programing = homework_detail_programing
|
||||||
homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
|
homework_detail_programing.ta_proportion = params[:ta_proportion] || 0.6
|
||||||
homework_detail_programing.language = params[:program][:language].to_i
|
homework_detail_programing.language = params[:language_type].to_i
|
||||||
|
|
||||||
inputs = params[:program][:input]
|
inputs = params[:program][:input]
|
||||||
if Array === inputs
|
if Array === inputs
|
||||||
|
|
|
@ -10,7 +10,7 @@ class HomeworkCommon < ActiveRecord::Base
|
||||||
has_one :homework_detail_manual, :dependent => :destroy
|
has_one :homework_detail_manual, :dependent => :destroy
|
||||||
has_one :homework_detail_programing, :dependent => :destroy
|
has_one :homework_detail_programing, :dependent => :destroy
|
||||||
has_many :homework_tests, :dependent => :destroy
|
has_many :homework_tests, :dependent => :destroy
|
||||||
has_many :student_works, :dependent => :destroy
|
has_many :student_works, :dependent => :destroy, :conditions => "is_test=0"
|
||||||
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表
|
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
|
||||||
# 课程动态
|
# 课程动态
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#学生提交作品表
|
#学生提交作品表
|
||||||
class StudentWork < ActiveRecord::Base
|
class StudentWork < ActiveRecord::Base
|
||||||
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id
|
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test
|
||||||
|
|
||||||
belongs_to :homework_common
|
belongs_to :homework_common
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddIsTestToStudentWorks < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :student_works, :is_test, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20150907064547) do
|
ActiveRecord::Schema.define(:version => 20150907152238) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -1318,6 +1318,7 @@ ActiveRecord::Schema.define(:version => 20150907064547) do
|
||||||
t.integer "late_penalty", :default => 0
|
t.integer "late_penalty", :default => 0
|
||||||
t.integer "absence_penalty", :default => 0
|
t.integer "absence_penalty", :default => 0
|
||||||
t.integer "system_score"
|
t.integer "system_score"
|
||||||
|
t.boolean "is_test", :default => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "student_works_evaluation_distributions", :force => true do |t|
|
create_table "student_works_evaluation_distributions", :force => true do |t|
|
||||||
|
|
Loading…
Reference in New Issue