dev_local
daiao 6 years ago
parent ec416ba374
commit dfc7ed119d

@ -30,6 +30,7 @@ class Exercise < ActiveRecord::Base
end
def create_user_question_list exercise_user_id
self.exercise_user_questions.where(exercise_user_id: exercise_user_id).destroy_all
self.exercise_questions.where("question_type != 5").each do |question|
ExerciseUserQuestion.create(exercise_id: self.id, exercise_user_id: exercise_user_id, exercise_question_id: question.id)
end

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