educoder/app/controllers/myshixuns_controller.rb

59 lines
2.3 KiB
Ruby
Raw Normal View History

2017-04-07 10:16:13 +08:00
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
2017-04-18 10:22:28 +08:00
# 返回结果params [:stauts] 0 表示成功,其它则失败
2017-04-07 10:16:13 +08:00
# msg 错误信息
# output 为测试用户编译输出结果
# myshixun:status 1为完成实训
2017-04-18 10:22:28 +08:00
# @jenkins: caseId对应test_set的positionpassed: 1表示成功0表示失败
2017-04-07 10:16:13 +08:00
def training_task_status
2017-04-18 10:22:28 +08:00
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
status = jsonTestDetails['status']
game_id = jsonTestDetails['buildID']
outPut = Base64.urlsafe_decode64(jsonTestDetails['outPut'].gsub(" ", "+")) unless jsonTestDetails['outPut'].blank?
2017-04-18 10:22:28 +08:00
jenkins_testsets = jsonTestDetails['msg']
2017-04-16 10:16:36 +08:00
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
2017-04-18 10:22:28 +08:00
game = Game.find(game_id)
challenge = game.challenge
2017-04-19 20:16:02 +08:00
# test_sets = challenge.test_sets
2017-04-18 10:22:28 +08:00
unless jenkins_testsets.blank?
jenkins_testsets.each do |j_test_set|
2017-04-20 17:19:18 +08:00
actual_output = Base64.decode64(j_test_set['output']) unless j_test_set['output'].blank?
2017-04-21 11:01:57 +08:00
output = Output.where(:game_id => game.id, :test_set_position => j_test_set['caseId'].to_i).first
2017-04-20 17:19:18 +08:00
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
2017-04-18 10:22:28 +08:00
end
end
2017-04-18 23:10:33 +08:00
if status == "0"
2017-04-18 10:22:28 +08:00
game.update_attribute(:status, 2)
game.update_attribute(:final_score, challenge.score)
else
game.update_attribute(:status, 0)
end
render :json => {:data => "success"}
2017-04-07 10:16:13 +08:00
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
2017-04-26 10:19:04 +08:00
@myshixun = Myshixun.find_by_identifier(params[:id])
2017-04-07 10:16:13 +08:00
rescue ActiveRecord::RecordNotFound
render_404
end
end