From ec08589dd39d525fed1316c647cfa52e3a09cbc6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 19 Oct 2019 21:48:04 +0800 Subject: [PATCH 1/4] =?UTF-8?q?VNC=E5=AE=9E=E8=AE=AD=E4=B8=AD=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/views/games/show.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 78f665b3d..5a86fa06e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -60,7 +60,7 @@ class GamesController < ApplicationController praise_count: praise_count, user_praise: user_praise, time_limit: time_limit, tomcat_url: edu_setting('cloud_tomcat_php'), is_teacher: is_teacher, myshixun_manager: myshixun_manager, git_url: (@shixun.vnc ? repo_url(@myshixun.repo_path) : "")} - if @shixun.vnc + if @shixun.vnc && @st == 0 get_vnc_link(@game) end diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index 048188746..7c9d1f22a 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -1,7 +1,7 @@ json.(@base_date, :st, :discusses_count, :game_count, :record_onsume_time, :prev_game, :next_game, :praise_count, :user_praise, :time_limit, :tomcat_url, :is_teacher, :myshixun_manager, :game, :challenge, :shixun, :myshixun, :git_url) -if @shixun.vnc +if @shixun.vnc && @st == 0 json.vnc_url @vnc_url json.vnc_evaluate @vnc_evaluate end From 6a374a3f2570fc911f0cba6a043bc74bf517f241 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 19 Oct 2019 23:31:39 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5a86fa06e..97c3dc6e2 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -881,7 +881,7 @@ class GamesController < ApplicationController end # actual_output为空表示暂时没有评测答题,不允许查看 actual_output = output.try(:actual_output).try(:strip) - #has_answer << choose.answer if choose.answer.present? + has_answer << choose.answer if choose.answer.present? # 标准答案处理,错误的不让用户查看,用-1替代 standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer result = output.try(:result) @@ -892,7 +892,7 @@ class GamesController < ApplicationController @chooses << sin_choose test_sets << sin_test_set end - @has_answer = true # 选择题永远都有答案 + @has_answer = has_answer.presence # 选择题永远都有答案 @choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count, :choose_correct_num => choose_correct_num, :test_sets => test_sets} end From 8d016468720dacb9243cee613ff8d521ad0e09de Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 21 Oct 2019 14:15:05 +0800 Subject: [PATCH 3/4] =?UTF-8?q?cdn=E5=8A=A0=E8=BD=BD=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/main_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 869ba27f6..0e2628c3e 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -1,5 +1,5 @@ class MainController < ApplicationController def index - render file: 'public/react/build/index', formats: [:html] + render file: 'public/react/build/index.html', :layout => false end end \ No newline at end of file From 382b6cfd639dc19418457caf089fabc549f54d79 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 21 Oct 2019 15:40:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=97=A5=E5=BF=97=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 8 +++--- app/controllers/concerns/logger_helper.rb | 6 ++++ app/controllers/games_controller.rb | 34 +++++++++++------------ app/controllers/myshixuns_controller.rb | 21 +++++--------- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6b58bc3b..d94325a5b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -353,10 +353,10 @@ class ApplicationController < ActionController::Base # Post请求 def uri_post(uri, params) begin - uid_logger("--uri_exec: params is #{params}, url is #{uri}") + uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}") uri = URI.parse(URI.encode(uri.strip)) res = Net::HTTP.post_form(uri, params).body - logger.info("--uri_exec: .....res is #{res}") + uid_logger_dubug("--uri_exec: .....res is #{res}") JSON.parse(res) rescue Exception => e uid_logger_error("--uri_exec: exception #{e.message}") @@ -367,10 +367,10 @@ class ApplicationController < ActionController::Base # 处理返回非0就报错的请求 def interface_post(uri, params, status, message) begin - uid_logger("--uri_exec: params is #{params}, url is #{uri}") + uid_logger_dubug("--uri_exec: params is #{params}, url is #{uri}") uri = URI.parse(URI.encode(uri.strip)) res = Net::HTTP.post_form(uri, params).body - logger.info("--uri_exec: .....res is #{res}") + uid_logger_dubug("--uri_exec: .....res is #{res}") res = JSON.parse(res) if (res && res['code'] != 0) tip_exception(status, message) diff --git a/app/controllers/concerns/logger_helper.rb b/app/controllers/concerns/logger_helper.rb index 44d0448ce..af368a007 100644 --- a/app/controllers/concerns/logger_helper.rb +++ b/app/controllers/concerns/logger_helper.rb @@ -9,6 +9,12 @@ module LoggerHelper Rails.logger.info("##:#{current_user.try(:id)} --#{message}") end + # debug日志 + def uid_logger_dubug(message) + Rails.logger.info("##dubug-#{current_user.try(:id)} --#{message}") + + end + # 以用户id开始的日志定义 def uid_logger_error(message) Rails.logger.error("##:#{current_user.try(:id)} --#{message}") diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 97c3dc6e2..67a2e0ee8 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -11,7 +11,7 @@ class GamesController < ApplicationController include ApplicationHelper def show - uid_logger("--games show start") + uid_logger_dubug("--games show start") # 防止评测中途ajaxE被取消;3改成0是为了处理首次进入下一关的问题 update_game_parameter(@game) @@ -439,7 +439,7 @@ class GamesController < ApplicationController path = params[:path] || path status = params[:status].to_i path = path.try(:strip) - uid_logger("--rep_content: path is #{path}") + uid_logger_dubug("--rep_content: path is #{path}") begin @content = git_fle_content(@myshixun.repo_path, path) || "" rescue Exception => e @@ -455,7 +455,7 @@ class GamesController < ApplicationController # 监测版本库HEAD是否存在,不存在则取最新的HEAD uri = "#{shixun_tomcat}/bridge/game/check" res = uri_post uri, rep_params - uid_logger("repo_content to bridge: res is #{res}") + uid_logger_dubug("repo_content to bridge: res is #{res}") # res值:0 表示正常;-1表示有错误;-2表示代码版本库没了 # if status == 0 && res @@ -507,11 +507,10 @@ class GamesController < ApplicationController else {updated_at: Time.now} end - logger.info("#############myshixuns_update: ##{myshixuns_update}") @myshixun.update_attributes!(myshixuns_update) gitUrl = repo_ip_url @myshixun.repo_path - logger.info("#############giturl: ##{gitUrl}") + uid_logger_dubug("#############giturl: ##{gitUrl}") gitUrl = Base64.urlsafe_encode64(gitUrl) shixun_tomcat = edu_setting('cloud_bridge') @@ -537,7 +536,7 @@ class GamesController < ApplicationController testSet << test_cases end - logger.info("##############testSet: #{testSet}") + uid_logger_dubug("##############testSet: #{testSet}") testCases = Base64.urlsafe_encode64(testSet.to_json) unless testSet.blank? # 评测类型: 0,1,2 用于webssh的评测, 3用于vnc @@ -560,11 +559,11 @@ class GamesController < ApplicationController # 私密仓库的设置 secret_rep = @shixun.shixun_secret_repository - logger.info("############secret_rep: #{secret_rep}") + uid_logger_dubug("############secret_rep: #{secret_rep}") if secret_rep&.repo_name secretGitUrl = repo_ip_url secret_rep.repo_path br_params.merge!({secretGitUrl: Base64.urlsafe_encode64(secretGitUrl), secretDir: secret_rep.secret_dir_path}) - logger.info("#######br_params:#{br_params}") + uid_logger_dubug("#######br_params:#{br_params}") end # 中间层交互 @@ -580,7 +579,6 @@ class GamesController < ApplicationController # 选择题评测 def choose_build - Rails.logger.error("#################{params}") # 选择题如果通关了,则不让再评测 if @game.status == 2 raise Educoder::TipException.new("您已通过该关卡") @@ -623,7 +621,7 @@ class GamesController < ApplicationController end # 批量插入评测结果 - uid_logger("#------------chooice score: #{score}") + uid_logger_dubug("#------------chooice score: #{score}") sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str ActiveRecord::Base.connection.execute sql @@ -683,10 +681,10 @@ class GamesController < ApplicationController resubmit_identifier = @game.resubmit_identifier # 如果没有超时并且正在评测中 # 判断评测中的状态有两种:1、如果之前没有通关的,只需判断status为1即可;如果通过关,则判断game的resubmit_identifier是否更新 - uid_logger("################game_status: #{@game.status}") - uid_logger("################params[:resubmit]: #{params[:resubmit]}") - uid_logger("################resubmit_identifier: #{resubmit_identifier}") - uid_logger("################time_out: #{params[:time_out]}") + uid_logger_dubug("################game_status: #{@game.status}") + uid_logger_dubug("################params[:resubmit]: #{params[:resubmit]}") + uid_logger_dubug("################resubmit_identifier: #{resubmit_identifier}") + uid_logger_dubug("################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))) @@ -696,7 +694,7 @@ class GamesController < ApplicationController render :json => { running_code_status: running_code_status, running_code_message: running_code_message } end - uid_logger("##### resubmit_identifier is #{resubmit_identifier}") + uid_logger_dubug("##### resubmit_identifier is #{resubmit_identifier}") port = params[:port] score = 0 experience = 0 @@ -745,7 +743,7 @@ class GamesController < ApplicationController end end - 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")}") + uid_logger_dubug("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 = e_record.try(:pod_execute) max_mem = e_record.try(:max_mem) @@ -791,7 +789,7 @@ class GamesController < ApplicationController begin shixun_tomcat = edu_setting('cloud_bridge') uri = "#{shixun_tomcat}/bridge/webssh/delete" - Rails.logger.info("#{current_user} => cloese_webssh digest is #{digest}") + uid_logger_dubug("#{current_user} => cloese_webssh digest is #{digest}") params = {:tpiID => myshixun_id, :digestKey => digest_key, :identifier => @game.identifier} res = uri_post uri, params if res && res['code'].to_i != 0 @@ -830,7 +828,7 @@ class GamesController < ApplicationController @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户 if max_query_index > 0 - uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") + uid_logger_dubug("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, o.ts_time, o.ts_mem, 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} diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 74f02f1ab..a9cc76296 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -90,7 +90,7 @@ class MyshixunsController < ApplicationController ActiveRecord::Base.transaction do begin t1 = Time.now - Rails.logger.info("@@@222222#{params[:jsonTestDetails]}") + uid_logger_dubug("@@@222222#{params[:jsonTestDetails]}") jsonTestDetails = JSON.parse(params[:jsonTestDetails]) timeCost = JSON.parse(params[:timeCost]) brige_end_time = Time.parse(timeCost['evaluateEnd']) if timeCost['evaluateEnd'].present? @@ -99,7 +99,7 @@ class MyshixunsController < ApplicationController game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] - logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + uid_logger_dubug("training_task_status start-#{game_id}-1#{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) @@ -116,17 +116,14 @@ class MyshixunsController < ApplicationController pics = params[:tpiRepoPath] game.update_column(:picture_path, pics) end - logger.info("training_task_status start#2**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") max_query_index = game.outputs ? (game.outputs.first.try(:query_index).to_i + 1) : 1 test_set_score = 0 unless jenkins_testsets.blank? jenkins_testsets.each_with_index do |j_test_set, i| - logger.info("j_test_set: ############## #{j_test_set}") actual_output = tran_base64_decode64(j_test_set['output']) #ts_time += j_test_set['testSetTime'].to_i # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) - logger.info "actual_output:################################################# #{actual_output}" ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f if j_test_set['testSetTime'] ts_mem = format("%.2f", j_test_set['testSetMem'].to_f/1024/1024).to_f if j_test_set['testSetMem'] @@ -139,15 +136,12 @@ class MyshixunsController < ApplicationController end end end - uid_logger("#############status: #{status}") 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是查看答案的扣分比例 # status:0表示评测成功 if status == "0" if resubmit.present? - uid_logger("#############resubmitdaiao: #{resubmit}") game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) challenge.path.split(";").each do |path| game_passed_code(path.try(:strip), myshixun, game_id) @@ -205,7 +199,6 @@ class MyshixunsController < ApplicationController :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :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")}") sucess_status # rescue Exception => e # tip_exception(e.message) @@ -265,7 +258,7 @@ class MyshixunsController < ApplicationController @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, :exec_time => exec_time) - 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")}") + uid_logger_dubug("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") end # 隐藏代码文件 和 VNC的都不需要走版本库 unless @hide_code || @myshixun.shixun&.vnc_evaluate @@ -276,8 +269,8 @@ class MyshixunsController < ApplicationController else params[:content] end - Rails.logger.info("###11222333####{content}") - Rails.logger.info("###222333####{last_content}") + uid_logger_dubug("###11222333####{content}") + uid_logger_dubug("###222333####{last_content}") if content != last_content @content_modified = 1 @@ -285,8 +278,8 @@ class MyshixunsController < ApplicationController author_name = current_user.real_name author_email = current_user.git_mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" - uid_logger("112233#{author_name}") - uid_logger("112233#{author_email}") + uid_logger_dubug("112233#{author_name}") + uid_logger_dubug("112233#{author_email}") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message,