parent
535e98a7c6
commit
64bc58436b
@ -0,0 +1,18 @@
|
||||
class MigrateExerciseSingleQuestionScore < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
exercise_answers = ExerciseAnswer.joins(:exercise_question).where("exercise_answers.created_at > '2019-11-01 00:00:00'").where(score: -1, exercise_questions: {question_type: [0, 2]})
|
||||
exercise_answers.includes(:exercise_choice, exercise_question: :exercise_standard_answers).find_each do |answer|
|
||||
|
||||
question = answer.exercise_question
|
||||
exercise_user = ExerciseUser.find_by(exercise_id: question.exercise_id, user_id: answer.user_id)
|
||||
user_choice_position = answer.exercise_choice&.choice_position
|
||||
|
||||
if user_choice_position && (user_choice_position.to_i == question.exercise_standard_answers.take&.exercise_choice_id.to_i) && exercise_user
|
||||
answer.update!(score: question.question_score)
|
||||
score = exercise_user.score + question.question_score
|
||||
objective_score = exercise_user.objective_score + question.question_score
|
||||
exercise_user.update!(score: score, objective_score: objective_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in new issue