From be29bcc8bdceb89f355e0c8617ea60491a7acc37 Mon Sep 17 00:00:00 2001 From: guange <8863824@gmail.com> Date: Mon, 7 Sep 2015 23:47:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E7=AD=94=E9=A2=98=E8=AE=B0?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_work_controller.rb | 28 ++++--------------- app/controllers/users_controller.rb | 2 +- app/models/homework_common.rb | 2 +- app/models/student_work.rb | 2 +- ...0907152238_add_is_test_to_student_works.rb | 5 ++++ db/schema.rb | 7 +++-- 6 files changed, 18 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20150907152238_add_is_test_to_student_works.rb diff --git a/app/controllers/student_work_controller.rb b/app/controllers/student_work_controller.rb index 9f8d25c7e..17c98e3b1 100644 --- a/app/controllers/student_work_controller.rb +++ b/app/controllers/student_work_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d7cf29387..c6735c551 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 1c066495f..b51de6c2c 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -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 #用户活动 # 课程动态 diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 6e39c954a..d7287dcc4 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -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 diff --git a/db/migrate/20150907152238_add_is_test_to_student_works.rb b/db/migrate/20150907152238_add_is_test_to_student_works.rb new file mode 100644 index 000000000..b58da7c16 --- /dev/null +++ b/db/migrate/20150907152238_add_is_test_to_student_works.rb @@ -0,0 +1,5 @@ +class AddIsTestToStudentWorks < ActiveRecord::Migration + def change + add_column :student_works, :is_test, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 4a718824a..0d6e87acf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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|