From 6b92defd3f9272ffb97a9f32e69bec7d8ed3a8a3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 15:13:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 9 ++++----- app/helpers/exercises_helper.rb | 10 +++++----- app/views/exercises/exercise_result.json.jbuilder | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f80327ad1..6fa694fbf 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1323,13 +1323,12 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin exercise_ids = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).size #判断是否有已发布的分班 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).size #判断是否有未发布的分班 @course_all_members = @course.students #课堂的全部学生 @exercise_all_users = @exercise.exercise_users ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) - # @exercise_course_groups = @exercise.get_ex_published_course(current_user.id) @exercise_users_list = @exercise.all_exercise_users(current_user.id) @course_all_members_count = @exercise_users_list.size @@ -1342,7 +1341,7 @@ class ExercisesController < ApplicationController end @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id - @exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数 + @exercise_commit_user_counts = @exercise_commit_users.size #试卷的已提交用户人数 @exercise_status = @exercise.get_exercise_status(current_user) #提交率 @@ -1394,7 +1393,7 @@ class ExercisesController < ApplicationController @question_result_hash = ques_result_all.sort_by{|s| s["#{@paging_type}"]} end - @exercise_questions_count = @exercise_questions.count + @exercise_questions_count = @exercise_questions.size @page = params[:page] || 1 @limit = params[:limit] || 10 @question_result_hash = Kaminari.paginate_array(@question_result_hash).page(@page).per(@limit) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index eb3802d94..3e73931e0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,7 +89,7 @@ module ExercisesHelper questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers - if ex.question_type != 5 + if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil effictive_users = ex_answers.search_answer_users("user_id",user_ids) @@ -106,7 +106,7 @@ module ExercisesHelper percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 end question_answer_infos = [] - if ex.question_type <= 2 #单选题 + if ex.question_type <= Exercise::JUDGMENT #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 @@ -126,7 +126,7 @@ module ExercisesHelper } question_answer_infos.push(answer_option) end - elsif ex.question_type == 3 #填空题 + elsif ex.question_type == Exercise::COMPLETION #填空题 ex_ordered = ex.is_ordered null_standard_answer = ex.exercise_standard_answers null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) @@ -179,7 +179,7 @@ module ExercisesHelper :right_answer => false } question_answer_infos.push(wrong_answer_position) - elsif ex.question_type == 4 #主观题 + 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 #部分分数人数 @@ -208,7 +208,7 @@ module ExercisesHelper } question_answer_infos.push(answer_option) end - elsif ex.question_type == 5 #实训题 + elsif ex.question_type == Exercise::PRACTICAL #实训题 ex.exercise_shixun_challenges.each do |c| cha_score = c&.question_score cha_shixun_answer = effictive_users.search_shixun_keys("exercise_shixun_challenge_id",c.id) diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index b0d1be9d2..2428e57c7 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -32,7 +32,7 @@ json.commit_results do json.ques_position q[:position] json.right_percent q[:percent] json.effictive_counts q[:ques_effictive_counts] - if q[:type] != 5 + if q[:type] != Exercise::PRACTICAL json.ques_details do json.array! q[:ques_details] do |d| json.choice_position d[:choice_position]