From 9306fa33781658c0d801ccbd2a4543181eed1633 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 5 Nov 2019 11:24:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E5=A4=9A=E9=80=89=E9=A2=98=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E6=AD=A3=E7=A1=AE=E7=AD=94=E6=A1=88=E5=92=8C?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=9B=9E=E7=AD=94=E4=BF=9D=E5=AD=98=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E6=8F=90=E7=A4=BA=E6=97=B6=E9=97=B4=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 23 ++++++++++++++++------- app/helpers/exercises_helper.rb | 8 +++++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a6464a151..784bb9c9a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1084,14 +1084,23 @@ class ExercisesController < ApplicationController @shixun_undo = 0 @ques_undo = 0 ex_answer_time = @exercise.time.to_i - @ex_end_time = @exercise.get_exercise_end_time(current_user.id) - if ex_answer_time > 0 - exercise_end_time = @exercise.exercise_users.exercise_commit_users(current_user.id) - if exercise_end_time.present? - ex_end_times = exercise_end_time.first.start_at.nil? ? Time.now : exercise_end_time.first.start_at - @ex_end_time = ex_end_times + ex_answer_time.minutes - end + if ex_answer_time > 0 #有剩余时间的时候 + user_left_time = get_exercise_left_time(@exercise,current_user) + @ex_end_time = Time.now + user_left_time.to_i.seconds + else + @ex_end_time = @exercise.get_exercise_end_time(current_user.id) end + # @ex_end_time = @exercise.get_exercise_end_time(current_user.id) + # if ex_answer_time > 0 + # left_answer_time = Time.now + ex_answer_time.minutes #判断试卷的倒计时和截止时间哪个先到 + # if left_answer_time < @ex_end_time + # exercise_end_time = @exercise.exercise_users.exercise_commit_users(current_user.id) + # if exercise_end_time.present? + # ex_end_times = exercise_end_time.first.start_at.nil? ? Time.now : exercise_end_time.first.start_at + # @ex_end_time = ex_end_times + ex_answer_time.minutes + # end + # end + # end @exercise_questions.each do |q| if q.question_type == Exercise::PRACTICAL #当为实训题时 user_myshixun = q.shixun.myshixuns.search_myshixun_user(current_user.id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 395d67913..a859a239e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -160,7 +160,12 @@ module ExercisesHelper #每个选项的正确率 ex_choices.each do |c| + Rails.logger.info("######________c__________#############{c}") + Rails.logger.info("######________standard_answer__________#############{standard_answer}") + right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 + Rails.logger.info("######_______right_answer__________#############{right_answer}") + answer_users_count = effictive_users.select{|answer| answer.exercise_choice_id == c.id}.size answer_percent = (effictive_users_count == 0 ? 0.0 : (answer_users_count / effictive_users_count.to_f ).round(3)) @@ -896,7 +901,8 @@ module ExercisesHelper 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_end_time = exercise.get_exercise_end_time(user.id) #没有考虑分班的情况 + # exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 From 25b4a073158373530e87b460418c41df06b34089 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 5 Nov 2019 11:31:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=A4=9A=E9=80=89?= =?UTF-8?q?=E9=A2=98=E6=A0=87=E5=87=86=E7=AD=94=E6=A1=88=E7=9A=84=E6=98=BE?= =?UTF-8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a859a239e..323bad3cf 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -142,6 +142,9 @@ module ExercisesHelper right_users_count = 0 #该问题的正确率 if ex.question_type == Exercise::MULTIPLE #多选题 + if standard_answer.size == 1 #以前的多选题答案存在一个表里 + standard_answer = standard_answer.first.to_s.split("").map(&:to_i) + end right_user_ids = user_ids standard_answer.each do |choice_position| standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id @@ -160,12 +163,7 @@ module ExercisesHelper #每个选项的正确率 ex_choices.each do |c| - Rails.logger.info("######________c__________#############{c}") - Rails.logger.info("######________standard_answer__________#############{standard_answer}") - right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 - Rails.logger.info("######_______right_answer__________#############{right_answer}") - answer_users_count = effictive_users.select{|answer| answer.exercise_choice_id == c.id}.size answer_percent = (effictive_users_count == 0 ? 0.0 : (answer_users_count / effictive_users_count.to_f ).round(3))