From 9787d70f9299b79ed18c9bdedd1a785abe7cae2e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:33:05 +0800 Subject: [PATCH 01/13] fixbug --- app/helpers/exercises_helper.rb | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index be71aedab..c9c213c47 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -86,10 +86,10 @@ module ExercisesHelper #试卷的统计结果页面计算各题的 def exercise_commit_result(questions,user_ids) question_infos = [] + percent = 0.0 questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers - if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -103,15 +103,23 @@ module ExercisesHelper effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 - if ex_total_score == 0.0 - percent = 0.0 - else - percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + if ex_total_score != 0.0 + percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + end end question_answer_infos = [] - if ex.question_type <= Exercise::JUDGMENT #单选题 - standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 + if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 + standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 + right_users_count = 0 #该问题的回答正确的人数 + user_ids.each do |user_id| + user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort + if user_an_choice == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) @@ -125,7 +133,7 @@ module ExercisesHelper :choice_position => c.choice_position, :choice_text => c.choice_text, :choice_users_count => answer_users_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -161,13 +169,14 @@ module ExercisesHelper :choice_position => index+1, :choice_text => s_choice_text, :choice_users_count => user_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => true } question_answer_infos.push(answer_option) all_user_count += user_count standard_answer_count += 1 end + percent = effictive_users_count > 0 ? (all_user_count / effictive_users_count.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) if effictive_users_count > 0 && user_wrong_count >= 0 @@ -179,7 +188,7 @@ module ExercisesHelper :choice_position => (standard_answer_count + 1), :choice_text => "wrong", :choice_users_count => user_wrong_count, - :choice_percent => wrong_percent.round(1), + :choice_percent => wrong_percent.round(1).to_s, :right_answer => false } question_answer_infos.push(wrong_answer_position) @@ -188,12 +197,10 @@ module ExercisesHelper full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 end - # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| right_answer = (index == 0) @@ -207,7 +214,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -224,7 +231,7 @@ module ExercisesHelper shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 if shixun_answered_scores == 0.0 - game_percent = "0.0" + game_percent = 0.0 else game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率 end @@ -242,7 +249,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } shixun_chas.push(answer_option) @@ -252,7 +259,7 @@ module ExercisesHelper :cha_name => c.challenge.subject, :cha_position => c.position, :cha_details => shixun_chas, - :cha_percent => game_percent + :cha_percent => game_percent.round(1).to_s } question_answer_infos.push(shixun_new_chas) end From 1bdffb56cdf8947eb78ce4db9ddb42a0cd3e27d2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:43:12 +0800 Subject: [PATCH 02/13] fixbug --- app/helpers/exercises_helper.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index c9c213c47..a416dfcbe 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,9 +113,15 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 + + #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort - if user_an_choice == standard_answer + user_an_choice = ex_answers.where(user_id:user_id) + answer_choice_array = [] + user_an_choice.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + if answer_choice_array == standard_answer right_users_count += 1 end end From d82a12d84b1bab94ae57096ce7461998f6129ab6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 09:14:49 +0800 Subject: [PATCH 03/13] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e2df181f0..8b6469089 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -31,7 +31,7 @@ class AccountsController < ApplicationController phone = nil verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last end - uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.created_at.to_i}") + uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.try(:created_at).to_i}") check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) unless check_code tip_exception("验证码无效") From e23e7678e61c89a952fbb07d8fc28859d3f92dd7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:17:25 +0800 Subject: [PATCH 04/13] =?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=E9=A1=B5=E9=9D=A2=EF=BC=8C=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a416dfcbe..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -116,12 +116,8 @@ module ExercisesHelper #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = ex_answers.where(user_id:user_id) - answer_choice_array = [] - user_an_choice.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 - end - if answer_choice_array == standard_answer + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer right_users_count += 1 end end @@ -129,7 +125,7 @@ module ExercisesHelper ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) - answer_users_count = answer_this_choice.count + answer_users_count = answer_this_choice.size if effictive_users_count == 0 answer_percent = 0.0 else @@ -170,7 +166,6 @@ module ExercisesHelper else answer_percent = (user_count / effictive_users_count.to_f ).round(3) end - answer_option = { :choice_position => index+1, :choice_text => s_choice_text, @@ -200,9 +195,9 @@ module ExercisesHelper question_answer_infos.push(wrong_answer_position) elsif ex.question_type == Exercise::SUBJECTIVE #主观题 ex_score = ex&.question_score - full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 - no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + full_scores = effictive_users.search_exercise_answer("score",ex_score).size #满分人数 + no_full_scores = effictive_users.exercise_no_full_scores(ex_score).size #部分分数人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).size #包含为0分的,及未评阅的 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 @@ -415,7 +410,7 @@ module ExercisesHelper user_answer_content = answer_choice_array.sort standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 - if standard_answer.count > 0 + if standard_answer.size > 0 q_score_1 = q.question_score # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else From 9a859c567547f5e183d1355fd41c2aea5b01c020 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:21:33 +0800 Subject: [PATCH 05/13] fixbug --- app/helpers/exercises_helper.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..1dd6c7452 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,13 +115,14 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + percent = 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) From a56da584d1fa4e1c2bb9c028bea67e9e592c9037 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:29:17 +0800 Subject: [PATCH 06/13] fixbug --- app/controllers/exercises_controller.rb | 6 +++--- app/helpers/exercises_helper.rb | 15 +++++++-------- app/models/exercise.rb | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index fe04e04f8..09b237221 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -203,13 +203,13 @@ class ExercisesController < ApplicationController else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 - @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 + @user_commit_counts = @exercise.exercise_users.where(commit_status:1).size #已提交的用户数 end @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).count #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 if @ex_status == 1 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1dd6c7452..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,14 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - percent = 0.0 + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e7d141ea9..a46fded25 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -178,13 +178,12 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.first.commit_status end - if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end - user_status end From 4fbf6ad4e14e94e105c384a831b9d0bb20c0a4d5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 09:36:15 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e2df181f0..ae7335496 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -45,6 +45,8 @@ class AccountsController < ApplicationController @user.activate # 必须要用save操作,密码的保存是在users中 if @user.save! + # todo user_extension + UserExtension.create!(user_id: @user.id) # 注册完成,手机号或邮箱想可以奖励500金币 RewardGradeService.call( @user, From 81e52b9e18d9bcacda1a174feb29a08fa6aca7bb Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 09:36:16 +0800 Subject: [PATCH 08/13] modify check mail and phone valid --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f9516b9e4..fbb1fef12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,7 @@ class ApplicationController < ActionController::Base # 考虑到安全参数问题,多一次查询,去掉Union user = User.where(phone: login).first || User.where(mail: login).first if type.to_i == 1 && !user.nil? - tip_exception("该手机号码或邮箱已被注册") + tip_exception(-2, "该手机号码或邮箱已被注册") elsif type.to_i == 2 && user.nil? tip_exception("该手机号码或邮箱未注册") end From 6998dd8286f3c0a2bb486e55c5519af7e2f66f3e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:36:35 +0800 Subject: [PATCH 09/13] fixbug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 09b237221..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1204,7 +1204,7 @@ class ExercisesController < ApplicationController #筛选/分类,排序 order = params[:order] - if @exercise_users_list.exists? && @exercise_users_list.size > 0 + if @exercise_users_list.present? && @exercise_users_list.size > 0 @exercise_users_count = @exercise_users_list.size #当前显示的全部成员数量 teacher_reviews = @exercise_users_list.exercise_review teacher_unreviews = @exercise_users_list.exercise_unreview From 8a78d0d3754a0e9a36c217af1c8192030d4aab2f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:53:27 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..9ac02c82a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,10 +115,12 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + effictive_users.transaction do + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 From 6d535cd4bc057298e1b94b0d05dc9ebb258df5b7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 10:02:21 +0800 Subject: [PATCH 11/13] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=88=E4=BD=9C=E8=80=85=E7=9A=84=E6=89=8B=E6=9C=BA=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8f6dd23a4..599be4cde 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -662,8 +662,8 @@ class ShixunsController < ApplicationController school_name = "%#{params[:school_name].to_s.strip}%" if user_name.present? || school_name.present? @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND - LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'") + (LOWER(users.lastname) LIKE ? or users.phone like ?) AND LOWER(schools.name) LIKE + ?", user_name, user_name, school_name) else @users = User.none end From 804fc5eea20fc717816b775f9cfa3c887ae230b7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:19:55 +0800 Subject: [PATCH 12/13] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..39d793b5a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController @paging_type = params[:sort].to_s end - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9ac02c82a..24c296558 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -84,7 +84,7 @@ module ExercisesHelper end #试卷的统计结果页面计算各题的 - def exercise_commit_result(questions,user_ids) + def exercise_commit_result(questions,user_ids,commit_users) question_infos = [] percent = 0.0 questions.each do |ex| @@ -115,9 +115,9 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - effictive_users.transaction do - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + commit_users.transaction do + commit_users.each do |user| + answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From 6af86402cbe654d395cb65e5f802557ec6c08772 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:22:18 +0800 Subject: [PATCH 13/13] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 24c296558..0cfcd5336 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -117,7 +117,7 @@ module ExercisesHelper #计算每个问题的答案人数 commit_users.transaction do commit_users.each do |user| - answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end