From c872f8bce375d5242e86e3e333ef126807d30eab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 15:36:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=9A=84=E6=80=A7=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 11 ++++++----- app/helpers/courses_helper.rb | 2 +- app/helpers/student_works_helper.rb | 6 +++--- app/models/challenge.rb | 2 +- app/models/homework_common.rb | 2 +- app/models/myshixun.rb | 8 ++++---- .../_homework_public_navigation.json.jbuilder | 2 +- app/views/homework_commons/index.json.jbuilder | 9 +++++---- app/views/homework_commons/works_list.json.jbuilder | 1 - 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3aacd71fa..4abada488 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -104,7 +104,7 @@ class HomeworkCommonsController < ApplicationController @shixun = @homework.shixuns.take if @homework.homework_type == "practice" student_works = @homework.all_works - @all_member_count = student_works.count + @all_member_count = student_works.size if @homework.publish_time.nil? || @homework.publish_time > Time.now @student_works = [] respond_to do |format| @@ -135,14 +135,14 @@ class HomeworkCommonsController < ApplicationController end elsif @user_course_identity < Course::STUDENT @student_works = @homework.teacher_works(@member) - @all_member_count = @student_works.count + @all_member_count = @student_works.size elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works else @student_works = [] end - unless @student_works.size == 0 + unless @student_works.blank? # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id) @@ -187,12 +187,13 @@ class HomeworkCommonsController < ApplicationController # 分页参数 page = params[:page] || 1 limit = params[:limit] || 20 - @student_works = @student_works.page(page).per(limit).includes(:student_works_scores) + @student_works = @student_works.page(page).per(limit) if @homework.homework_type == "practice" - @student_works = @student_works.includes(user: :user_extension, myshixun: :games) + @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) else @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) end + # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) end respond_to do |format| format.json diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 93b8bfc50..fa51de6b7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -232,7 +232,7 @@ module CoursesHelper course.course_groups.includes(:course_members) end group_info = [] - if course_groups.count > 0 + if !course_groups.blank? course_groups.each do |group| group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count} end diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 682bfbf81..17cdd41a7 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -54,13 +54,13 @@ module StudentWorksHelper objects = myshixuns.map do |myshixun| # 评测次数 - evaluate_count = myshixun.games.sum(:evaluate_count) + evaluate_count = myshixun.games.pluck(:evaluate_count).sum # 获取最大评测次数 max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count) # 通关耗时 - pass_consume_time = (myshixun.games.where(status: 2).pluck(:cost_time).sum / 60.0) + pass_consume_time = (myshixun.total_cost_time / 60.0) # 总耗时 - all_time = (myshixun.games.sum(:cost_time) / 60.0) + all_time = (myshixun.games.pluck(:cost_time).sum / 60.0) # 通关得分 user_total_score = myshixun.total_score.to_i # 耗时,保留2位小数, diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a5d9874ce..5495dd7a3 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -38,7 +38,7 @@ class Challenge < ApplicationRecord ## 选择题总分 def choose_score - self.challenge_chooses.sum(:score) + self.challenge_chooses.pluck(:score).sum end # 关卡总分 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 9cc2c9a69..9ed80e746 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -70,7 +70,7 @@ class HomeworkCommon < ApplicationRecord if self.course_second_category.present? {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)} else - {category_id: course.shixun_course_modules.first.try(:id), category_name: course.shixun_course_modules.first.try(:module_name)} + {category_id: course.shixun_course_modules.take.try(:id), category_name: course.shixun_course_modules.take.try(:module_name)} end end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index b5bbdc249..e4573f3dd 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -74,12 +74,12 @@ class Myshixun < ApplicationRecord # 个人实训得分 def total_score - self.games.where("status = 2 and final_score > 0").sum(:final_score).to_i + self.games.select{|game| game.status = 2 && game.final_score > 0}.pluck(:final_score).sum.to_i end # 个人通关数 def passed_count - self.games.where(status: 2).count + self.games.select{|game| game.status = 2}.size end # 通关时间 @@ -89,12 +89,12 @@ class Myshixun < ApplicationRecord # 耗时 def total_spend_time - game_spend_time self.games.where(status: 2).sum(:cost_time).to_i + game_spend_time total_cost_time end # 通关总耗时 def total_cost_time - self.games.where(status: 2).sum(:cost_time).to_i + self.games.select{|game| game.status = 2}.map(&:cost_time).sum.to_i end end diff --git a/app/views/homework_commons/_homework_public_navigation.json.jbuilder b/app/views/homework_commons/_homework_public_navigation.json.jbuilder index 2c803bee8..2c548074c 100644 --- a/app/views/homework_commons/_homework_public_navigation.json.jbuilder +++ b/app/views/homework_commons/_homework_public_navigation.json.jbuilder @@ -10,5 +10,5 @@ json.homework_name homework.name json.homework_id homework.id json.homework_type homework.homework_type if homework.homework_type == "practice" - json.shixun_identifier homework.shixuns.first.try(:identifier) + json.shixun_identifier homework.shixuns.take.try(:identifier) end diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index d718550c1..5b9717c2f 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -2,10 +2,6 @@ json.course_identity @user_course_identity json.homework_type @homework_type json.course_public @course.is_public == 1 json.is_end @course.is_end -json.all_count @all_count -json.published_count @published_count -json.unpublished_count @all_count - @published_count -json.task_count @task_count json.main_category_id @main_category.try(:id) json.main_category_name @main_category.try(:module_name) json.category_id @category.try(:id) @@ -46,3 +42,8 @@ json.homeworks @homework_commons.each do |homework| end end +json.all_count @all_count +json.published_count @published_count +json.unpublished_count @all_count - @published_count +json.task_count @task_count + diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 0c1ed0c5b..42d4abf48 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -101,7 +101,6 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.anonymous_appeal @homework.anonymous_appeal json.student_works @student_works.each do |work| - if @is_evaluation json.(work, :id, :work_status, :update_time)