69 lines
3.1 KiB
Ruby
69 lines
3.1 KiB
Ruby
# status 控制实训的状态,0:编辑;1: 申请发布; 2:正式发布; 3:关闭
|
||
# is_updated 字段为1表示实训的更改可能会影响到后续的评测,0表示更改不会影响后续的评测
|
||
# 繁忙等级参数:80发布实训失败,返回code为-1;81:实训开启的时候fork失败;83:开启实训的时候,openGameInstance返回非0值;84:jenkins系统异常,post数据不成功
|
||
# 85:challenge创建的时候Jenkins处理异常;86:实训评测失败,jenkins返回错误结果; 87:版本库删除异常;88:点击评测失败,没返回数据;89:重置链接jenkins返回失败
|
||
# 90: 更新公共测试用例失败,返回code非0;91:实训有改动,评测的时候初始化数据,返回数据code非0
|
||
# 116:challenge创建关卡的时候返回结果错误
|
||
#
|
||
class Shixun < ActiveRecord::Base
|
||
attr_accessible :description, :is_public, :name, :changeset_num, :status, :user_id, :gpid, :language, :identifier, :authentication,
|
||
:myshixun_count, :propaedeutics, :is_updated
|
||
|
||
has_many :users, :through => :shixun_members
|
||
has_many :shixun_members, :dependent => :destroy
|
||
has_one :repository
|
||
has_many :homework_commons_shixunses
|
||
has_many :challenges, :dependent => :destroy, :order => "challenges.id ASC"
|
||
has_many :myshixuns
|
||
has_and_belongs_to_many :homework_commons
|
||
|
||
# 获取特定格式的实训测试用例
|
||
# params = {:challengeStage => "#{@challenge.position}", :challengeType => "#{@challenge.evaluation_way.to_i}",
|
||
# :challengeProgramName => "#{@challenge.exec_path}",
|
||
# :trainingID => "#{@shixun.id}", :operationEnvironment => @shixun.language}
|
||
def gameInfo
|
||
fragments = []
|
||
testSet = []
|
||
testCases = []
|
||
challenges = self.challenges.includes(:test_sets)
|
||
challenges.each do |challenge|
|
||
pipeline_script = {:challengeStage => "#{challenge.position}", :challengeType => "#{challenge.evaluation_way.to_i}", :challengeProgramName => "#{challenge.exec_path}", :operationEnvironment => "#{self.language}", :trainingID => "#{self.id}"}
|
||
fragments << pipeline_script
|
||
# 每一关所有的测试集
|
||
challenge.test_sets.each do |test_set|
|
||
test_cases = {:caseId => test_set.id.to_s, :input => test_set.input, :output => test_set.output, :isPublic => (test_set.is_public ? "1" : "0")}
|
||
testSet << test_cases
|
||
end
|
||
test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet}
|
||
testCases << test_sets_list
|
||
testSet = []
|
||
end
|
||
gameInfo = {:trainingID => self.id.to_s, :operationEnvironment => self.language, :challengeInfo => fragments, :testCases => testCases}
|
||
gameInfo = Base64.strict_encode64(gameInfo.to_json) unless gameInfo.blank?
|
||
return gameInfo
|
||
end
|
||
|
||
# id 转换成 identifier
|
||
def to_param
|
||
identifier
|
||
end
|
||
|
||
def owner
|
||
User.find(self.user_id)
|
||
rescue ActiveRecord::RecordNotFound
|
||
render_404
|
||
end
|
||
|
||
def shixun_score
|
||
score = 0
|
||
self.challenges.each do |challenge|
|
||
score += challenge.score
|
||
end
|
||
score
|
||
end
|
||
|
||
def collaborators
|
||
self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank?
|
||
end
|
||
end
|