diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 8d769a244..65ebd4074 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,17 +9,17 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - logger.info("git file content: repo_path is #{repo_path}, path is #{path}") + Rails.logger.info("git file content: repo_path is #{repo_path}, path is #{path}") content = GitService.file_content(repo_path: repo_path, path: path) - logger.info("git file content: content is #{content}") + Rails.logger.info("git file content: content is #{content}") decode_content = nil if content.present? content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass content = Base64.decode64(content) cd = CharDet.detect(content) - logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" + Rails.logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" decode_content = if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3c364b979..ff4dc6be9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1335,7 +1335,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" + filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1442e1da3..437965ca6 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -734,6 +734,6 @@ module ExercisesHelper #实训题学生代码的行数 def content_line(content) - content.split(/\r?\n/).length + content.split(/\r?\n/).length + 1 end end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index ee055ac66..73711192f 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -2,6 +2,7 @@ class ExerciseUserPdfService include ExercisesHelper include ApplicationHelper include StudentWorksHelper + include GitHelper attr_reader :exercise, :ex_user, :request_url @@ -14,8 +15,8 @@ class ExerciseUserPdfService end def filename - user_course = @course.course_members.find_by(user_id:@ex_user_user.id).course_group_name - exercise_user_name = user_course + "_" + exercise.exercise_name + "_" + @ex_user_user.real_name + user_course = @course.course_members.find_by(user_id:@ex_user_user.id)&.course_group_name + exercise_user_name = "#{@ex_user_user.real_name}_#{user_course.present? ? user_course : "未分班"}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" "#{exercise_user_name.strip}.pdf" end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index f83323d7e..3aac67713 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -10,7 +10,7 @@ class ExportExercisesService end def filename - exercise_export_name = exercise.user.real_name + "_" + exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" "#{exercise_export_name.strip}.zip" end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 759a2d2b0..5e763d1cc 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -17,9 +17,9 @@
-+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %>分 @@ -44,17 +44,20 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %>分 <% end %> - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - + + <% if @exercise_ques_count > 0 %> + 合计<%= @exercise_ques_count %>题 + + 共<%= @exercise_ques_scores %>分 + <% end %> +
+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %>分 @@ -37,21 +37,23 @@ 共<%= @exercise_ques_null_scores %>分 <% end %> <% if @exercise_ques_main_count > 0 %> - 主观题<%= @exercise_ques_main_count %>题, - 共<%= @exercise_ques_main_scores %>分 + 主观题<%= @exercise_ques_main_count %>题, + 共<%= @exercise_ques_main_scores %>分 <% end %> <% if @exercise_ques_shixun_count > 0 %> - 实训题<%= @exercise_ques_shixun_count %>题, - 共<%= @exercise_ques_shixun_scores %>分 + 实训题<%= @exercise_ques_shixun_count %>题, + 共<%= @exercise_ques_shixun_scores %>分 <% end %> - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - + + <% if @exercise_ques_count > 0 %> + 合计<%= @exercise_ques_count %>题 + + 共<%= @exercise_ques_scores %>分 + <% end %> +
+ <% if game.try(:lastest_code).blank? %> + <% cha_path = challenge_path(game.challenge&.path) %> + <% latest_code = git_fle_content(game.myshixun.repo_path,cha_path) %> + <% else %> + <% latest_code = game.try(:lastest_code) %> + <% end %> + <% con_rows = content_line(latest_code) %> +
最近通过的代码 - <%= game.challenge.path %> + <%= game.challenge&.path %> -
-