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

dev_forum
cxt 5 years ago
commit 8de2fec21e

@ -184,14 +184,13 @@ class ApplicationController < ActionController::Base
end
# 系统全局认证
#
def check_auth
if !current_user.profile_completed?
info_url = '/account/profile'
tip_exception(402, info_url)
elsif current_user.certification != 1
if current_user.certification != 1
day_cer = UserDayCertification.find_by(user_id: current_user.id)
tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400
elsif !current_user.profile_completed?
info_url = '/account/profile'
tip_exception(402, info_url)
end
end

@ -15,8 +15,18 @@ class Competitions::CompetitionModulesController < Competitions::BaseController
md = current_module.competition_module_md_content || current_module.build_competition_module_md_content
md.name = params[:md_name]
md.content = params[:md_content]
ActiveRecord::Base.transaction do
md.save!
attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i)
old_attachment_ids = md.attachments.pluck(:id)
destroy_ids = old_attachment_ids - attachment_ids
md.attachments.where(id: destroy_ids).delete_all
Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md)
end
render_ok
end

@ -4,9 +4,16 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
def create
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
@ -33,13 +54,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController
end
@count = teams.count
@teams = paginate(teams.includes(:user, users: :user_extension))
@teams = paginate(teams.includes(:user, users: { user_extension: :school }))
end
def user_competition_teams
teams = current_competition.competition_teams
teams = teams.joins(:team_members).where(team_members: { user_id: current_user.id })
@teams = teams.includes(:user, users: :user_extension).to_a
@teams = teams.includes(:user, users: { user_extension: :school }).to_a
@count = @teams.size
end

@ -667,6 +667,7 @@ class ExercisesController < ApplicationController
#立即发布的弹窗内容
def publish_modal
ActiveRecord::Base.transaction do
begin
exercise_ids = params[:check_ids]
@ -685,6 +686,9 @@ class ExercisesController < ApplicationController
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
def publish
tip_exception("缺少截止时间参数") if params[:end_time].blank?
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
ActiveRecord::Base.transaction do
begin
check_ids = Exercise.where(id: params[:check_ids])

@ -47,7 +47,7 @@ class GamesController < ApplicationController
max_query_index = @game.query_index.to_i
# 统计评测时间
record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time)
record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:pod_execute)
# myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员平台认证的老师花费金币查看者)
myshixun_manager = @identity < User::EDU_GAME_MANAGER
@ -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)))
# 代码评测的信息
@ -757,9 +758,10 @@ class GamesController < ApplicationController
web_route = game_challenge.try(:web_route)
mirror_name = @shixun.mirror_name
e_record = EvaluateRecord.where(:identifier => 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,6 +869,7 @@ 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}")
end

@ -46,6 +46,7 @@ class MyshixunsController < ApplicationController
end
# 代码运行中的信息接口
# 这个方法是中间层主动调用的点击评测后中间层会发送参数过来告诉目前Pod的启动情况一次评测会调用两次请求
def code_runinng_message
begin
jsonTestDetails = JSON.parse(params[:jsonTestDetails])
@ -100,12 +101,13 @@ 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'])
# 资源消耗
uid_logger("##########!!!!!!#{jsonTestDetails['resUsage']}")
max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present?
uid_logger("##########!!!!!!#{max_mem}")
jenkins_testsets = jsonTestDetails['msg']
compile_success = jsonTestDetails['compileSuccess']
# message = Base64.decode64(params[:msg]) unless params[:msg].blank?
@ -130,6 +132,7 @@ class MyshixunsController < ApplicationController
# is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public)
logger.info "actual_output:################################################# #{actual_output}"
ts_time = format("%.3f", j_test_set['testSetTime'].to_i).to_f
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, :query_index => max_query_index,
:compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => j_test_set['testSetTime'])
@ -140,7 +143,7 @@ class MyshixunsController < ApplicationController
end
end
uid_logger("#############status: #{status}")
record = EvaluateRecord.where(:game_id => game_id).first
record = EvaluateRecord.where(:identifier => 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是查看答案的扣分比例
@ -200,8 +203,9 @@ class MyshixunsController < ApplicationController
test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f
if record.present?
consume_time = format("%.3f", (Time.now - record.created_at)).to_f
uid_logger("11122233334444#{max_mem}, #{sec_key}")
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")}")

@ -205,15 +205,15 @@ class PollsController < ApplicationController
@is_teacher_or = 1
@user_poll_answer = 3 #教师页面
end
poll_status = @poll.get_poll_status(current_user)
@poll_status = @poll.get_poll_status(current_user)
poll_id_array = [@poll.id]
@poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的
@poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的
if (@poll_publish_count == 0) && (@poll_unpublish_count == 0) #即表示没有分班
if poll_status == 1
if @poll_status == 1
@poll_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候
elsif poll_status == 2
elsif @poll_status == 2
@poll_publish_count = 1 #试卷未发布,且课堂没有分班的时候
end
end
@ -244,6 +244,9 @@ class PollsController < ApplicationController
end
#首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。
def publish
tip_exception("缺少截止时间参数") if params[:end_time].blank?
tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now)
tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day)
ActiveRecord::Base.transaction do
begin
check_ids = Poll.where(id: params[:check_ids])

