From 0d5361b59cd9c45c10c585610ba1df83ef22a0dd Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 14:38:12 +0800 Subject: [PATCH] shixun file update --- app/controllers/myshixuns_controller.rb | 85 ++++++++++--------- app/views/myshixuns/update_file.json.jbuilder | 1 + 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 035b43955..24c5066e5 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -243,55 +243,56 @@ class MyshixunsController < ApplicationController # -----Repository # TODO: 之类需要一个resubmit参数,但是是关于games. def update_file - @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first - tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? - path = params[:path].strip unless params[:path].blank? - game_id = params[:game_id] - game = Game.find(game_id) - @content_modified = 0 - # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 - # 自动保存的时候evaluate为0;点评测的时候为1 - if params[:evaluate] == 1 - record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id) - uid_logger("-- game is #{game_id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") - student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:student_work => student_work_time) - end - unless @hide_code - # 远程版本库文件内容 - last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] + begin + @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first + tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? + path = params[:path].strip unless params[:path].blank? + game_id = params[:game_id] + game = Game.find(game_id) + @content_modified = 0 + + # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 + # 自动保存的时候evaluate为0;点评测的时候为1 + if params[:evaluate] == 1 + @sec_key = generate_identifier(EvaluateRecord, 12) + record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id, + :identifier => @sec_key) + 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 + 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? - params[:content].gsub(/\t/, ' ') - else - params[:content] - end - if content != last_content - @content_modified = 1 + content = params[:content] - author_name = current_user.full_name - author_email = current_user.mail - 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) + if content != last_content + @content_modified = 1 - 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 - if game.status == 2 - @resubmit = Time.now.to_i - end + if game.status == 2 + @resubmit = Time.now.to_i + end - # 评测时间记录 - if record.present? - consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:file_update => consume_time) + # 评测时间记录 + if record.present? + consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f + record.update_attributes!(:file_update => consume_time) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception("文件内容更新异常,请稍后重试") end end diff --git a/app/views/myshixuns/update_file.json.jbuilder b/app/views/myshixuns/update_file.json.jbuilder index c647927c4..ce8426715 100644 --- a/app/views/myshixuns/update_file.json.jbuilder +++ b/app/views/myshixuns/update_file.json.jbuilder @@ -1,3 +1,4 @@ json.content @content json.resubmit "#{@resubmit}" +json.sec_key "#{@sec_key}" json.content_modified @hide_code ? false : @content_modified