From 1c051ba24d1b9f702983cb756977ff8b94fffc31 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 30 May 2019 12:54:19 +0800 Subject: [PATCH] =?UTF-8?q?D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...44812_migrate_shixun_student_work_score.rb | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 db/migrate/20190530044812_migrate_shixun_student_work_score.rb diff --git a/db/migrate/20190530044812_migrate_shixun_student_work_score.rb b/db/migrate/20190530044812_migrate_shixun_student_work_score.rb new file mode 100644 index 00000000..446a2652 --- /dev/null +++ b/db/migrate/20190530044812_migrate_shixun_student_work_score.rb @@ -0,0 +1,28 @@ +class MigrateShixunStudentWorkScore < ActiveRecord::Migration + def up + homeworks = HomeworkCommon.where(id: [18615, 18614, 18617, 18616, 25901, 25902]) + homeworks.each do |homework| + transaction do + challeng_ids = homework.homework_challenge_settings.map(&:challenge_id) + homework.student_works.where("work_status > 0").each do |work| + myshixun = work.myshixun + games = myshixun.games.where(:challenge_id => challeng_ids) + myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil + if myshixun_endtime.present? && myshixun_endtime < homework.end_time + work.work_status = 1 + work.late_penalty = 0 + else + work.work_status = 2 + work.late_penalty = homework.late_penalty + end + score = work.final_score.to_f + work.eff_score.to_f - work.late_penalty.to_f + work.work_score = format("%.2f", score < 0 ? 0 : score.to_f) unless work.ultimate_score + work.save + end + end + end + end + + def down + end +end