shixun file update

dev_forum
jingquan huang 5 years ago
parent e48b935043
commit 0d5361b59c

@ -243,55 +243,56 @@ class MyshixunsController < ApplicationController
# -----Repository # -----Repository
# TODO: 之类需要一个resubmit参数,但是是关于games. # TODO: 之类需要一个resubmit参数,但是是关于games.
def update_file def update_file
@hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first begin
tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first
path = params[:path].strip unless params[:path].blank? tip_exception("技术平台为空!") if @myshixun.mirror_name.blank?
game_id = params[:game_id] path = params[:path].strip unless params[:path].blank?
game = Game.find(game_id) game_id = params[:game_id]
@content_modified = 0 game = Game.find(game_id)
# params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 @content_modified = 0
# 自动保存的时候evaluate为0点评测的时候为1
if params[:evaluate] == 1 # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过
record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id) # 自动保存的时候evaluate为0点评测的时候为1
uid_logger("-- game is #{game_id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") if params[:evaluate] == 1
student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f @sec_key = generate_identifier(EvaluateRecord, 12)
record.update_attributes!(:student_work => student_work_time) record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id,
end :identifier => @sec_key)
unless @hide_code uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}")
# 远程版本库文件内容 end
last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] unless @hide_code
# 远程版本库文件内容
last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"]
content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? content = params[:content]
params[:content].gsub(/\t/, ' ')
else
params[:content]
end
if content != last_content
@content_modified = 1
author_name = current_user.full_name if content != last_content
author_email = current_user.mail @content_modified = 1
message = params[:evaluate] == 0 ? "auto commit" : "task commit"
@content = GitService.update_file(repo_path: @repo_path,
file_path: path,
message: message,
content: content,
author_name: author_name,
author_email: author_email)
uid_logger("-- file update #{@content}") author_name = current_user.full_name
author_email = current_user.mail
message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted"
@content = GitService.update_file(repo_path: @repo_path,
file_path: path,
message: message,
content: content,
author_name: author_name,
author_email: author_email)
end
end end
end
if game.status == 2 if game.status == 2
@resubmit = Time.now.to_i @resubmit = Time.now.to_i
end end
# 评测时间记录 # 评测时间记录
if record.present? if record.present?
consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f
record.update_attributes!(:file_update => consume_time) record.update_attributes!(:file_update => consume_time)
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("文件内容更新异常,请稍后重试")
end end
end end

@ -1,3 +1,4 @@
json.content @content json.content @content
json.resubmit "#{@resubmit}" json.resubmit "#{@resubmit}"
json.sec_key "#{@sec_key}"
json.content_modified @hide_code ? false : @content_modified json.content_modified @hide_code ? false : @content_modified

Loading…
Cancel
Save