educoder/app/controllers/myshixuns_controller.rb

94 lines
3.6 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.

# encoding: utf-8
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, :myshixun_reset]
def myshixun_reset
ActiveRecord::Base.transaction do
begin
shixun = @myshixun.shixun
myshixun_job = "myshixun_#{@myshixun.id}"
@myshixun.destroy
myshixun_member = @myshixun
repository = @myshixun.repository
repository.destroy
git_rep = Gitlab.client.delete_project(@myshixun.gpid)
params = {:resubmit => "#{myshixun_job}"}
uri = URI("#{jenkins_shixuns}/jenkins-exec/game/deleteJob")
res = uri_exec uri, params
logger.info("### delete repository result is #{git_rep}")
if git_rep != true
rails("版本库删除异常")
end
rescue e
puts e
raise ActiveRecord::Rollback
end
redirect_to shixun_exec_shixun_path(shixun)
end
end
# taskId 即返回的game id
# 返回结果params [:stauts] 0 表示成功,其它则失败
# msg 错误信息
# output 为测试用户编译输出结果
# myshixun:status 1为完成实训
# @jenkins: caseId对应test_set的positionpassed: 1表示成功0表示失败
# resubmit 1表示已通关后重新评测0表示非重新评测
# retry_status 0初始值1重新评测失败2重新评测成功
def training_task_status
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
status = jsonTestDetails['status']
game_id = jsonTestDetails['buildID']
resubmit = jsonTestDetails['resubmit']
outPut = Base64.urlsafe_decode64(jsonTestDetails['outPut'].gsub(" ", "+")).force_encoding("utf-8") 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.urlsafe_decode64(j_test_set['output'].gsub(" ", "+")).force_encoding("utf-8") 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, :is_public => j_test_set['isPublic'].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"
if resubmit == "1"
game.update_attributes!(:retry_status => 2)
else
game.update_attributes!(:status => 2, :final_score => challenge.score, :end_time => Time.now)
end
else
if resubmit == "1"
game.update_attribute(:retry_status, 1)
else
game.update_attribute(:status, 0)
end
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