Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
daiao 6 years ago
commit 053c093f68

@ -4,9 +4,16 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
def create
team = current_competition.competition_teams.new(user: current_user)
Competitions::SaveTeamService.call(team, save_params)
if current_competition.personal? # 个人赛报名
Competitions::CreatePersonalTeamService.call(current_competition, current_user)
else
team = current_competition.competition_teams.new(user: current_user)
Competitions::SaveTeamService.call(team, save_params)
end
render_ok
rescue Competitions::CreatePersonalTeamService::Error => ex
render_error(ex.message)
end
def update
@ -22,6 +29,20 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
render_error(ex.message)
end
def leave
team = current_competition.competition_teams.find(params[:id])
member = team.team_members.find_by(user_id: current_user.id)
return render_error('您不是该战队的成员') if member.blank?
if member.user_id == team.user_id
team.destroy! # 队长退出,战队解散
else
member.destroy!
end
render_ok
end
private
def all_competition_teams

@ -712,6 +712,7 @@ class GamesController < ApplicationController
uid_logger("################params[:resubmit]: #{params[:resubmit]}")
uid_logger("################resubmit_identifier: #{resubmit_identifier}")
uid_logger("################time_out: #{params[:time_out]}")
sec_key = params[:sec_key]
if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? &&
(params[:resubmit] != resubmit_identifier)))
# 代码评测的信息
@ -740,14 +741,14 @@ class GamesController < ApplicationController
end
else # 重新评测
# 如果满足前面的条件,进入此处只可能是结果已返回并存入了数据库
if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库
if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库
game_status = (@game.retry_status == 2 ? 2 : 0) # retry_status是判断重新评测的通关情况。2表示通关
end
end
# 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集
max_query_index = @game.query_index
#max_query_index = @game.outputs.first.try(:query_index)
# max_query_index = @game.outputs.first.try(:query_index)
# 区分评测过未评测过,未评测过按需求取数据
testset_detail max_query_index.to_i, game_challenge
@ -757,9 +758,10 @@ class GamesController < ApplicationController
web_route = game_challenge.try(:web_route)
mirror_name = @shixun.mirror_name
e_record = EvaluateRecord.where(:sec_key => sec_key).first
# 轮询结束,更新评测统计耗时
if game_status == 0 || game_status == 2
e_record = EvaluateRecord.where(:game_id => @game.id).first
if e_record
front_js = format("%.3f", (Time.now.to_f - e_record.try(:updated_at).to_f)).to_f
consume_time = format("%.3f", (Time.now - e_record.created_at)).to_f
@ -767,9 +769,10 @@ class GamesController < ApplicationController
end
end
uid_logger("game is is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
# 记录前端总耗时
record_consume_time = EvaluateRecord.where(:game_id => @game.id).first.try(:consume_time)
record_consume_time = e_record.try(:pod_execute)
max_mem = e_record.try(:max_mem)
# 实训制作者当前拥有的金币
grade = User.where(:id => @game.user_id).pluck(:grade).first
@ -780,7 +783,7 @@ class GamesController < ApplicationController
@base_date = {grade: grade, gold: score, experience: experience, status: game_status, had_done: had_done,
position: game_challenge.position, port: port, record_consume_time: record_consume_time,
mirror_name: mirror_name, picture: picture, web_route: web_route, star: @game.star,
next_game: next_game, prev_game: prev_game}
next_game: next_game, prev_game: prev_game, max_mem: max_mem}
end
# 记录实训花费的时间
@ -852,7 +855,7 @@ class GamesController < ApplicationController
if max_query_index > 0
uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}")
@qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position,
@qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time,
o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c,
test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index}
and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and
@ -866,8 +869,9 @@ class GamesController < ApplicationController
end
@last_compile_output = @qurey_test_sets.first['out_put'].gsub(/\n/, '<br/>').gsub(/\t/, "&nbsp\;&nbsp\;&nbsp\;&nbsp\;&nbsp\;&nbsp\;&nbsp\;&nbsp\;") if @qurey_test_sets.first['out_put'].present?
else
# 没有评测过,第一次进来后的呈现方式
@qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public, t.input, t.output, t.position
FROM test_sets t where t.challenge_id = #{challenge.id}")
FROM test_sets t where t.challenge_id = #{challenge.id}")
end
end

