自动化构建game

This commit is contained in:
huang 2017-03-17 17:16:10 +08:00
parent 0263165c2b
commit 57f74bb56c
10 changed files with 133 additions and 108 deletions

View File

@ -8,6 +8,7 @@ class GamesController < ApplicationController
def index
@games = @myshixun.games
@games_count = @games.count
respond_to do |format|
format.html
format.js
@ -45,14 +46,24 @@ class GamesController < ApplicationController
gitUrl = git_repository_url(@myshixun, "Myshixun")
gitUrl = Base64.encode64(gitUrl)
taskId = params[:id]
jobName = @myshixun.forked_from
jobName = "myshixun_#{@myshixun.id}"
input = {}
output = {}
test_sets = @game.test_sets
unless test_sets.blank?
test_sets.each do |test_set|
input.store("input",test_set.try(:input))
output.store("output",test_set.try(:input))
end
end
step = @game.stage
if @game.status == 0
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}"}
params = {:jobName => "#{jobName}", :taskId => "#{taskId}", :step => "#{step}", :gitUrl => "#{gitUrl}" }
uri = URI.parse("http://123.59.135.74:9999/jenkins-exec/api/buildJob")
res = uri_exec uri, params
@game.update_attribute(:status, 1)
@outputs = @game.game_outputses
@outputs = @game.outputs
end
respond_to do |format|
format.js
@ -61,10 +72,7 @@ class GamesController < ApplicationController
# 自动推送下一个任务
def next_step
shixun = @myshixun.parent
position = @game.stage + 1
challenge = Challenge.where(:shixun_id => shixun, :position => position).first
render_404 if challenge.blank?
next_game = @game.next_game
next_game = publish_games challenge, @myshixun.id, position
respond_to do |format|
format.html{redirect_to myshixun_game_path(next_game, :myshixun_id => @myshixun.id)}

View File

@ -37,10 +37,11 @@ class ShixunsController < ApplicationController
end
gshixun = g.fork(@shixun.gpid, User.current.gid)
myshixun = copy_myshixun(@shixun, gshixun)
first_challenge = Challenge.where(:shixun_id => @shixun.id, :position => 1).first
render_404 if first_challenge.blank?
game = publish_games(first_challenge, myshixun.id)
challenges = @shixun.challenges
render_404 if challenges.blank?
challenges.each_with_index do |challenge, index|
publish_games(challenge, myshixun.id, index)
end
respond_to do |format|
format.html{redirect_to myshixun_path(myshixun)}
end
@ -129,24 +130,25 @@ class ShixunsController < ApplicationController
@notice = "实训开启失败:请先创建版本库"
return
end
jobName = "#{@shixun.id}"
pipeLine = "#{Base64.encode64(@shixun.script)}"
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
params = {jobName: jobName, pipeLine: pipeLine}
res = uri_exec uri, params
training_shixun_notice res
if res['code'] == 0
@shixun.update_attribute(:status, 1)
end
@shixun.update_attribute(:status, 1)
# jobName = "#{@shixun.id}"
# pipeLine = "#{Base64.encode64(@shixun.script)}"
# uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
# params = {jobName: jobName, pipeLine: pipeLine}
# res = uri_exec uri, params
# training_shixun_notice res
# if res['code'] == 0
# @shixun.update_attribute(:status, 1)
# end
end
# 更新实训job
def shixun_job_update
jobName = "#{@shixun.id}"
pipeLine = "#{Base64.encode64(@shixun.script)}"
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
params = {jobName: jobName, pipeLine: pipeLine}
res = uri_exec uri, params
# jobName = "#{@shixun.id}"
# pipeLine = "#{Base64.encode64(@shixun.script)}"
# uri = URI("http://123.59.135.74:9999/jenkins-exec/api/updateJob")
# params = {jobName: jobName, pipeLine: pipeLine}
# res = uri_exec uri, params
training_shixun_notice res
if res['code'] == 0
@shixun.update_attribute(:status, 1)
@ -191,6 +193,10 @@ class ShixunsController < ApplicationController
if myshixun.save
m = MyshixunMember.new(:user_id => User.current.id, :role => 1)
myshixun.myshixun_members << m
uri = URI("http://123.59.135.74:9999/jenkins-exec/api/createJob")
pipeLine = "#{Base64.encode64(tpm_shixun.script)}"
params = {jobName: "myshixun_#{myshixun.id}", pipeLine: pipeLine}
res = uri_exec uri, params
copy_myshixun_repository(myshixun, gshixun)
return myshixun
end

View File

