数据库为空的迁移问题
This commit is contained in:
parent
c4bd78e442
commit
f5a88ef6f9
|
@ -1,35 +1,39 @@
|
||||||
class UpdateOneStudentScore < ActiveRecord::Migration
|
class UpdateOneStudentScore < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first
|
begin
|
||||||
student_work_score.score = 100
|
student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first
|
||||||
student_work_score.save
|
student_work_score.score = 100
|
||||||
student_works = StudentWork.where("user_id = 6456")
|
student_work_score.save
|
||||||
student_works.each do |work|
|
student_works = StudentWork.where("user_id = 6456")
|
||||||
unless work.student_works_scores.empty?
|
student_works.each do |work|
|
||||||
if work.student_works_scores.where(:reviewer_role => 2).empty?
|
unless work.student_works_scores.empty?
|
||||||
work.teaching_asistant_score = nil
|
if work.student_works_scores.where(:reviewer_role => 2).empty?
|
||||||
else
|
work.teaching_asistant_score = nil
|
||||||
work.teaching_asistant_score = work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
else
|
||||||
|
work.teaching_asistant_score = work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f
|
||||||
|
end
|
||||||
|
if work.student_works_scores.where(:reviewer_role => 3).empty?
|
||||||
|
work.student_score = nil
|
||||||
|
else
|
||||||
|
work.student_score = work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if work.student_works_scores.where(:reviewer_role => 3).empty?
|
if work.teaching_asistant_score.nil?
|
||||||
work.student_score = nil
|
work.final_score = work.student_score
|
||||||
|
elsif work.student_score.nil?
|
||||||
|
work.final_score = work.teaching_asistant_score
|
||||||
else
|
else
|
||||||
work.student_score = work.student_works_scores.where(:reviewer_role => 3).average(:score).try(:round, 2).to_f
|
homework = HomeworkCommon.find work.homework_common_id
|
||||||
|
ta_proportion = homework.homework_detail_manual.ta_proportion
|
||||||
|
final_ta_score = BigDecimal.new("#{work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
||||||
|
final_s_score = BigDecimal.new("#{work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
||||||
|
final_score = final_ta_score + final_s_score
|
||||||
|
work.final_score = format("%.2f",final_score.to_f)
|
||||||
end
|
end
|
||||||
|
work.save
|
||||||
end
|
end
|
||||||
if work.teaching_asistant_score.nil?
|
rescue => e
|
||||||
work.final_score = work.student_score
|
logger.error "[Errno::ENOENT] ===> #{e}"
|
||||||
elsif work.student_score.nil?
|
|
||||||
work.final_score = work.teaching_asistant_score
|
|
||||||
else
|
|
||||||
homework = HomeworkCommon.find work.homework_common_id
|
|
||||||
ta_proportion = homework.homework_detail_manual.ta_proportion
|
|
||||||
final_ta_score = BigDecimal.new("#{work.teaching_asistant_score}") * BigDecimal.new("#{ta_proportion}")
|
|
||||||
final_s_score = BigDecimal.new("#{work.student_score}") * (BigDecimal.new('1.0') - BigDecimal.new("#{ta_proportion}"))
|
|
||||||
final_score = final_ta_score + final_s_score
|
|
||||||
work.final_score = format("%.2f",final_score.to_f)
|
|
||||||
end
|
|
||||||
work.save
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
class UpdateOneStudentTeacherScore < ActiveRecord::Migration
|
class UpdateOneStudentTeacherScore < ActiveRecord::Migration
|
||||||
def up
|
def up
|
||||||
work = StudentWork.find 49774
|
begin
|
||||||
score = StudentWorksScore.new
|
work = StudentWork.find 49774
|
||||||
score.score = 100
|
score = StudentWorksScore.new
|
||||||
score.user_id = 7318
|
score.score = 100
|
||||||
score.student_work_id = work.id
|
score.user_id = 7318
|
||||||
score.reviewer_role = 1
|
score.student_work_id = work.id
|
||||||
if score.save
|
score.reviewer_role = 1
|
||||||
work.teacher_score = score.score
|
if score.save
|
||||||
|
work.teacher_score = score.score
|
||||||
|
end
|
||||||
|
work.save
|
||||||
|
rescue => e
|
||||||
|
logger.error "[Errno::ENOENT] ===> #{e}"
|
||||||
end
|
end
|
||||||
work.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
|
|
Loading…
Reference in New Issue