From d4489a253f6ee56745249afd0660a2f8599fcb94 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 10:45:40 +0800 Subject: [PATCH] =?UTF-8?q?answer=5Fopen=E4=BF=AE=E6=94=B9=E4=B8=BAboolean?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- app/controllers/myshixuns_controller.rb | 2 +- app/services/games_service.rb | 12 ++++++------ .../20171014095120_update_score_and_exp_for_user.rb | 2 +- ...9065522_update_grade_and_experiences_for_users.rb | 2 +- db/migrate/20171020011305_modify_grades_for_user.rb | 2 +- db/migrate/20171101020347_game_final_score.rb | 2 +- .../20190311032811_add_passed_score_for_users.rb | 2 +- .../20190313005345_add_score_for_pass_games.rb | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 1797f3ed..d7caa8de 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -219,10 +219,10 @@ class GamesController < ApplicationController @had_passed_testsests_public_count = had_test.blank? ? 0 : had_test.select{|had_test| had_test.result == true && had_test.is_public == true}.count @mirror_name = @myshixun.mirror_name @final_score = ((@shixun.status <= 1) ? 0 : @game.final_score.to_i) - if @myshixun.shixun.status <= 1 || (@game.final_score != 0 && @game.answer_open > 0) + if @myshixun.shixun.status <= 1 || (@game.final_score != 0 && !@game.answer_open) @gold = 0 else - if @game.answer_open > 0 && @game.final_score ==0 + if !@game.answer_open && @game.final_score ==0 @gold = -@game_challenge.score.to_i else @gold = @game.final_score.to_i diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 85735080..3cd2f247 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -560,7 +560,7 @@ class MyshixunsController < ApplicationController challenge.path.split(";").each do |path| game_passed_code(game.id, path, myshixun.try(:gpid), 1) end - if game.answer_open == 0 && (challenge.shixun.try(:status) > 1) # 如果没有查看答案,则获得该关卡得分 + if !game.answer_open && (challenge.shixun.try(:status) > 1) # 如果没有查看答案,则获得该关卡得分 reward_grade(game.user, game.id, 'Game', challenge.score) reward_experience(game.user, game.id, 'Game', challenge.score) game.update_attributes!(:final_score => challenge.score) diff --git a/app/services/games_service.rb b/app/services/games_service.rb index 7cfe9107..42fdbc86 100644 --- a/app/services/games_service.rb +++ b/app/services/games_service.rb @@ -278,7 +278,7 @@ class GamesService is_teacher = (current_user.user_extensions.identity == 0) is_certification_teacher = current_user.is_certification_teacher # 这几种情况可以直接查看答案的:实训未发布;当前用户为实训管理员;已经查看过答案;平台认证的老师; - if (@shixun.status < 2 || shixun_manager(@shixun, current_user) || @game.answer_open == 1 || is_certification_teacher) + if (@shixun.status < 2 || shixun_manager(@shixun, current_user) || @game.answer_open || is_certification_teacher) Rails.logger.info("answer#{params[:identifier]}#### user is #{current_user.id}, status is #{@shixun.status}, manager is #{shixun_manager(@shixun, current_user)}, open #{@game.answer_open}, cer #{is_certification_teacher}") if challenge.st == 0 result = challenge.try(:answer) @@ -303,7 +303,7 @@ class GamesService challenge_score = challenge.try(:score) final_score = @game.final_score if current_user.grade.to_i - challenge_score > 0 - if @game.answer_open == 0 # 如果这是第一次查看答案 + if !@game.answer_open # 如果这是第一次查看答案 if challenge.st == 0 final_score = final_score - challenge_score # 积分消耗情况记录 @@ -530,7 +530,7 @@ class GamesService game = Game.select([:myshixun_id, :status, :challenge_id, :id, :evaluate_count]).find_by_identifier(params[:identifier]) myshixun = Myshixun.select([:updated_at, :gpid, :id, :shixun_id]).find(game.myshixun_id) shixun = Shixun.select([:id, :evaluate_script, :webssh, :exec_time, :sigle_training, :identifier, :status]).find(myshixun.shixun_id) - game_challenge = Challenge.select([:id, :position, :picture_path]).find(game.challenge_id) + game_challenge = Challenge.select([:id, :position, :picture_path, :exec_time]).find(game.challenge_id) # 更新评测次数 game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1)) @@ -573,7 +573,7 @@ class GamesService params = {:tpiID => "#{myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{taskId}",:instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => shixun.webssh, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(shixun))}", :tpmScript => "#{tpmScript}", - :timeLimit => "#{shixun.exec_time}", :content_modified => content_modified, :persistenceName => shixun.identifier, + :timeLimit => "#{game_challenge.exec_time}", :content_modified => content_modified, :persistenceName => shixun.identifier, :isPublished => (shixun.status < 2 ? 0 : 1), :sec_key => params[:sec_key]} # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 @@ -749,7 +749,7 @@ class GamesService if had_passed && !game.had_passed? game.update_attributes(:status => 2, :end_time => Time.now) # TPM实训已发布并且没有查看答案 - if shixun.is_published? && game.answer_open == 0 + if shixun.is_published? && !game.answer_open # 查看答案的时候处理final_scor和扣分记录 experience = score reward_grade(myshixun.owner, game.id, 'Game', score) @@ -853,7 +853,7 @@ class GamesService if game_status == 2 # 通关 if shixun.status > 1 score = game.final_score # 查看答案的时候有对最终获得金币进行处理 - experience = game.answer_open > 0 ? 0 : game_challenge.score.to_i + experience = game.answer_open ? 0 : game_challenge.score.to_i else score = 0 experience = 0 diff --git a/db/migrate/20171014095120_update_score_and_exp_for_user.rb b/db/migrate/20171014095120_update_score_and_exp_for_user.rb index 038b630f..c1645418 100644 --- a/db/migrate/20171014095120_update_score_and_exp_for_user.rb +++ b/db/migrate/20171014095120_update_score_and_exp_for_user.rb @@ -1,6 +1,6 @@ class UpdateScoreAndExpForUser < ActiveRecord::Migration def up - games = Game.where(:answer_open => 0, :status => 2, :final_score => 0) + games = Game.where(:answer_open => false, :status => 2, :final_score => 0) if games.present? games.each do |game| if game.challenge.shixun.try(:status) == 2 diff --git a/db/migrate/20171019065522_update_grade_and_experiences_for_users.rb b/db/migrate/20171019065522_update_grade_and_experiences_for_users.rb index 4a8c8b8e..8a84c553 100644 --- a/db/migrate/20171019065522_update_grade_and_experiences_for_users.rb +++ b/db/migrate/20171019065522_update_grade_and_experiences_for_users.rb @@ -1,6 +1,6 @@ class UpdateGradeAndExperiencesForUsers < ActiveRecord::Migration def up - games = Game.where(:answer_open => 0, :status => 2, :final_score => 0) + games = Game.where(:answer_open => false, :status => 2, :final_score => 0) if games.present? games.each do |game| if game.challenge.shixun.try(:status) == 2 diff --git a/db/migrate/20171020011305_modify_grades_for_user.rb b/db/migrate/20171020011305_modify_grades_for_user.rb index 5c53ad8c..c21fc6c8 100644 --- a/db/migrate/20171020011305_modify_grades_for_user.rb +++ b/db/migrate/20171020011305_modify_grades_for_user.rb @@ -1,6 +1,6 @@ class ModifyGradesForUser < ActiveRecord::Migration def up - games = Game.where(:answer_open => 0, :status => 2) + games = Game.where(:answer_open => false, :status => 2) if games.present? games.each do |game| user = User.find(game.user_id) diff --git a/db/migrate/20171101020347_game_final_score.rb b/db/migrate/20171101020347_game_final_score.rb index 70f185ec..d2fc2413 100644 --- a/db/migrate/20171101020347_game_final_score.rb +++ b/db/migrate/20171101020347_game_final_score.rb @@ -1,6 +1,6 @@ class GameFinalScore < ActiveRecord::Migration def up - games = Game.where(:answer_open => 0, :final_score => 0, :status => 2) + games = Game.where(:answer_open => false, :final_score => 0, :status => 2) count = games.count / 30 + 2 transaction do for i in 1 .. count do i diff --git a/db/migrate/20190311032811_add_passed_score_for_users.rb b/db/migrate/20190311032811_add_passed_score_for_users.rb index c65550eb..21c2fc1f 100644 --- a/db/migrate/20190311032811_add_passed_score_for_users.rb +++ b/db/migrate/20190311032811_add_passed_score_for_users.rb @@ -1,6 +1,6 @@ class AddPassedScoreForUsers < ActiveRecord::Migration def up - games = Game.where("final_score = 0 and status = 2 and answer_open = 0 and created_at > '2019-03-09 00:00:00'").includes(:challenge) + games = Game.where("final_score = 0 and status = 2 and answer_open = false and created_at > '2019-03-09 00:00:00'").includes(:challenge) puts "game_count: #{games.count}" games.find_each do |game| puts "#{game.id}" diff --git a/db/migrate/20190313005345_add_score_for_pass_games.rb b/db/migrate/20190313005345_add_score_for_pass_games.rb index 0517993c..31cba48b 100644 --- a/db/migrate/20190313005345_add_score_for_pass_games.rb +++ b/db/migrate/20190313005345_add_score_for_pass_games.rb @@ -1,6 +1,6 @@ class AddScoreForPassGames < ActiveRecord::Migration def up - games = Game.where("final_score = 0 and status = 2 and answer_open = 0 and end_time > '2019-03-08 00:00:00'").includes(:challenge) + games = Game.where("final_score = 0 and status = 2 and answer_open = false and end_time > '2019-03-08 00:00:00'").includes(:challenge) puts "game_count: #{games.count}" games.find_each do |game| puts "#{game.id}"