@ -37,11 +37,13 @@ module ApplicationHelper
# super
# end
# 复制一个任务
def publish_games challenge, myshixun_id
def publish_games challenge, myshixun_id, index
game = Game.new
game.attributes = challenge.attributes.dup.except("id","shixun_id","user_id","visits")
game.myshixun_id = myshixun_id
game.user_id = User.current.id
game.stage = challenge.position
index == 0 ? game.status = 0 : game.status = 3
challenge_samples = challenge.challenge_samples
test_sets = challenge.test_sets
if game.save

View File

@ -1,5 +1,5 @@
class Game < ActiveRecord::Base
# stauts 0: can exe 1failed 2successed
# stauts 0: can exe 1doing 2successed 3:locked
attr_accessible :description, :myshixun_id, :stage, :subject, :user_id, :status, :ready_knowledge, :task_pass, :answer, :score
belongs_to :myshixun,:touch=> true
belongs_to :user
@ -7,4 +7,10 @@ class Game < ActiveRecord::Base
has_many :outputs, :dependent => :destroy
has_many :test_sets, :dependent => :destroy
has_many :challenge_samples, :dependent => :destroy
def next_game
game = Game.where(:myshixun_id => self.myshixun_id, :stage => self.stage + 1).first
render_404 if game.nil?
return game
end
end

View File

@ -9,7 +9,7 @@ class Myshixun < ActiveRecord::Base
# 优先取未完成的任务如果任务都完成则取stage最大的任务有下一步
def current_task
games = self.games
current_game = games.select{|game| game.status != 2}
current_game = games.select{|game| game.status != 2 && game.status != 3}
if current_game.blank?
current_game = Game.where(:status => 2, :myshixun_id => self.id).order("stage desc").first
end

View File

