diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index f6724a654..445d67087 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,11 +9,13 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - content = GitService.file_content(repo_path: repo_path, path: path)["content"] - logger.info("@@@@@@@@@@@@@@@@@@#{content}") + content = GitService.file_content(repo_path: repo_path, path: path) + logger.info("@@@@@@@@@@@@@@@@@@#{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']}" @@ -27,6 +29,7 @@ module GitHelper end decode_content + rescue Exception => e uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c3e8c4e5d..3e4dea5e3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -201,16 +201,16 @@ class ExercisesController < ApplicationController def common_header ActiveRecord::Base.transaction do begin + @user_left_time = nil if @user_course_identity > Course::ASSISTANT_PROFESSOR @is_teacher_or = 0 @user_exercise_answer = @exercise.check_user_answer_status(current_user) @user_commit_counts = 0 - get_exercise_left_time(@exercise,current_user) + @user_left_time = get_exercise_left_time(@exercise,current_user) else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 - @user_left_time = nil end @ex_status = @exercise.get_exercise_status(current_user.id) @@ -1022,8 +1022,6 @@ class ExercisesController < ApplicationController end end - get_exercise_left_time(@exercise,@exercise_user_current) - # ex_time = @exercise.time # if ex_time > 0 # time_mill = ex_time * 60 #转为秒 @@ -1038,10 +1036,12 @@ class ExercisesController < ApplicationController @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) + @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else + @user_left_time = get_exercise_left_time(@exercise,current_user) @user_exercise_status = 0 #可编辑 end diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 60a551e7b..c3fa30270 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -16,7 +16,8 @@ class GitsController < ApplicationController username_password = Base64.decode64(request.env["HTTP_AUTHORIZATION"].split(" ")[1]) input_username = username_password.split(":")[0].strip() input_password = username_password.split(":")[1].strip() - uid_logger("git start auth: input_username is #{input_username}") + uid_logger("git start auth: input_username is 55#{input_username}55") + uid_logger("git start auth: password is 66#{input_password}66") # Git 超级权限用户 if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip @@ -27,7 +28,7 @@ class GitsController < ApplicationController # 如果用户名密码错误 if !system_user.check_password?(input_password) - uid_logger_error("git start: password is wrong") + uid_logger_error("git start: password is wrong#77#{input_password}77") result = false else git_url = params["url"] diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b734d9685..285dbb37e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -413,43 +413,41 @@ module ExercisesHelper score2 += 0.0 end elsif q.question_type == 5 #实训题时,主观题这里不评分 - if answers_content.present? - q.exercise_shixun_challenges.each do |exercise_cha| - game = Game.user_games(user.id,exercise_cha.challenge_id).first #当前用户的关卡 - if game.present? - exercise_cha_score = 0.0 - answer_status = 0 - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = exercise_cha.question_score #每一关卡的得分 - answer_status = 1 - end - ex_shixun_answer_content = answers_content.where(exercise_shixun_challenge_id: exercise_cha.id) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path exercise_cha.challenge.path - game_challenge = game.game_codes.search_challenge_path(cha_path).first - if game_challenge.present? - game_code = game_challenge - code = game_code.try(:new_code) - else - code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) - end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + q.exercise_shixun_challenges.each do |exercise_cha| + game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 + if game.present? + exercise_cha_score = 0.0 + answer_status = 0 + if game.status == 2 && game.final_score >= 0 + exercise_cha_score = exercise_cha.question_score #每一关卡的得分 + answer_status = 1 + end + ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + cha_path = challenge_path exercise_cha.challenge.path + game_challenge = game.game_codes.search_challenge_path(cha_path).first + if game_challenge.present? + game_code = game_challenge + code = game_code.try(:new_code) else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) end - score5 += exercise_cha_score + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) + else + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end + score5 += exercise_cha_score + else + score5 += 0.0 end - else - score5 += 0.0 end end user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 @@ -681,9 +679,11 @@ module ExercisesHelper result end - def get_exercise_left_time(exercise,exercise_user) + def get_exercise_left_time(exercise,user) ex_time = exercise.time + user_left_time = nil if ex_time > 0 + exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 @@ -691,9 +691,9 @@ module ExercisesHelper time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 end exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 + user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end - @user_left_time + user_left_time end #实训题学生代码的行数 diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 918995bef..af883131a 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -35,7 +35,7 @@ module ExportHelper else head_cells_add = [] end - normal_head_b_cells = %w(最终成绩 提交时间 更新时间) + normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) works.each_with_index do |w, index| w_user = w.user @@ -85,8 +85,21 @@ module ExportHelper w_15 = w.work_score.nil? ? "未评分" : w.work_score.round(1) w_16 = w.commit_time ? format_time(w.commit_time) : "--" w_17 = w.update_time ? format_time(w.update_time) : "--" + teacher_comments = w.student_works_scores + if teacher_comments.present? + w_18 = "" + teacher_comments.each do |t| + user_name = t.user.real_name + user_time = format_time(t.updated_at) + user_score = t.score + user_comment = t.comment + w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + end + else + w_18 = "--" + end - row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] + row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18] row_cells_column = row_cells_column.reject(&:blank?) @work_cells_column.push(row_cells_column) end @@ -102,7 +115,7 @@ module ExportHelper if allow_late_boolean #允许迟交 eff_score_cell.push("迟交扣分") end - shixun_time_cells = %w(最终成绩 更新时间 提交耗时) + shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) works.each_with_index do |w, index| myshixun = w.try(:myshixun) @@ -143,7 +156,20 @@ module ExportHelper w_15 = w.work_score.nil? ? "--" : w.work_score.round(1) w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间" w_17 = w.cost_time - row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] + teacher_comments = w.student_works_scores + if teacher_comments.present? + w_18 = "" + teacher_comments.each do |t| + user_name = t.user.real_name + user_time = format_time(t.updated_at) + user_score = t.score + user_comment = t.comment + w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + end + else + w_18 = "--" + end + row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18] row_cells_column = row_cells_column.reject(&:blank?) @work_cells_column.push(row_cells_column) end diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index 3809c6264..aab3ac057 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -1,5 +1,6 @@ wb = xlsx_package.workbook +# wb.use_autowidth = false wb.styles do |s| sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} @@ -8,7 +9,7 @@ wb.styles do |s| sheet.add_row table_columns, :style => blue_cell if task_users.count > 0 task_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height => 20,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) diff --git a/lib/gitcheck/myshixun_update.txt b/lib/gitcheck/myshixun_update.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/gitcheck/readme_test.txt b/lib/gitcheck/readme_test.txt new file mode 100644 index 000000000..03f757f18 --- /dev/null +++ b/lib/gitcheck/readme_test.txt @@ -0,0 +1,51 @@ +# 新版Git测试说明 +统一: +参考实训:http://47.96.87.25:48080/shixuns/ca9fvobr/repository +请求方式:POST +参数{repo_path: "educoder/ca9fvobr.git"} +公共方法: +['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', + 'file_content', 'commits'] + +1、仓库目录接口 + 测试方法:模拟1000个用户同时去访问接口,访问方式 + http://121.199.19.206:9000/api/file_tree + 参数: + {repo_path: "educoder/ca9fvobr.git", path: ''} // 如:{path: 'step1'} + +2、创建版本库 + 访问地址:http://121.199.19.206:9000/api/add_repository + 参数: + {repo_path: 比如:"Hjqreturn/aaass1.git"} + +3、fork版本库 + http://121.199.19.206:9000/api/fork_repository + 参数: + {repo_path: 'Hjqreturn/aaass1.git', fork_repository_path: 'educoder/ca9fvobr.git'} + 说明:fork_repository_path是源项目的repo_path, repo_path是新项目的 + + +4、更新文件 + 测试方法: + 1、更新同一个文件,并发量可以不用很大,可以用同一个用户并发10-100 + 2、更新不同的文件:可以依据创建的版本库去更新 + 访问地址:http://121.199.19.206:9000/api/update_file + 参数: + {repo_path: "educoder/ca9fvobr.git", + file_path: 'step1/main.py', + message: 'commit by test', + content: 'afdjadsjfj1111', + author_name: 'guange', + author_email: '8863824@gmil.com'} + +5、获取文件内容 + 访问地址:http://121.199.19.206:9000/api/file_content + 参数: + {repo_path: "educoder/ca9fvobr.git", file_path: 'step1/main.py',} + +6、获取提交记录 + 访问地址:http://121.199.19.206:9000/api/commits + 参数: + {repo_path: 比如:"educoder/ca9fvobr.git"} + + diff --git a/lib/gitcheck/shixun_update.txt b/lib/gitcheck/shixun_update.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/tasks/git_check.rake b/lib/tasks/git_check.rake new file mode 100644 index 000000000..64f8be91b --- /dev/null +++ b/lib/tasks/git_check.rake @@ -0,0 +1,16 @@ +namespace :git do + desc "检测是否TPM是否需要更新" + task :shixun_check_update => :environment do + + end + + desc "检测版本库是否有异常" + task :myshixuns_check_update => :environment do + + end + + + task :check => :environment do + + end +end