Merge branch 'guange_homework' of http://repository.trustie.net/xianbo/trustie2 into guange_homework
This commit is contained in:
commit
068b03cd8f
|
@ -42,9 +42,6 @@ class StudentWorkController < ApplicationController
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
render :json => resultObj
|
render :json => resultObj
|
||||||
end
|
end
|
||||||
|
@ -165,24 +162,23 @@ class StudentWorkController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
if params[:student_work]
|
if params[:student_work]
|
||||||
stundet_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||||
stundet_work ||= StudentWork.new
|
student_work ||= StudentWork.new
|
||||||
stundet_work.name = params[:student_work][:name]
|
student_work.name = params[:student_work][:name]
|
||||||
stundet_work.description = params[:student_work][:description]
|
student_work.description = params[:student_work][:description]
|
||||||
stundet_work.project_id = params[:student_work][:project_id]
|
student_work.project_id = params[:student_work][:project_id]
|
||||||
stundet_work.homework_common_id = @homework.id
|
student_work.homework_common_id = @homework.id
|
||||||
stundet_work.user_id = User.current.id
|
student_work.user_id = User.current.id
|
||||||
stundet_work.save_attachments(params[:attachments])
|
student_work.save_attachments(params[:attachments])
|
||||||
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
if Time.parse(@homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d")
|
||||||
stundet_work.late_penalty = @homework.late_penalty
|
student_work.late_penalty = @homework.late_penalty
|
||||||
else
|
else
|
||||||
stundet_work.late_penalty = 0
|
student_work.late_penalty = 0
|
||||||
end
|
end
|
||||||
render_attachment_warning_if_needed(stundet_work)
|
render_attachment_warning_if_needed(student_work)
|
||||||
if stundet_work.save
|
|
||||||
if @homework.homework_type == 2 && @homework.homework_detail_programing #编程作业,学生提交作品后计算系统得分
|
if student_work.save
|
||||||
|
|
||||||
end
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html {
|
format.html {
|
||||||
flash[:notice] = l(:notice_successful_create)
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
@ -624,7 +620,7 @@ class StudentWorkController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_or_save_student_work(is_test)
|
def find_or_save_student_work(is_test)
|
||||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
student_work = StudentWork.where(homework_common_id: @homework.id, 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],
|
||||||
|
@ -633,6 +629,7 @@ class StudentWorkController < ApplicationController
|
||||||
is_test: is_test
|
is_test: is_test
|
||||||
)
|
)
|
||||||
unless @homework.save
|
unless @homework.save
|
||||||
|
logger.debug @homework.errors.full_messages
|
||||||
else
|
else
|
||||||
student_work = @homework.student_works.where(user_id: User.current.id).first
|
student_work = @homework.student_works.where(user_id: User.current.id).first
|
||||||
end
|
end
|
||||||
|
|
|
@ -368,8 +368,15 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_commit_homework
|
def user_commit_homework
|
||||||
flash[:notice] = l(:notice_successful_create)
|
homework = HomeworkCommon.find(params[:homework])
|
||||||
redirect_to student_work_index_url(:homework => params[:homework])
|
student_work = homework.student_works.where(user_id: User.current.id).first
|
||||||
|
if student_work
|
||||||
|
student_work.save
|
||||||
|
flash[:notice] = l(:notice_successful_create)
|
||||||
|
redirect_to student_work_index_url(:homework => params[:homework])
|
||||||
|
else
|
||||||
|
render_403
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_new_homework
|
def user_new_homework
|
||||||
|
|
|
@ -56,6 +56,10 @@ class HomeworkCommon < ActiveRecord::Base
|
||||||
Mailer.run.homework_added(self)
|
Mailer.run.homework_added(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_program_homework?
|
||||||
|
self.homework_type == 2 && self.homework_detail_programing
|
||||||
|
end
|
||||||
|
|
||||||
delegate :language_name, :to => :homework_detail_programing
|
delegate :language_name, :to => :homework_detail_programing
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,10 +10,32 @@ class StudentWork < ActiveRecord::Base
|
||||||
has_many :student_work_tests, order: 'id desc'
|
has_many :student_work_tests, order: 'id desc'
|
||||||
|
|
||||||
before_destroy :delete_praise
|
before_destroy :delete_praise
|
||||||
|
before_save :set_program_score, :set_src
|
||||||
|
|
||||||
acts_as_attachable
|
acts_as_attachable
|
||||||
|
|
||||||
def delete_praise
|
def delete_praise
|
||||||
PraiseTread.where("praise_tread_object_id = #{self.id} AND praise_tread_object_type = 'StudentWork'").destroy_all
|
PraiseTread.where("praise_tread_object_id = #{self.id} AND praise_tread_object_type = 'StudentWork'").destroy_all
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def last_test
|
||||||
|
student_work_tests.order('id desc').first
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def set_program_score
|
||||||
|
if homework_common.is_program_homework? #编程作业,学生提交作品后计算系统得分
|
||||||
|
#根据最后一次测试计算得分
|
||||||
|
unless last_test
|
||||||
|
self.system_score = 0
|
||||||
|
else
|
||||||
|
self.system_score = last_test.test_score
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
def set_src
|
||||||
|
self.description = last_test.src if last_test
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,10 +34,19 @@ class StudentWorkTest < ActiveRecord::Base
|
||||||
|
|
||||||
def test_score
|
def test_score
|
||||||
if self.status.to_i == 0
|
if self.status.to_i == 0
|
||||||
format("%.1f",100.0 / self.student_work.homework_common.homework_tests.count)
|
100
|
||||||
else
|
elsif self.results.empty?
|
||||||
0
|
0
|
||||||
|
else
|
||||||
|
get_success_count * 100 / self.results.count
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def get_success_count
|
||||||
|
self.results.inject(0) do |sum, result|
|
||||||
|
sum += (result["status"].to_i == 0 ? 1 : 0)
|
||||||
|
end || 0
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue