From f5a88ef6f9cd24326a0b7eba330888625042b0e0 Mon Sep 17 00:00:00 2001 From: huang Date: Sun, 24 Apr 2016 10:52:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E8=BF=81=E7=A7=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20160224074034_update_one_student_score.rb | 56 ++++++++++--------- ...014316_update_one_student_teacher_score.rb | 22 +++++--- 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/db/migrate/20160224074034_update_one_student_score.rb b/db/migrate/20160224074034_update_one_student_score.rb index 6e1930652..454bd8acd 100644 --- a/db/migrate/20160224074034_update_one_student_score.rb +++ b/db/migrate/20160224074034_update_one_student_score.rb @@ -1,35 +1,39 @@ class UpdateOneStudentScore < ActiveRecord::Migration def up - student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first - student_work_score.score = 100 - student_work_score.save - student_works = StudentWork.where("user_id = 6456") - student_works.each do |work| - unless work.student_works_scores.empty? - if work.student_works_scores.where(:reviewer_role => 2).empty? - work.teaching_asistant_score = nil - else - work.teaching_asistant_score = work.student_works_scores.where(:reviewer_role => 2).average(:score).try(:round, 2).to_f + begin + student_work_score = StudentWorksScore.where("user_id = 11688 AND student_work_id = 34414").first + student_work_score.score = 100 + student_work_score.save + student_works = StudentWork.where("user_id = 6456") + student_works.each do |work| + unless work.student_works_scores.empty? + if work.student_works_scores.where(:reviewer_role => 2).empty? + work.teaching_asistant_score = nil + 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 - if work.student_works_scores.where(:reviewer_role => 3).empty? - work.student_score = nil + if work.teaching_asistant_score.nil? + work.final_score = work.student_score + elsif work.student_score.nil? + work.final_score = work.teaching_asistant_score 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 + work.save end - if work.teaching_asistant_score.nil? - work.final_score = work.student_score - 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 + rescue => e + logger.error "[Errno::ENOENT] ===> #{e}" end end diff --git a/db/migrate/20160329014316_update_one_student_teacher_score.rb b/db/migrate/20160329014316_update_one_student_teacher_score.rb index cf56db220..cdbc9444f 100644 --- a/db/migrate/20160329014316_update_one_student_teacher_score.rb +++ b/db/migrate/20160329014316_update_one_student_teacher_score.rb @@ -1,15 +1,19 @@ class UpdateOneStudentTeacherScore < ActiveRecord::Migration def up - work = StudentWork.find 49774 - score = StudentWorksScore.new - score.score = 100 - score.user_id = 7318 - score.student_work_id = work.id - score.reviewer_role = 1 - if score.save - work.teacher_score = score.score + begin + work = StudentWork.find 49774 + score = StudentWorksScore.new + score.score = 100 + score.user_id = 7318 + score.student_work_id = work.id + score.reviewer_role = 1 + if score.save + work.teacher_score = score.score + end + work.save + rescue => e + logger.error "[Errno::ENOENT] ===> #{e}" end - work.save end def down