2015-05-19 10:36:30 +08:00
|
|
|
#学生提交作品表
|
|
|
|
class StudentWork < ActiveRecord::Base
|
2015-09-07 23:47:14 +08:00
|
|
|
attr_accessible :name, :description, :homework_common_id, :user_id, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :project_id, :is_test
|
2015-05-19 10:36:30 +08:00
|
|
|
|
|
|
|
belongs_to :homework_common
|
|
|
|
belongs_to :user
|
2015-05-19 10:56:41 +08:00
|
|
|
has_many :student_works_evaluation_distributions, :dependent => :destroy
|
2015-05-19 11:18:19 +08:00
|
|
|
has_many :student_works_scores, :dependent => :destroy
|
2015-05-21 10:54:02 +08:00
|
|
|
belongs_to :project
|
2015-08-28 12:04:49 +08:00
|
|
|
has_many :student_work_tests, order: 'id desc'
|
2015-05-19 17:12:43 +08:00
|
|
|
|
2015-07-17 14:48:20 +08:00
|
|
|
before_destroy :delete_praise
|
2015-09-09 00:43:54 +08:00
|
|
|
before_save :set_program_score, :set_src
|
2015-07-17 14:48:20 +08:00
|
|
|
|
2015-05-19 17:12:43 +08:00
|
|
|
acts_as_attachable
|
2015-07-17 14:48:20 +08:00
|
|
|
|
|
|
|
def delete_praise
|
|
|
|
PraiseTread.where("praise_tread_object_id = #{self.id} AND praise_tread_object_type = 'StudentWork'").destroy_all
|
|
|
|
end
|
2015-09-09 00:43:54 +08:00
|
|
|
|
|
|
|
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
|
2015-09-18 17:16:31 +08:00
|
|
|
set_final_score self.homework_common,self
|
2015-09-09 00:43:54 +08:00
|
|
|
end
|
|
|
|
def set_src
|
|
|
|
self.description = last_test.src if last_test
|
|
|
|
end
|
|
|
|
|
2015-09-18 11:05:21 +08:00
|
|
|
#成绩计算
|
|
|
|
def set_final_score homework,student_work
|
|
|
|
if homework && homework.homework_detail_manual
|
|
|
|
if homework.homework_type == 1 #匿评作业
|
|
|
|
if homework.teacher_priority == 1 #教师优先
|
|
|
|
if student_work.teacher_score
|
|
|
|
student_work.final_score = student_work.teacher_score
|
|
|
|
else
|
|
|
|
if student_work.teaching_asistant_score.nil?
|
|
|
|
student_work.final_score = student_work.student_score
|
|
|
|
elsif student_work.student_score.nil?
|
|
|
|
student_work.final_score = student_work.teaching_asistant_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_manual.ta_proportion
|
|
|
|
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_ta_score + final_s_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else #不考虑教师评分
|
|
|
|
if student_work.teaching_asistant_score.nil?
|
|
|
|
student_work.final_score = student_work.student_score
|
|
|
|
elsif student_work.student_score.nil?
|
|
|
|
student_work.final_score = student_work.teaching_asistant_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_manual.ta_proportion
|
|
|
|
final_ta_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_s_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_ta_score + final_s_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif homework.homework_type == 2 && homework.homework_detail_programing #编程作业-----设定:系统评分必定不为空
|
|
|
|
if homework.teacher_priority == 1 #教师优先
|
|
|
|
if student_work.teacher_score
|
|
|
|
student_work.final_score = student_work.teacher_score
|
|
|
|
else
|
|
|
|
if student_work.teaching_asistant_score.nil? #教辅未评分
|
|
|
|
if student_work.student_score.nil?
|
|
|
|
student_work.final_score = student_work.system_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_st_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
elsif student_work.student_score.nil? #学生未评分
|
|
|
|
if student_work.teaching_asistant_score.nil?
|
|
|
|
student_work.final_score = student_work.system_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_ts_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
|
|
|
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
|
|
|
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_ts_score + final_st_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else #不考虑教师评分
|
|
|
|
if student_work.teaching_asistant_score.nil? #教辅未评分
|
|
|
|
if student_work.student_score.nil?
|
|
|
|
student_work.final_score = student_work.system_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_programing.ta_proportion + homework.homework_detail_manual.ta_proportion / 2
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_st_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
elsif student_work.student_score.nil? #学生未评分
|
|
|
|
if student_work.teaching_asistant_score.nil?
|
|
|
|
student_work.final_score = student_work.system_score
|
|
|
|
else
|
|
|
|
ta_proportion = homework.homework_detail_programing.ta_proportion + (1.0 - homework.homework_detail_manual.ta_proportion - homework.homework_detail_programing.ta_proportion) / 2
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{ta_proportion}")
|
|
|
|
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_ts_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
final_sy_score = BigDecimal.new("#{student_work.system_score || 0}") * BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}")
|
|
|
|
final_ts_score = BigDecimal.new("#{student_work.teaching_asistant_score}") * BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}")
|
|
|
|
final_st_score = BigDecimal.new("#{student_work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{homework.homework_detail_programing.ta_proportion}") - BigDecimal.new("#{homework.homework_detail_manual.ta_proportion}"))
|
|
|
|
final_score = final_sy_score + final_ts_score + final_st_score
|
|
|
|
student_work.final_score = format("%.2f",final_score.to_f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-19 10:36:30 +08:00
|
|
|
end
|