|
|
|
@ -0,0 +1,30 @@
|
|
|
|
|
class MigrateExerciseUserQuestions < ActiveRecord::Migration
|
|
|
|
|
def up
|
|
|
|
|
exercise = Exercise.where(:id => 1031).first
|
|
|
|
|
if exercise.present?
|
|
|
|
|
exercise.exercise_users.each do |exercise_user|
|
|
|
|
|
# 分配的实训题数量多于6个的(撤销发布过的学生会有12个题)则删除前六个题
|
|
|
|
|
if exercise_user.exercise_user_questions.where(:exercise_id => exercise.id).count > 6
|
|
|
|
|
exercise_user.exercise_user_questions[0..5].each do |question|
|
|
|
|
|
question.destroy
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 分数超过一百分的需要重新计算得分
|
|
|
|
|
if exercise_user.objective_score > 100.0
|
|
|
|
|
score = 0
|
|
|
|
|
ExerciseUserQuestion.where(exercise_user_id: exercise_user.id, exercise_id: exercise.id).each do |question|
|
|
|
|
|
question.exercise_shixun_challenges.each do |exercise_cha|
|
|
|
|
|
score += exercise_cha.exercise_shixun_answers.where(user_id => exercise_user.user_id).try(:score).to_f
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
exercise_user.update_attributes(score: score, objective_score: score)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def down
|
|
|
|
|
end
|
|
|
|
|
end
|