dev_local
parent
41387c7b82
commit
8ca1d3fe9a
@ -0,0 +1,35 @@
|
|||||||
|
class MigrateHgExerciseScore < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
exercise = Exercise.where(id: [1177]).first
|
||||||
|
if exercise.present?
|
||||||
|
exercise.exercise_users.where(commit_status: 1).each do |ex_user|
|
||||||
|
score = 0
|
||||||
|
exercise_qustions = exercise.user_question_list(ex_user.try(:id))
|
||||||
|
exercise_qustions.each do |question|
|
||||||
|
question.exercise_shixun_challenges.each do |exercise_cha|
|
||||||
|
game = Game.where(:user_id => ex_user.user_id, :challenge_id => exercise_cha.challenge_id).first
|
||||||
|
if game.present?
|
||||||
|
exercise_cha_score = 0
|
||||||
|
if game.final_score >= 0
|
||||||
|
exercise_cha_score = game.status == 2 ? exercise_cha.question_score : game.real_score(exercise_cha.question_score)
|
||||||
|
end
|
||||||
|
|
||||||
|
answer = exercise_cha.exercise_shixun_answers.where(:user_id => ex_user.user_id).first
|
||||||
|
|
||||||
|
if answer.present?
|
||||||
|
score += exercise_cha_score
|
||||||
|
answer.update_attributes(:score => exercise_cha_score)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ex_user.update_attributes(:objective_score => score, :score => score)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in new issue