educoder/db/migrate/20190927091948_change_user_...

34 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

class ChangeUserP02389416Exercise < ActiveRecord::Migration[5.2]
def change
puts "====> start_to_create user exercise_answer"
#分别为第811141516,20,21,26
# 分数分别为2分2分5分2分2分2分2分2分 合计19分
question_ids = [37411,37414,37417,37418,37419,37423,37424,37429]
choice_ids = [117788,117797,117806,117809,117811,117816,117818,117828]
question_scores = [2,2,5,2,2,2,2,2]
question_ids.each_with_index do |q, index|
ex_exercise_user = ExerciseAnswer.where(user_id: 45442, exercise_question_id: q, exercise_choice_id: choice_ids[index])
if ex_exercise_user.exists?
ex_exercise_user.first.update_attribute(:score,question_scores[index])
else
ExerciseAnswer.create(user_id: 45442, exercise_question_id: q, exercise_choice_id: choice_ids[index], score: question_scores[index])
end
end
ex_user = ExerciseUser.where(user_id: 45442, exercise_id: 2561)&.first
if ex_user.present?
if ex_user.score > 65 || ex_user.objective_score > 65
ex_user.update_attributes(score: 65, objective_score: 65)
else
obj_score = ex_user.objective_score.to_i + 19
total_score = ex_user.score.to_i + 19
ex_user.update_attributes(score: total_score, objective_score: obj_score)
end
end
puts "====> end_to_create user exercise_answer"
end
end