From 6ac210d96b2c6e6ec89d1645c2e19a091b2819c2 Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 1 Mar 2019 19:40:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190301112631_migrate_exer_user_score.rb | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 db/migrate/20190301112631_migrate_exer_user_score.rb diff --git a/db/migrate/20190301112631_migrate_exer_user_score.rb b/db/migrate/20190301112631_migrate_exer_user_score.rb new file mode 100644 index 00000000..d334373c --- /dev/null +++ b/db/migrate/20190301112631_migrate_exer_user_score.rb @@ -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