educoder/app/controllers/myshixuns_controller.rb

54 lines
1.9 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.

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的positionpassed: 1表示成功0表示失败
def training_task_status
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
status = jsonTestDetails['status']
game_id = jsonTestDetails['buildID']
outPut = Base64.decode64(jsonTestDetails['outPut']) unless params[: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
game_outputs = Output.create(:code => status, :game_id => game_id, :out_put => outPut)
unless jenkins_testsets.blank?
jenkins_testsets.each do |j_test_set|
test_set = TestSet.where(:position => j_test_set['caseId'], :challenge_id => challenge).first
test_set.update_attributes(:actual_output => j_test_set['expectedOutput'], :result => j_test_set['passed'].to_i)
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(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end