Merge branch 'develop' into educoder

dev_shixuns
cxt 6 years ago
commit 9cccdf0b8a

@ -0,0 +1,66 @@
class MigrateExerUserScore < ActiveRecord::Migration
def up
exercise = Exercise.where(:id => 1264).first
if exercise.present?
question = exercise.exercise_questions.first
shixun = question.try(:shixun)
if shixun.present?
exercise.exercise_users.where(:commit_status => 0).each do |exercise_user|
myshixun = Myshixun.where(:shixun_id => shixun.id, :user_id => exercise_user.user_id).first
if myshixun.present? && myshixun.created_at > exercise.publish_time
exercise_user.start_at = myshixun.created_at
exercise_user.commit_status = 1
exercise_user.end_at = exercise.end_time
exercise_user.status = 1
s_score = 0
question.exercise_shixun_challenges.each do |exercise_cha|
game = Game.where(:user_id => exercise_user.user_id, :challenge_id => exercise_cha.challenge_id).first
if game.present?
exercise_cha_score = 0
answer_status = 0
cha_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split("") : []
challeng_path = cha_path.reject(&:blank?)[0].try(:strip)
if game.status == 2 && game.final_score >= 0
exercise_cha_score = exercise_cha.question_score
answer_status = 1
end
if exercise_cha.exercise_shixun_answers.where(:user_id => exercise_user.user_id).empty?
if GameCode.where(:game_id => game.try(:id), :path => challeng_path).first.present?
game_code = GameCode.where(:game_id => game.try(:id), :path => challeng_path).first
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
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 => exercise_user.user_id,
:score => exercise_cha_score, :answer_text => code, :status => answer_status)
end
s_score += exercise_cha_score
end
end
exercise_user.objective_score = s_score
exercise_user.subjective_score = 0
exercise_user.score = s_score
exercise_user.save
end
end
end
end
end
def down
end
end
Loading…
Cancel
Save