59 lines
2.3 KiB
Ruby
59 lines
2.3 KiB
Ruby
class MyshixunsController < ApplicationController
|
||
layout 'base_myshixun'
|
||
skip_before_filter :verify_authenticity_token, :only => [:training_task_status]
|
||
before_filter :require_login, :except => [:training_task_status]
|
||
before_filter :find_myshixun, :only => [:show]
|
||
|
||
# taskId 即返回的game id
|
||
# 返回结果:params [:stauts] 0 表示成功,其它则失败
|
||
# msg 错误信息
|
||
# output 为测试用户编译输出结果
|
||
# myshixun:status 1为完成实训
|
||
# @jenkins: caseId对应test_set的position,passed: 1表示成功,0表示失败
|
||
def training_task_status
|
||
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
|
||
status = jsonTestDetails['status']
|
||
game_id = jsonTestDetails['buildID']
|
||
outPut = Base64.decode64(jsonTestDetails['outPut']) unless jsonTestDetails['outPut'].blank?
|
||
jenkins_testsets = jsonTestDetails['msg']
|
||
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
|
||
game = Game.find(game_id)
|
||
challenge = game.challenge
|
||
# test_sets = challenge.test_sets
|
||
unless jenkins_testsets.blank?
|
||
jenkins_testsets.each do |j_test_set|
|
||
actual_output = Base64.decode64(j_test_set['output']) unless j_test_set['output'].blank?
|
||
output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first
|
||
if output.nil?
|
||
game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'],
|
||
:actual_output => actual_output, :result => j_test_set['passed'].to_i)
|
||
else
|
||
output.update_attributes(:code => status, :out_put => outPut, :actual_output => actual_output, :result => j_test_set['passed'].to_i)
|
||
end
|
||
|
||
end
|
||
end
|
||
if status == "0"
|
||
game.update_attribute(:status, 2)
|
||
game.update_attribute(:final_score, challenge.score)
|
||
else
|
||
game.update_attribute(:status, 0)
|
||
end
|
||
render :json => {:data => "success"}
|
||
end
|
||
|
||
def show
|
||
respond_to do |format|
|
||
format.html{redirect_to myshixun_game_path(@myshixun.current_task, :myshixun_id => @myshixun)}
|
||
end
|
||
end
|
||
|
||
private
|
||
# Find myshixun of id params[:id]
|
||
def find_myshixun
|
||
@myshixun = Myshixun.find_by_identifier(params[:id])
|
||
rescue ActiveRecord::RecordNotFound
|
||
render_404
|
||
end
|
||
end
|