From 9b5955cda185b6f8e0f86a43f196818ad1737ea7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:02:09 +0800 Subject: [PATCH 1/6] fix bug --- app/helpers/exercises_helper.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4530167ba..2a052fffe 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -682,16 +682,26 @@ module ExercisesHelper def get_exercise_left_time(exercise,user) ex_time = exercise.time user_left_time = nil + time_now_i = Time.now.to_i 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 - if (exercise_user_start + time_mill) > exercise_end_time - time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + #用户未开始答题时,即exercise_user_start为0 + if exercise_user_start == 0 + if (exercise_end_time - time_now_i) > time_mill + user_left_time = time_mill + else + user_left_time = (exercise_end_time < time_now_i) ? nil : (exercise_end_time - time_now_i) + end + else + if (exercise_user_start + time_mill) > exercise_end_time + time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + end + exercise_user_left_time = time_now_i - exercise_user_start #用户已回答的时间 + user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 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) #当前用户对试卷的回答剩余时间 end user_left_time end From 525b848cca2984172b46c5cf4effc603fd68bd37 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:21:38 +0800 Subject: [PATCH 2/6] fix bug --- app/tasks/exercise_publish_task.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 387a834f1..4c8ee39e8 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -44,7 +44,7 @@ class ExercisePublishTask end # 分组设置发布时间的测验 - exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) + exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) exercise_group_settings.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? @@ -70,12 +70,12 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && exercise_user.start_at.present? + if exercise_user&.commit_status == 0 && exercise_user&.start_at.present? s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score @@ -98,7 +98,7 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| From 1d6500ca7af8e7e7e7a58804e6b3f81967beb9e4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:50:54 +0800 Subject: [PATCH 3/6] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 70c023d26..3a651f89d 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -249,8 +249,8 @@ <% if @games.size > 0 %> <% @games.each_with_index do |game, index| %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> + <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.id,user_id: @ex_user_user.id) %> <%= index + 1 %> From 62cf506e2b33ed06d51033374a8a5a5e62dc711c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:55:30 +0800 Subject: [PATCH 4/6] fix bug --- app/templates/exercise_export/exercise_export.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index f5022527e..59be4f1bd 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -241,7 +241,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 1px; + left: 2px; } table{ width:100%; From f40f8ae0422b6678b002999bbdd25c838f77ba52 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:58:20 +0800 Subject: [PATCH 5/6] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 3a651f89d..193a25301 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -250,7 +250,7 @@ <% if @games.size > 0 %> <% @games.each_with_index do |game, index| %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.id,user_id: @ex_user_user.id) %> + <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %> <%= index + 1 %> From 25ef08118c76f5758cad7162561ddad3f71a5722 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 17:45:57 +0800 Subject: [PATCH 6/6] fixbug --- app/helpers/exercises_helper.rb | 12 ++++++------ app/helpers/export_helper.rb | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 2a052fffe..856f808d7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -355,9 +355,9 @@ module ExercisesHelper exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 - answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 if answers_content.present? #学生有回答时 @@ -369,11 +369,11 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - q_score_1 = 0.0 + multi_each_score = 0.0 end - answers_content.update_all(:score => q_score_1) + answers_content.update_all(:score => multi_each_score) score1 = score1 + q.question_score end else @@ -424,7 +424,7 @@ module ExercisesHelper 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 + 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 diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index af883131a..22c10bdb3 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -89,11 +89,12 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + 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") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + w_18 = w_18 + comment_title end else w_18 = "--" @@ -160,11 +161,13 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + 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") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + w_18 = w_18 + comment_title end else w_18 = "--"