diff --git a/db/migrate/20190530044812_migrate_shixun_student_work_score.rb b/db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb similarity index 50% rename from db/migrate/20190530044812_migrate_shixun_student_work_score.rb rename to db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb index 446a2652..4eb869b4 100644 --- a/db/migrate/20190530044812_migrate_shixun_student_work_score.rb +++ b/db/migrate/20190530050358_migrate_shixun_student_work_score_2.rb @@ -1,19 +1,22 @@ -class MigrateShixunStudentWorkScore < ActiveRecord::Migration +class MigrateShixunStudentWorkScore2 < 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 + if homework.end_time > Time.now work.work_status = 1 work.late_penalty = 0 - else - work.work_status = 2 - work.late_penalty = homework.late_penalty + else + myshixun = work.myshixun + + if myshixun.status == 1 && myshixun.try(:done_time) < homework.end_time + work.work_status = 1 + work.late_penalty = 0 + else + work.work_status = 2 + work.late_penalty = homework.late_penalty + end 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