@ -7,12 +7,38 @@
</div>
</div>
<div class="content-history-inner">
<% @outputs.each do |output| %>
<div class="<%= output.code == 0 ? 'clearfix history-success mb10' : 'clearfix history-fail mb10' %>">
<span class="<%= output.code == 0 ? 'icon-success fl mr5' : 'icon-fail fl mr5' %>">2</span>
<p class="fl"><%= output.code == 0 ? '恭喜,您已经完成了本任务!' : '错误结果!' %></p>
<%= link_to "详情", outputs_show_myshixun_game_path(@game, :myshixun_id => @myshixun, :game_output_id => output.id), :class => "fr mr10" %>
</div>
<% unless @outputs.blank? %>
<% @outputs.each do |output| %>
<div class="<%= output.code == 0 ? 'clearfix history-success mb10' : 'clearfix history-fail mb10' %>">
<span class="<%= output.code == 0 ? 'icon-success fl mr5' : 'icon-fail fl mr5' %>">2</span>
<p class="fl"><%= output.code == 0 ? '恭喜,您已经完成了本任务!' : '错误结果!' %></p>
<%= link_to "详情", outputs_show_myshixun_game_path(@game, :myshixun_id => @myshixun, :game_output_id => output.id), :class => "fr mr10" %>
</div>
<% end %>
<% end %>
</div>
</div>
<div class=" col-width fl content-output ml15 mt15">
<div class="panel-header ">
<h3 >测试输出</h3>
</div>
<div class="content-history-inner">
Thor position=(32,4).Light position={32,4}<br/>
Engryg=74
</div>
</div>
<div class=" col-width fl content-submit ml15 mt15">
<div class="panel-header ">
<h3 >操作</h3>
</div>
<div class="content-submitbox">
<a href="#" class="task-btn mb10 ">保存修改</a>
<% if @game.status == 0 %>
<%= link_to "提交评测", {:controller => 'games', :action => "game_build", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :onclick => "training_task_submmit();", :remote => true %>
<% elsif @game.status == 1 %>
<a class="task-btn mb10">评测中..</a>
<% elsif @game.status == 2 %>
<%= link_to "下 一 步", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :onclick => "training_task_submmit();", :remote => true %>
<% end %>
</div>
</div>

View File

@ -12,7 +12,7 @@
<a href="#"><i class="fa fa-minus-square font-14 fl color-grey"></i></a>
</div>
</div>
<div class="tab_content clearfix" >
<div class="tab_content clearfix">
<ul id="tab_nav">
<li id="tab_nav_1" class="tab_hover " onclick="HoverLi(1);">
<a href="javascript:void(0);" class="tab_type">过关任务</a>
@ -44,12 +44,6 @@
<div id="code_results">
<%= render :partial => 'exec_results' %>
</div>
<div id="code_outpus">
<%= render :partial => 'code_outputs' %>
</div>
<div id="code_actions">
<%= render :partial => 'code_actions' %>
</div>
</div>
</div>

View File

@ -1,74 +1,56 @@
<div class="content clearfix" >
<div class="col-width-10 ml15 mt15 mr15">
<div class="panel-header clearfix">
<h3 class="fl">全部任务</h3><span class="btn-cir btn-cir-grey ml5 mt3 fl"><%= @myshixun.games.count %></span>
<h3 class="fl">全部任务</h3><span class="btn-cir btn-cir-grey ml5 mt3 fl"><%= @games_count %></span>
</div>
<div class="panel-list">
<div class=" clearfix panel-inner">
<h4 class="fl panel-inner-title "><i class="fa fa-check-circle font-18 color-green mr5"></i><span class="color-red">第1关</span> Python基础入门</h4>
<p class="fr "><i class="fa fa-trophy color-yellow font-16 mr5 "></i><span class=" color-grey">NO.120</span></p>
<div class="cl"></div>
<p class="ml15 mt15 color-grey">
<span class=" mr10">开始时间2017-02-28 15:08</span>
<span class=" mr10">完成时间2017-02-28 15:28</span>
<span class=" mr10">耗时00小时20分</span>
<span class=" mr10">测评次数3次</span>
<span class=" mr10">得分108分</span>
</p>
</div>
</div>
<div class="panel-list">
<div class=" clearfix panel-inner">
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第2关</span> 用Python语言写程序</h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
<% @games.each do |game| %>
<div class="panel-list">
<div class=" clearfix panel-inner">
<% if game.status == 0 %>
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第<%= game.stage %>关</span> <%= game.subject %></h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" task-btn task-btn-green fr">马上开启</a>
<div class="cl"></div>
<% elsif game.status == 1 %>
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第<%= game.stage %>关</span> <%= game.subject %></h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" fr link-color-green">正在解决中</a>
<div class="cl"></div>
<% elsif game.status == 2 %>
<h4 class="fl panel-inner-title "><i class="fa fa-check-circle font-18 color-green mr5"></i><span class="color-red">第<%= game.stage %>关</span> <%= game.subject %></h4>
<p class="fr "><i class="fa fa-trophy color-yellow font-16 mr5 "></i><span class=" color-grey">NO.120</span></p>
<div class="cl"></div>
<p class="ml15 mt15 color-grey">
<span class=" mr10">开始时间2017-02-28 15:08</span>
<span class=" mr10">完成时间2017-02-28 15:28</span>
<span class=" mr10">耗时00小时20分</span>
<span class=" mr10">测评次数3次</span>
<span class=" mr10">得分108分</span>
</p>
<% elsif game.status == 3 %>
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-lock font-18 color-grey mr5"></i><span class="color-red">第<%= game.stage %>关</span> <%= game.subject %></h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" task-btn fr"> &nbsp;&nbsp;已锁定&nbsp;&nbsp;</a>
<div class="cl"></div>
<% end %>
</div>
</div>
<a href="#" class=" task-btn task-btn-green fr">马上开启</a>
<div class="cl"></div>
</div>
</div>
<div class="panel-list">
<div class=" clearfix panel-inner">
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-dot-circle-o font-18 color-green mr5"></i><span class="color-red">第2关</span> 用Python语言写程序</h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" fr link-color-green">正在解决中</a>
<div class="cl"></div>
</div>
</div>
<div class="panel-list">
<div class=" clearfix panel-inner">
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-lock font-18 color-grey mr5"></i><span class="color-red">第3关</span> Python的字符串使用</h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" task-btn fr"> &nbsp;&nbsp;已锁定&nbsp;&nbsp;</a>
<div class="cl"></div>
</div>
</div>
<div class="panel-list">
<div class=" clearfix panel-inner">
<div class="fl">
<h4 class=" panel-inner-title "><i class="fa fa-lock font-18 color-grey mr5"></i><span class="color-red">第4关</span>关 Python的简单结构</h4>
<p class="ml15 mt15 color-grey">
<span class=" mr10">已闯关2489人</span>
<span class=" mr10">平均耗时0小时28分</span>
</p>
</div>
<a href="#" class=" task-btn fr"> &nbsp;&nbsp;已锁定&nbsp;&nbsp;</a>
<div class="cl"></div>
</div>
</div>
<% end %>
</div>
</div>

View File

@ -0,0 +1 @@
$("#code_results").html('<%= escape_javascript(render :partial => 'games/exec_results') %>');

View File

@ -1,6 +1,6 @@
<% unless @shixun.script.blank? %>
<% if @shixun.status == 1 %>
<%= link_to "重启实训", shixun_job_update_shixun_path(@shixun), :class => "fr sy_btn_green mb10", :remote => true %>
<a class="fr sy_btn_green mb10">已开启</a>
<% else %>
<%= link_to "开启实训", shixun_job_create_shixun_path(@shixun), :class => "fr sy_btn_green mb10", :remote => true %>
<% end %>