112 lines
4.2 KiB
Ruby
112 lines
4.2 KiB
Ruby
# encoding: utf-8
|
||
# 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;92:webssh开启失败,接口getConnectInfo返回code值非0
|
||
# 93: 实训断开连接失败,接口deleteSSH返回code值非0
|
||
# 94: 获取评测等待时间失败,接口getWaitingTime返回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, :trainee, :major_id, :homepage_show, :webssh, :hidden, :fork_from, :can_copy
|
||
|
||
has_many :users, :through => :shixun_members
|
||
has_many :shixun_members, :dependent => :destroy
|
||
has_one :repository, :dependent => :destroy
|
||
has_many :homework_commons_shixunses
|
||
has_many :challenges, :dependent => :destroy, :order => "challenges.position ASC"
|
||
has_many :myshixuns, :dependent => :destroy
|
||
has_many :stage_shixuns, :dependent => :destroy
|
||
belongs_to :major
|
||
belongs_to :major_course
|
||
has_many :shixun_major_courses, :dependent => :destroy
|
||
has_and_belongs_to_many :homework_commons
|
||
has_many :discusses, :as => :dis, :dependent => :destroy
|
||
has_many :shixun_ports
|
||
|
||
scope :visible, lambda{where(status: [2,3])}
|
||
|
||
include ApplicationHelper
|
||
# 获取特定格式的实训测试用例
|
||
# 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}"}
|
||
fragments << pipeline_script
|
||
# 每一关所有的测试集
|
||
challenge.test_sets.each do |test_set|
|
||
test_cases = {:input => test_set.input, :output => test_set.output}
|
||
testSet << test_cases
|
||
end
|
||
test_sets_list = {:challengeStage => challenge.position.to_s, :challengeTestCases => testSet}
|
||
testCases << test_sets_list
|
||
testSet = []
|
||
end
|
||
gameInfo = {:tpmID => self.id.to_s, :operationEnvironment => "#{self.try(:language)}", :challengeInfo => fragments, :testCases => testCases}
|
||
gameInfo = Base64.urlsafe_encode64(gameInfo.to_json) unless gameInfo.blank?
|
||
return gameInfo
|
||
end
|
||
|
||
# id 转换成 identifier
|
||
def to_param
|
||
identifier
|
||
end
|
||
|
||
def shixun_trainee
|
||
trainee = ""
|
||
case self.trainee
|
||
when 1
|
||
trainee = "初级学员"
|
||
when 2
|
||
trainee = "中级学员"
|
||
when 3
|
||
trainee = "高级学员"
|
||
when 4
|
||
trainee = "顶级学员"
|
||
end
|
||
trainee
|
||
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.to_i
|
||
end
|
||
score
|
||
end
|
||
|
||
def shixun_status
|
||
status = ""
|
||
case self.status
|
||
when 0
|
||
status = "编辑中"
|
||
when 1
|
||
status = "审核中"
|
||
when 2
|
||
status = "已发布"
|
||
when 3
|
||
status = "已关闭"
|
||
end
|
||
end
|
||
|
||
def collaborators
|
||
self.shixun_members.select{|member| member.role == 2} unless self.shixun_members.blank?
|
||
end
|
||
end
|