|
|
@ -106,6 +106,7 @@ class ChallengesController < ApplicationController
|
|
|
|
def update
|
|
|
|
def update
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
tab = params[:tab].to_i
|
|
|
|
tab = params[:tab].to_i
|
|
|
|
|
|
|
|
logger.info("########params[:challenge]:#{params[:challenge]}")
|
|
|
|
@challenge.update_attributes(params[:challenge])
|
|
|
|
@challenge.update_attributes(params[:challenge])
|
|
|
|
if tab == 1
|
|
|
|
if tab == 1
|
|
|
|
@challenge.challenge_tags.delete_all
|
|
|
|
@challenge.challenge_tags.delete_all
|
|
|
@ -120,14 +121,21 @@ class ChallengesController < ApplicationController
|
|
|
|
sets_output = @test_sets.map(&:output)
|
|
|
|
sets_output = @test_sets.map(&:output)
|
|
|
|
sets_input = @test_sets.map(&:input)
|
|
|
|
sets_input = @test_sets.map(&:input)
|
|
|
|
sets_open = @test_sets.map(&:is_public)
|
|
|
|
sets_open = @test_sets.map(&:is_public)
|
|
|
|
|
|
|
|
score = @test_sets.map(&:score)
|
|
|
|
params_hidden = params[:test_set][:hidden].map{|hidden| hidden.to_i == 0}
|
|
|
|
params_hidden = params[:test_set][:hidden].map{|hidden| hidden.to_i == 0}
|
|
|
|
# 测试集变化则需要更新(输入、 输出、 是否隐藏)
|
|
|
|
# 测试集变化则需要更新(输入、 输出、 是否隐藏)
|
|
|
|
if sets_output != params[:test_set][:output] || sets_open != params_hidden || sets_input != params[:test_set][:input]
|
|
|
|
if sets_output != params[:test_set][:output] || sets_open != params_hidden || sets_input != params[:test_set][:input] ||
|
|
|
|
|
|
|
|
score != params[:test_set][:score]
|
|
|
|
@test_sets.delete_all unless @test_sets.blank?
|
|
|
|
@test_sets.delete_all unless @test_sets.blank?
|
|
|
|
if params[:test_set][:hidden].length > 0
|
|
|
|
if params[:test_set][:hidden].length > 0
|
|
|
|
params[:test_set][:input].each_with_index do |input, index|
|
|
|
|
params[:test_set][:input].each_with_index do |input, index|
|
|
|
|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
|
|
|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
|
|
|
TestSet.create(:challenge_id => @challenge.id, :input => "#{input}", :output => "#{params[:test_set][:output][index]}", :is_public => params_hidden[index], :position => (index + 1))
|
|
|
|
logger.info("########:score:----##{params[:test_set][:score][index]}")
|
|
|
|
|
|
|
|
TestSet.create(:challenge_id => @challenge.id, :input => "#{input}",
|
|
|
|
|
|
|
|
:output => "#{params[:test_set][:output][index]}",
|
|
|
|
|
|
|
|
:is_public => params_hidden[index],
|
|
|
|
|
|
|
|
:score => params[:test_set][:score][index],
|
|
|
|
|
|
|
|
:position => (index + 1))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -302,7 +310,9 @@ class ChallengesController < ApplicationController
|
|
|
|
if params[:test_set][:hidden].length > 0
|
|
|
|
if params[:test_set][:hidden].length > 0
|
|
|
|
params[:test_set][:input].each_with_index do |input, index|
|
|
|
|
params[:test_set][:input].each_with_index do |input, index|
|
|
|
|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
|
|
|
unless (input[index] == params[:test_set][:output][index] && input[index].nil?)
|
|
|
|
TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index], :is_public => params_hidden[index], :position => (index + 1))
|
|
|
|
TestSet.create(:challenge_id => @challenge.id, :input => input, :output => params[:test_set][:output][index],
|
|
|
|
|
|
|
|
:is_public => params_hidden[index], :position => (index + 1),
|
|
|
|
|
|
|
|
:score => params[:test_set][:score][index])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|