dev_local
cxt 5 years ago
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

@ -0,0 +1,62 @@
class MigrateExerciseShixunAnswer < ActiveRecord::Migration
def up
exercise = Exercise.where(id: [1060]).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?
answer.update_attributes(:score => exercise_cha_score)
else
answer_status = game.status == 2 ? 1 : 0
challeng_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split("") : []
challeng_path = challeng_path.reject(&:blank?)[0].try(:strip)
game_code = GameCode.where(:game_id => game.try(:id), :path => challeng_path).first
if game_code.present?
code = game_code.try(:new_code)
else
begin
g = Gitlab.client
Rails.logger.info "commit_exercise_path---- #{challeng_path}"
if game.present?
code = g.files(game.myshixun.gpid, challeng_path, "master").try(:content)
else
code = g.files(question.shixun.gpid, challeng_path, "master").try(:content)
end
code = tran_base64_decode64(code)
rescue Exception => e
@error_messages = e.message
Rails.logger.info "commit_exercise---- #{@error_messages}"
end
end
ExerciseShixunAnswer.create(:exercise_question_id => question.id, :exercise_shixun_challenge_id => exercise_cha.id,
:user_id => ex_user.user_id, :score => exercise_cha_score, :answer_text => code,
:status => answer_status)
end
score += exercise_cha_score
end
end
end
ex_user.update_attributes(:objective_score => score, :score => score)
end
end
end
def down
end
end

@ -0,0 +1,31 @@
class MigrateExerciseGameCode < ActiveRecord::Migration
def up
exercise = Exercise.where(id: [1060]).first
if exercise.present?
exercise.exercise_users.where(commit_status: 1).each do |ex_user|
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?
answer = exercise_cha.exercise_shixun_answers.where(:user_id => ex_user.user_id).first
if answer.present?
challeng_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split("") : []
challeng_path = challeng_path.reject(&:blank?)[0].try(:strip)
game_code = GameCode.where(:game_id => game.try(:id), :path => challeng_path).first
if game_code.present?
code = game_code.try(:new_code)
answer.update_attributes(:answer_text => code)
end
end
end
end
end
end
end
end
def down
end
end
Loading…
Cancel
Save