trustieplus/app/models/shixun.rb

112 lines
4.2 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# encoding: utf-8
# status 控制实训的状态0编辑1: 申请发布; 2正式发布 3关闭
# is_updated 字段为1表示实训的更改可能会影响到后续的评测0表示更改不会影响后续的评测
# 繁忙等级参数80发布实训失败返回code为-181实训开启的时候fork失败;83开启实训的时候openGameInstance返回非0值84jenkins系统异常post数据不成功
# 85challenge创建的时候Jenkins处理异常;86实训评测失败jenkins返回错误结果; 87版本库删除异常88点击评测失败没返回数据89重置链接jenkins返回失败
# 90: 更新公共测试用例失败返回code非091实训有改动评测的时候初始化数据返回数据code非092webssh开启失败接口getConnectInfo返回code值非0
# 93: 实训断开连接失败接口deleteSSH返回code值非0
# 94: 获取评测等待时间失败接口getWaitingTime返回code值为非0
# 116challenge创建关卡的时候返回结果错误
#
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