From 40afc495e753576051ba7d0fcf94ca8d882fb32d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 4 Jun 2019 19:51:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB27641=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=95=88=E7=8E=87=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...190604115012_migrate_homework_eff_score.rb | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 db/migrate/20190604115012_migrate_homework_eff_score.rb diff --git a/db/migrate/20190604115012_migrate_homework_eff_score.rb b/db/migrate/20190604115012_migrate_homework_eff_score.rb new file mode 100644 index 00000000..22e05e65 --- /dev/null +++ b/db/migrate/20190604115012_migrate_homework_eff_score.rb @@ -0,0 +1,41 @@ +class MigrateHomeworkEffScore < ActiveRecord::Migration + def up + homework = HomeworkCommon.where(id: 27641).first + if homework.present? + max_efficiency = homework.max_efficiency + homework.student_works.where(compelete_status: 1).each do |work| + user_total_score = 0 + pass_consume_time = 0 + myshixun = work.myshixun + homework.homework_challenge_settings.each do |setting| + game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first + unless game.nil? + pass_consume_time += (game.cost_time / 60.0).to_f + user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i + end + end + + efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0)) + work.update_column("efficiency", format("%.2f", efficiency)) + + if max_efficiency < work.efficiency + max_efficiency = work.efficiency + end + end + homework.update_column("max_efficiency", max_efficiency) + + homework.student_works.where("compelete_status != 0").each do |student_work| + eff_score = student_work.efficiency / homework.max_efficiency * homework.eff_score + student_work.eff_score = format("%.2f", eff_score) + unless student_work.ultimate_score + work_score = student_work.final_score.to_f + student_work.eff_score - student_work.late_penalty + student_work.work_score = format("%.2f", work_score < 0 ? 0 : work_score) + end + student_work.save + end + end + end + + def down + end +end