@ -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

@ -41,9 +41,7 @@ class Discuss < ApplicationRecord
# end
def child_discuss(user)
user.admin? ?
Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) :
Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc)
Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc)
end
private

@ -127,8 +127,10 @@ class Exercise < ApplicationRecord
#判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间
def get_exercise_status(user)
return Exercise::UNPUBLISHED if user.nil?
if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态
if course.is_end
status = 4
else
if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态
ex_time = get_exercise_times(user_id,false)
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
@ -142,6 +144,7 @@ class Exercise < ApplicationRecord
else
status = exercise_status #当为老师的时候,则为试卷的总状态
end
end
status
end

@ -61,7 +61,7 @@ class Game < ApplicationRecord
if self.status == 2 # 通关了则取实际得分,没通关则取总分
gold = (shixun_status <= 1) ? 0 : self.final_score.to_i
# 只要过关了查看了答案经验值就是0通关前查看了答案金final_score为负数
experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.score.to_i
experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : self.final_score.to_i
else
gold = challenge.score.to_i
experience = gold

@ -100,7 +100,10 @@ class Poll < ApplicationRecord
end
def get_poll_status(user)
if user.student_of_course?(course)
if course.is_end
status = 4
else
if user.present? && user.student_of_course?(course)
ex_time = get_poll_times(user_id,false)
pb_time = ex_time[:publish_time]
ed_time = ex_time[:end_time]
@ -114,6 +117,7 @@ class Poll < ApplicationRecord
else
status = polls_status
end
end
status
end

@ -10,7 +10,7 @@ module Searchable::Dependents::ChallengeTag
def check_searchable_dependents
if new_record? || name_previously_changed?
challenge.shixun.reindex(:searchable_challenge_data)
challenge.shixun.reindex
end
end
end

@ -9,7 +9,7 @@ module Searchable::Dependents::Stage
def check_searchable_dependents
if name_previously_changed? || description_previously_changed?
subject.reindex(:searchable_stages_data)
subject.reindex
end
end
end

@ -10,13 +10,13 @@ module Searchable::Dependents::User
def check_searchable_dependents
if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed?
# reindex shixun
created_shixuns.each{ |shixun| shixun.reindex(:searchable_user_data) }
created_shixuns.each(&:reindex)
# reindex course
manage_courses.each(&:reindex)
# reindex subject
created_subjects.each { |subject| subject.reindex(:searchable_user_data) }
created_subjects.each(&:reindex)
end
end
end

@ -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>

@ -5,4 +5,7 @@ if md.present?
json.md_name md.name
json.md_content md.content
json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S')
json.attachments do
json.array! md.attachments, partial: 'attachments/attachment_simple', as: :attachment
end
end

@ -1,5 +1,6 @@
competition = current_competition
json.personal competition.personal?
json.enroll_ended competition.enroll_ended?
json.enrolled competition.enrolled?(current_user)

@ -17,6 +17,9 @@ json.competition_teams do
json.partial! 'users/user_simple', user: member.user
json.user_id member.user_id
json.role member.en_role
json.identity member.user.identity
json.school_name member.user.school_name
json.student_id member.user.student_id
end
end
end

@ -7,6 +7,7 @@ json.test_sets @qurey_test_sets do |test_set|
json.actual_output evaluate_actual_output(test_set)
end
json.compile_success test_set.try(:compile_success)
json.ts_time test_set.try(:ts_time)
end
json.allowed_unlock @shixun.test_set_permission

@ -1,4 +1,4 @@
json.(@base_date, :grade, :gold, :experience, :status, :had_done, :position, :port, :record_consume_time, :mirror_name,
:picture, :web_route, :star, :next_game, :prev_game)
:picture, :web_route, :star, :next_game, :prev_game, :max_mem)
# # 测试集相关
json.partial! 'games/testset_list'

@ -7,7 +7,7 @@ json.group_list do
end
end
# 未分班展示情况放在最后
if @course_groups.count < @limit.to_i
if @course_groups.count > 0 && @course_groups.count < @limit.to_i
ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids)
if ungroup_work_count > 0
json.ungroup_list do

@ -1,5 +1,6 @@
json.course_is_end @course.is_end # true表示已结束false表示未结束
json.extract! @poll, :id,:polls_name,:polls_description,:polls_status,:show_result
json.extract! @poll, :id,:polls_name,:polls_description,:show_result
json.polls_status @poll_status
json.user_permission do
json.is_teacher_or @is_teacher_or

@ -13,6 +13,9 @@ json.top do
json.message_url "#{@old_domain}#{@user_url}/user_tidings"
json.new_message @new_message
json.moop_cases_url "#{@old_domain}/moop_cases"
json.crowdsourcing_url "#{@old_domain}/crowdsourcing"
json.career_url do
json.array! @career.to_a do |c|
if c[1].present?

@ -1,13 +0,0 @@
defaults: &defaults
url: http://localhost:9200
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/'
# url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com'

@ -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