answer_open修改为boolean类型

dev_bj
SylorHuang 5 years ago
parent 163149b42f
commit d4489a253f

@ -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

@ -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)

@ -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

@ -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

@ -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

@ -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)

@ -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

@ -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}"

@ -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}"

Loading…
Cancel
Save