迁移27641作业效率分

dev_library
cxt 6 years ago
parent d66cdb9f60
commit 40afc495e7

@ -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
Loading…
Cancel
Save