模拟答题记入数据库
This commit is contained in:
parent
9e9f373a76
commit
be29bcc8bd
|
@ -14,8 +14,8 @@ class StudentWorkController < ApplicationController
|
|||
def program_test
|
||||
is_test = params[:is_test] == 'true'
|
||||
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
|
||||
resultObj[:status] = 100
|
||||
|
@ -43,24 +43,7 @@ class StudentWorkController < ApplicationController
|
|||
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
|
||||
|
@ -640,13 +623,14 @@ class StudentWorkController < ApplicationController
|
|||
xls_report.string
|
||||
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
|
||||
if student_work.nil?
|
||||
@homework.student_works.build(
|
||||
name: params[:title],
|
||||
description: params[:src],
|
||||
user_id: User.current.id
|
||||
user_id: User.current.id,
|
||||
is_test: is_test
|
||||
)
|
||||
unless @homework.save
|
||||
else
|
||||
|
|
|
@ -401,7 +401,7 @@ class UsersController < ApplicationController
|
|||
homework_detail_programing = HomeworkDetailPrograming.new
|
||||
homework.homework_detail_programing = homework_detail_programing
|
||||
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]
|
||||
if Array === inputs
|
||||
|
|
|
@ -10,7 +10,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
has_one :homework_detail_manual, :dependent => :destroy
|
||||
has_one :homework_detail_programing, :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 :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
|
||||
# 课程动态
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#学生提交作品表
|
||||
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 :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.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20150907064547) do
|
||||
ActiveRecord::Schema.define(:version => 20150907152238) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -1313,11 +1313,12 @@ ActiveRecord::Schema.define(:version => 20150907064547) do
|
|||
t.float "student_score"
|
||||
t.float "teaching_asistant_score"
|
||||
t.integer "project_id", :default => 0
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.datetime "created_at", :null => false
|
||||
t.datetime "updated_at", :null => false
|
||||
t.integer "late_penalty", :default => 0
|
||||
t.integer "absence_penalty", :default => 0
|
||||
t.integer "system_score"
|
||||
t.boolean "is_test", :default => false
|
||||
end
|
||||
|
||||
create_table "student_works_evaluation_distributions", :force => true do |t|
|
||||
|
|
Loading…
Reference in New Issue