@ -46,6 +46,7 @@ class MyshixunsController < ApplicationController
end
# 代码运行中的信息接口
# 这个方法是中间层主动调用的点击评测后中间层会发送参数过来告诉目前Pod的启动情况一次评测会调用两次请求
def code_runinng_message
begin
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
@ -100,12 +101,11 @@ class MyshixunsController < ApplicationController
game_id = jsonTestDetails['buildID']
sec_key = jsonTestDetails['sec_key']
# 资源消耗
res_usage = jsonTestDetails['resUsage']
logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
resubmit = jsonTestDetails['resubmit']
outPut = tran_base64_decode64(jsonTestDetails['outPut'])
# 资源消耗
max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present?
jenkins_testsets = jsonTestDetails['msg']
compile_success = jsonTestDetails['compileSuccess']
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
@ -140,7 +140,7 @@ class MyshixunsController < ApplicationController
end
end
uid_logger("#############status: #{status}")
record = EvaluateRecord.where(:game_id => game_id).first
record = EvaluateRecord.where(:sec_key => sec_key).first
logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比.
# answer_deduction是查看答案的扣分比例
@ -201,7 +201,7 @@ class MyshixunsController < ApplicationController
if record.present?
consume_time = format("%.3f", (Time.now - record.created_at)).to_f
record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'],
:pod_execute => timeCost['execute'], :test_cases => test_cases_time,
:pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem,
:brige => timeCost['evaluateAllTime'], :return_back => return_back_time)
end
uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")

@ -23,6 +23,11 @@ class Competition < ApplicationRecord
status?
end
# 是否为个人赛
def personal?
competition_staffs.maximum(:maximum) == 1
end
# 报名是否结束
def enroll_ended?
enroll_end_time.blank? || enroll_end_time < Time.now

@ -0,0 +1,27 @@
class Competitions::CreatePersonalTeamService < ApplicationService
Error = Class.new(StandardError)
attr_reader :competition, :user
def initialize(competition, user)
@competition = competition
@user = user
end
def call
raise Error, '个人赛才能报名' unless competition.personal?
is_teacher = user.is_teacher?
raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden?
raise Error, '本竞赛的参赛者限定为:教师' if !is_teacher && competition.member_enroll_forbidden?
enrolled = competition.competition_teams.exists?(user_id: user.id)
multiple_limited = (is_teacher && competition.teacher_multiple_limited?) || (!is_teacher && competition.member_multiple_limited?)
raise Error, '您已报名该竞赛' if enrolled && multiple_limited
ActiveRecord::Base.transaction do
team = competition.competition_teams.create!(name: user.show_name, user_id: user.id)
team.team_members.create!(competition_id: competition, user_id: user.id, role: 1, is_teacher: is_teacher)
end
end
end

@ -17,6 +17,7 @@ class Competitions::SaveTeamService < ApplicationService
is_teacher = team.user.is_teacher?
ActiveRecord::Base.transaction do
team.generate_invite_code if new_record
team.team_type = 1 # 组队竞赛
team.name = params[:name].to_s.strip
team.save!

@ -81,25 +81,25 @@
</div>
<div class="pbt5">
<% if q.question_type == 0 %>
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<div class="pbt5 clearfix main-choice">
<span class="choose-radio pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></span>
</div>
<% end %>
<% elsif q.question_type == 1 %>
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<div class="pbt5 clearfix main-choice">
<span class="choose-checkbox pull-left mt8"></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown(s.choice_text,@request_url) %></span>
<span class="inline-block pull-left choice-text ml10"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></span>
</div>
<% end %>
<% elsif q.question_type == 2 %>
<div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<span class="mr15">
<span class="choose-radio "></span>
<span class="mlr5 inline-block"><%= s.choice_text %></span>
<span class="mlr5 inline-block"><%= "#{(index+65).chr}.#{s.choice_text}" %></span>
</span>
<% end %>
</div>

@ -182,16 +182,16 @@
<div class="clearfix"></div>
<div class="pbt5">
<% if q_type == 0 %>
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
<div class="pbt10 clearfix main-choice">
<span class="choose-radio <%= check_answer %> pull-left mt10"></span>
<span class="inline-block pull-left ml10 choice-text mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
<span class="inline-block pull-left ml10 choice-text mt-2"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></span>
</div>
<% end %>
<div class="clearfix"></div>
<% elsif q_type == 1 %>
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %>
<div class="pbt10 clearfix main-choice">
<% if check_answer %>
@ -199,13 +199,13 @@
<% else %>
<span class="choose-checkbox pull-left mt10"></span>
<% end %>
<span class="inline-block pull-left choice-text ml10 mt-2"><%= to_markdown(s.choice_text,@request_url) %></span>
<span class="inline-block pull-left choice-text ml10 mt-2"><%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %></span>
</div>
<% end %>
<div class="clearfix"></div>
<% elsif q_type == 2 %>
<div class="pbt5 clearfix">
<% q.exercise_choices.each do |s| %>
<% q.exercise_choices.each_with_index do |s,index| %>
<% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %>
<% check_answer = 'choose-answer' %>
<% else %>
@ -213,7 +213,7 @@
<% end %>
<span class="mr15">
<span class="choose-radio <%= check_answer %>"></span>
<span class="mlr5"><%= s.choice_text %></span>
<span class="mlr5"><%= "#{(index+65).chr}.#{s.choice_text}" %></span>
</span>
<% end %>
</div>

@ -676,6 +676,7 @@ Rails.application.routes.draw do
resource :competition_staff
resources :competition_teams, only: [:index, :show] do
post :join, on: :collection
post :leave, on: :member
end
resources :teachers, only: [:index]
resources :students, only: [:index]

Loading…
Cancel
Save