game结果列表实时刷新
This commit is contained in:
parent
6f2a55984b
commit
62b579df71
|
|
@ -27,15 +27,8 @@ class ChallengesController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@challenge.save!
|
||||
if params[:sample][:input].length > 0
|
||||
params[:sample][:input].each_with_index do |value, index|
|
||||
unless (value == params[:sample][:output][index] && value.blank?)
|
||||
ChallengeSample.create(:challenge_id => @challenge.id, :input => value, :output => params[:sample][:output][index])
|
||||
end
|
||||
end
|
||||
end
|
||||
if params[:program][:output].length > 0
|
||||
params[:program][:output].each do |output|
|
||||
if params[:test_set][:output].length > 0
|
||||
params[:test_set][:output].each do |output|
|
||||
TestSet.create(:challenge_id => @challenge.id, :input => nil, :output => output)
|
||||
end
|
||||
end
|
||||
|
|
@ -45,11 +38,10 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
end
|
||||
# 向jenkins端发送请求,构建pipeline片段,实时返回结果
|
||||
=begin
|
||||
begin
|
||||
jenkins_shixuns = Redmine::Configuration['jenkins_shixuns']
|
||||
params = {:shixunType => "#{@challenge.evaluation_way.to_i}", :filePath => "#{@challenge.path}", :step => "#{@challenge.position}", :challengeId => "#{@challenge.id}"}
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/generateScriptPerChallenge")
|
||||
uri = URI("#{jenkins_shixuns}/jenkins-exec/api/generatePipelineScriptForEachChallenge")
|
||||
res = uri_exec uri, params
|
||||
if res.blank?
|
||||
raise("jenkins服务器异常")
|
||||
|
|
@ -57,7 +49,6 @@ class ChallengesController < ApplicationController
|
|||
rescue
|
||||
raise("jenkins服务器异常")
|
||||
end
|
||||
=end
|
||||
respond_to do |format|
|
||||
format.html {redirect_to shixun_challenge_path(@challenge, :shixun_id => @shixun), notice: '创建成功!'}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,26 +10,26 @@ class MyshixunsController < ApplicationController
|
|||
# output 为测试用户编译输出结果
|
||||
# myshixun:status 1为完成实训
|
||||
def training_task_status
|
||||
status = params[:status].to_i
|
||||
task_id = params[:taskId]
|
||||
outPut = Base64.decode64(params[:outPut]) unless params[:outPut].blank?
|
||||
message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
||||
game = Game.find(task_id)
|
||||
challenge = game.challenge
|
||||
if status == 0
|
||||
myshixun = game.myshixun
|
||||
games_count = myshixun.games.count
|
||||
if challenge.position == games_count
|
||||
myshixun.update_attribute(:status, 1)
|
||||
end
|
||||
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
game.update_attribute(:status, 2)
|
||||
game.update_attribute(:final_score, challenge.score)
|
||||
else
|
||||
game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
game.update_attribute(:status, 0)
|
||||
end
|
||||
render :json => {:data => "success"}
|
||||
# status = params[:status].to_i
|
||||
# task_id = params[:taskId]
|
||||
# outPut = Base64.decode64(params[:outPut]) unless params[:outPut].blank?
|
||||
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
||||
# game = Game.find(task_id)
|
||||
# challenge = game.challenge
|
||||
# if status == 0
|
||||
# myshixun = game.myshixun
|
||||
# games_count = myshixun.games.count
|
||||
# if challenge.position == games_count
|
||||
# myshixun.update_attribute(:status, 1)
|
||||
# end
|
||||
# game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
# game.update_attribute(:status, 2)
|
||||
# game.update_attribute(:final_score, challenge.score)
|
||||
# else
|
||||
# game_outputs = Output.create(:code => status, :msg => message, :game_id => task_id, :out_put => outPut)
|
||||
# game.update_attribute(:status, 0)
|
||||
# end
|
||||
# render :json => {:data => "success"}
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
|
|||
|
|
@ -81,25 +81,15 @@
|
|||
<li class="clearfix">
|
||||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="sample_inputs_label"></span>
|
||||
<input type="checkbox" name="sample[lock][]" class="fl ml5 mr5 mt8"><span class="fl mr5">锁定</span>
|
||||
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value=""><span class="fl mr5">锁定</span>
|
||||
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
</p>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="sample[input][]" placeholder="输入" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="sample[output][]" placeholder="希望输出" ></textarea>
|
||||
</li>
|
||||
</script>
|
||||
<script id="t:test-answer-list" type="text/html">
|
||||
<li class="clearfix">
|
||||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="inputs_label"></span>
|
||||
<a href="javascript:void(0);" title="增加" class="test_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
<a href="javascript:void(0);" title="删除" class="test_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
</p>
|
||||
<!-- <input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" placeholder="测试输入" />-->
|
||||
<textarea class="panel-form-width-100 panel-box-sizing" id="textarea_output_test" name="program[output][]" placeholder="输入测试集内容" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
|
||||
</li>
|
||||
</script>
|
||||
|
||||
<div id="shixun_form">
|
||||
<li class="clearfix">
|
||||
<label class="panel-form-label fl"><span class="c_red mr5">*</span>名称:</label>
|
||||
|
|
@ -142,7 +132,7 @@
|
|||
<li class="clearfix">
|
||||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="sample_inputs_label">组<%= index + 1 %></span>
|
||||
<input type="checkbox" name="sample[lock][]" class="fl ml5 mr5 mt8"><span class="fl mr5">锁定</span>
|
||||
<input type="checkbox" name="test_set[lock][<%= index %>]" class="fl ml5 mr5 mt8" checked="<%= @challenge.test_sets.is_public? ? true : false %>" value="<%= @challenge.test_sets.is_public? ? true : false %>"><span class="fl mr5">锁定</span>
|
||||
<% if index == 0 %>
|
||||
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,则对学员隐藏该条测试集,但在“提交评测”时也将被自动检测。</span>
|
||||
<% end %>
|
||||
|
|
@ -151,8 +141,8 @@
|
|||
<a href="javascript:void(0)" title="删除" class="sample_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
<% end %>
|
||||
</p>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="sample[input][]" placeholder="输入" ><%= sample.input %></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="sample[output][]" placeholder="希望输出" ><%= sample.output %></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ><%= sample.input %></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ><%= sample.output %></textarea>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
|
|
@ -163,53 +153,15 @@
|
|||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="sample_inputs_label">组1</span>
|
||||
<span class="color-grey fr" style="font-size:12px;">温馨提示:选中“锁定”,则对学员隐藏该条测试集,但在“提交评测”时也将被自动检测。</span>
|
||||
<input type="checkbox" name="sample[lock][]" class="fl ml5 mr5 mt8"><span class="fl mr5">锁定</span>
|
||||
<input type="checkbox" name="test_set[lock][]" class="fl ml5 mr5 mt8" value="" id="1"><span class="fl mr5">锁定</span>
|
||||
<a href="javascript:void(0)" title="增加" class="sample_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
</p>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="sample[input][]" placeholder="输入" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="sample[output][]" placeholder="希望输出" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_input_test" name="test_set[input][]" placeholder="输入" ></textarea>
|
||||
<textarea class="panel-form-width-40 panel-box-sizing" id="textarea_sample_output_test" name="test_set[output][]" placeholder="希望输出" ></textarea>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
</li>
|
||||
<li class="clearfix">
|
||||
<% if params[:action] == "edit" && @challenge.test_sets.count > 0 %>
|
||||
<label class="panel-form-label fl">测试集设置:</label>
|
||||
<ul class="fl task-bg-grey panel-box-sizing" >
|
||||
<% @challenge.test_sets.each_with_index do |test, index| %>
|
||||
<li class="clearfix">
|
||||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="inputs_label">测试集<%= index + 1 %></span>
|
||||
<% if index == 0%>
|
||||
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
|
||||
<% end %>
|
||||
<a href="javascript:void(0);" title="增加" class="test_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
<% if index > 0 %>
|
||||
<a href="javascript:void(0);" title="删除" class="test_icon_remove"><i class="fa fa-times-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
<% end %>
|
||||
</p>
|
||||
<!--<input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" value="<%#= test.input %>"/> -->
|
||||
<textarea class="panel-form-width-100 panel-box-sizing" id="textarea_output_test" name="program[output][]" placeholder="输入测试集内容" ><%= test.output %></textarea>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% else %>
|
||||
<label class="panel-form-label fl">测试集设置:</label>
|
||||
<ul class="fl task-bg-grey panel-box-sizing">
|
||||
<li class="clearfix">
|
||||
<p class="clearfix">
|
||||
<span class="color-green fb fl" name="inputs_label">测试集1</span>
|
||||
<span class="color-grey fr" style="font-size:12px;">温馨提示:在学员"提交评测"时进行自动检测。</span>
|
||||
<a href="javascript:void(0);" title="增加" class="test_icon_add"><i class="fa fa-plus-circle color-grey font-16 ml10 fl mt7"></i></a>
|
||||
</p>
|
||||
<!-- <input type="text" class="panel-form-width-670 panel-form-height-30 mb10" name="program[input][]" id="textarea_input_test" placeholder="测试输入" />-->
|
||||
<textarea class="panel-form-width-100 panel-box-sizing " id="textarea_output_test" name="program[output][]" placeholder="输入用例内容" ></textarea>
|
||||
</li>
|
||||
</ul>
|
||||
<% end %>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="clearfix">
|
||||
<label class=" panel-form-label fl"> 知识/技能点:</label>
|
||||
<div class="fl task-bd-grey">
|
||||
|
|
|
|||
|
|
@ -1,3 +1,6 @@
|
|||
<%= content_for(:header_tags) do %>
|
||||
<%= javascript_include_tag 'baiduTemplate', 'jquery.datetimepicker.js' %>
|
||||
<% end %>
|
||||
<ul id="blacktab_nav">
|
||||
<li id="blacktab_nav_1" class="blacktab_hover " onclick="HoverLi(1);">
|
||||
<a href="javascript:void(0);" class="tab_type">测试结果</a>
|
||||
|
|
@ -9,7 +12,12 @@
|
|||
<div class="cl"></div>
|
||||
</ul>
|
||||
<div class="cl"></div>
|
||||
<div class=" -flex -relative blacktab-inner" >
|
||||
<div id="game_test_set_results"></div>
|
||||
<script id="t:exec_results" type="text/html">
|
||||
</script>
|
||||
|
||||
|
||||
<div class=" -flex -relative blacktab-inner">
|
||||
<div id="blacktab_con_1" class="" >
|
||||
<div class="fit -scroll">
|
||||
<div class="-layout-v -fit">
|
||||
|
|
@ -35,8 +43,8 @@
|
|||
<li><span class="-task-ces-info-left color-blue">期望输出:</span><span><%= test_set.output %></span></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -68,4 +76,157 @@
|
|||
$("#test_case_"+id).toggle();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="code_results" class="panel-footer CELL COLS mt15 ml15">
|
||||
</div>
|
||||
<script id="t:exec_results" type="text/html">
|
||||
<div class="col-width content-history CELL mb15" >
|
||||
<div class="panel-header clearfix">
|
||||
<h3 class="fl">测评历史</h3>
|
||||
<div class="fr mt5">
|
||||
<a href="javascript:void(0)" onclick="extend_window()"><i class="fa fa-expand font-14 fl color-grey"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content-history-inner">
|
||||
<!--<! if (results.length != 0) { !>-->
|
||||
<! for(var i=0;i< results.length; i++) { !>
|
||||
<! if(results[i][0] == 0){ !>
|
||||
<div class="clearfix history-success mb10">
|
||||
<span class="icon-success fl mr5"><!= results.length - i !></span>
|
||||
<p class="fl">恭喜,您已经完成了本任务!</p>
|
||||
<a href="/myshixuns/<%= @myshixun.id %>/games/<%= @game.id %>/outputs_show?game_output_id=<!= results[i][1] !>" class="fr mr10" data-remote="true">详情</a>
|
||||
</div>
|
||||
<! }else{ !>
|
||||
<div class="clearfix history-fail mb10">
|
||||
<span class="icon-fail fl mr5"><!= results.length - i !></span>
|
||||
<p class="fl">错误结果!</p>
|
||||
<a href="/myshixuns/<%= @myshixun.id %>/games/<%= @game.id %>/outputs_show?game_output_id=<!= results[i][1] !>" class="fr mr10" data-remote="true">详情</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="undis" style="background: #f5f9fc;padding: 10px;margin-top:-10px;margin-bottom: 10px" id="game_exception_results_<!= results[i][1] !>"></div>
|
||||
<! } !>
|
||||
<! } !>
|
||||
<!--<! } !>-->
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-width content-output ml15 CELL mb15">
|
||||
<div class="panel-header clearfix">
|
||||
<h3>测试输出</h3>
|
||||
</div>
|
||||
<div class="content-history-inner" id="game_test_output"></div>
|
||||
<div class="undis" id="game_test_output1">
|
||||
<%= h @latest_output %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-width content-submit ml15 CELL mb15">
|
||||
<div class="panel-header">
|
||||
<h3 >操作</h3>
|
||||
</div>
|
||||
<div class="content-submitbox">
|
||||
<div id="game_rep_modify">
|
||||
</div>
|
||||
<! if(status == 0){ !>
|
||||
<div id="game_commit">
|
||||
<a href="javascript:void(0)" class="task-btn task-btn-green" onclick="training_task_submmit();">提交评测</a>
|
||||
</div>
|
||||
<! }else if(status == 1){ !>
|
||||
<a class="task-btn mb10">评测中..</a>
|
||||
<! }else if(status == 2 && had_done != 1){ !>
|
||||
<%= link_to "下 一 关", {:controller => 'games', :action => "next_step", :id => @game, :myshixun_id => @myshixun}, :class => "task-btn task-btn-green", :remote => true %>
|
||||
<! } !>
|
||||
<! if(had_done == 1) { !>
|
||||
<a href="javascript:void(0)" class="task-btn mb10" >已通关</a>
|
||||
<! } !>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script >
|
||||
var bt = baidu.template;
|
||||
bt.LEFT_DELIMITER = '<!';
|
||||
bt.RIGHT_DELIMITER = '!>';
|
||||
$(function(){
|
||||
var html = bt('t:exec_results',{status: <%= @game.status %>, results: <%= @results %>, had_done: "<%= @had_done %>"});
|
||||
$("#code_results").html(html);
|
||||
$("#game_test_output").html($("#game_test_output1").text())
|
||||
});
|
||||
function training_task_submmit(){
|
||||
var i = 0;
|
||||
$("#ajax-indicator").show();
|
||||
$("#game_commit").html("<a class='task-btn mb10'>评测中..</a>");
|
||||
$.ajax({
|
||||
url: '<%= game_build_myshixun_game_path(@game, :myshixun_id => @myshixun) %>',
|
||||
success: function (){
|
||||
//移除载入
|
||||
var temp = $("#ajax-indicator").children('span')[0];
|
||||
$("#ajax-indicator").children('span')[0].remove();
|
||||
$("#ajax-indicator").css('border', 0);
|
||||
$("#ajax-indicator").css('padding', 0);
|
||||
|
||||
var intId = setInterval(function(){
|
||||
var ajaxTimeoutTest = $.ajax({
|
||||
url: '<%= game_status_myshixun_game_path(@game, :myshixun_id => @myshixun) %>',
|
||||
timeout : 50000,
|
||||
data:'test',
|
||||
success:function(data){
|
||||
//如果查到了,就退出
|
||||
// i变量用来统计setInterval执行了多少次,便于统计访问时间
|
||||
i = i + 1;
|
||||
if(data.status == 2 || data.status == 0){
|
||||
clearInterval(intId);
|
||||
// 显示载入
|
||||
$("#ajax-indicator").html(temp);
|
||||
$("#ajax-indicator").css('border', "1px solid #bbb");
|
||||
$("#ajax-indicator").css('padding', "0.6em");
|
||||
var html = bt('t:exec_results',{status: data.status, results: data.results, had_done: data.had_done});
|
||||
$("#code_results").html(html);
|
||||
console.log(data.output)
|
||||
$("#game_test_output").html(data.output)
|
||||
var html = bt('t:extend_exec_results',{status: data.status, output: data.output, results: data.results, had_done: data.had_done});
|
||||
$("#extend_code_results").html(html);
|
||||
if(data.status == 2){
|
||||
if( data.had_done == 0 ) {
|
||||
var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game=> @game, :myshixun => @myshixun, :had_done => 0}) %>";
|
||||
}else{
|
||||
var htmlvalue = "<%= j (render :partial => 'games/pass_game_show', :locals => { :game=> @game, :myshixun => @myshixun, :had_done => 1}) %>";
|
||||
}
|
||||
// 传递具体屏幕的宽高,实现不同浏览器与不同分辨率都能撑满屏幕
|
||||
pop_box_new2(htmlvalue, window.innerWidth, window.innerHeight);
|
||||
}
|
||||
}
|
||||
// 访问30次,即60s后后台还未改变状态即执行
|
||||
if(i == 30){
|
||||
$.ajax({
|
||||
url: '<%= change_status_myshixun_game_path(@game, :myshixun_id => @myshixun) %>',
|
||||
success:function(data){
|
||||
clearInterval(intId);
|
||||
var html = bt('t:exec_results',{status: data.status, output: data.output, results: data.results, had_done: data.had_done});
|
||||
$("#code_results").html(html);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
complete: function(XMLHttpRequest,status){if(status=='timeout'){
|
||||
ajaxTimeoutTest.abort();
|
||||
clearInterval(intId);
|
||||
}}
|
||||
});
|
||||
}, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
function extend_window(){
|
||||
$("#extend_code_results").show();
|
||||
}
|
||||
function file_edit_submit1(){
|
||||
$('#file_update_id').submit();
|
||||
$("#bottom_save_edit").hide();
|
||||
}
|
||||
|
||||
</script>
|
||||
Loading…
Reference in New Issue