实训作品列表、实训报告页面的性能调整

dev_course
cxt 5 years ago
parent 0bb5241084
commit c872f8bce3

@ -104,7 +104,7 @@ class HomeworkCommonsController < ApplicationController
@shixun = @homework.shixuns.take if @homework.homework_type == "practice" @shixun = @homework.shixuns.take if @homework.homework_type == "practice"
student_works = @homework.all_works 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 if @homework.publish_time.nil? || @homework.publish_time > Time.now
@student_works = [] @student_works = []
respond_to do |format| respond_to do |format|
@ -135,14 +135,14 @@ class HomeworkCommonsController < ApplicationController
end end
elsif @user_course_identity < Course::STUDENT elsif @user_course_identity < Course::STUDENT
@student_works = @homework.teacher_works(@member) @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 elsif @user_course_identity > Course::STUDENT && @homework.work_public
@student_works = student_works @student_works = student_works
else else
@student_works = [] @student_works = []
end end
unless @student_works.size == 0 unless @student_works.blank?
# 教师评阅搜索 0: 未评, 1 已评 # 教师评阅搜索 0: 未评, 1 已评
unless params[:teacher_comment].blank? unless params[:teacher_comment].blank?
student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id) 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 page = params[:page] || 1
limit = params[:limit] || 20 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" 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 else
@student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension)
end end
# @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group)
end end
respond_to do |format| respond_to do |format|
format.json format.json

@ -232,7 +232,7 @@ module CoursesHelper
course.course_groups.includes(:course_members) course.course_groups.includes(:course_members)
end end
group_info = [] group_info = []
if course_groups.count > 0 if !course_groups.blank?
course_groups.each do |group| course_groups.each do |group|
group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count} group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count}
end end

@ -54,13 +54,13 @@ module StudentWorksHelper
objects = objects =
myshixuns.map do |myshixun| 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) 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 user_total_score = myshixun.total_score.to_i
# 耗时,保留2位小数 # 耗时,保留2位小数

@ -38,7 +38,7 @@ class Challenge < ApplicationRecord
## 选择题总分 ## 选择题总分
def choose_score def choose_score
self.challenge_chooses.sum(:score) self.challenge_chooses.pluck(:score).sum
end end
# 关卡总分 # 关卡总分

@ -70,7 +70,7 @@ class HomeworkCommon < ApplicationRecord
if self.course_second_category.present? if self.course_second_category.present?
{category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)} {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)}
else 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 end
end end

@ -74,12 +74,12 @@ class Myshixun < ApplicationRecord
# 个人实训得分 # 个人实训得分
def total_score 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 end
# 个人通关数 # 个人通关数
def passed_count def passed_count
self.games.where(status: 2).count self.games.select{|game| game.status = 2}.size
end end
# 通关时间 # 通关时间
@ -89,12 +89,12 @@ class Myshixun < ApplicationRecord
# 耗时 # 耗时
def total_spend_time def total_spend_time
game_spend_time self.games.where(status: 2).sum(:cost_time).to_i game_spend_time total_cost_time
end end
# 通关总耗时 # 通关总耗时
def total_cost_time 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
end end

@ -10,5 +10,5 @@ json.homework_name homework.name
json.homework_id homework.id json.homework_id homework.id
json.homework_type homework.homework_type json.homework_type homework.homework_type
if homework.homework_type == "practice" if homework.homework_type == "practice"
json.shixun_identifier homework.shixuns.first.try(:identifier) json.shixun_identifier homework.shixuns.take.try(:identifier)
end end

@ -2,10 +2,6 @@ json.course_identity @user_course_identity
json.homework_type @homework_type json.homework_type @homework_type
json.course_public @course.is_public == 1 json.course_public @course.is_public == 1
json.is_end @course.is_end 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_id @main_category.try(:id)
json.main_category_name @main_category.try(:module_name) json.main_category_name @main_category.try(:module_name)
json.category_id @category.try(:id) json.category_id @category.try(:id)
@ -46,3 +42,8 @@ json.homeworks @homework_commons.each do |homework|
end end
end end
json.all_count @all_count
json.published_count @published_count
json.unpublished_count @all_count - @published_count
json.task_count @task_count

@ -101,7 +101,6 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
json.anonymous_appeal @homework.anonymous_appeal json.anonymous_appeal @homework.anonymous_appeal
json.student_works @student_works.each do |work| json.student_works @student_works.each do |work|
if @is_evaluation if @is_evaluation
json.(work, :id, :work_status, :update_time) json.(work, :id, :work_status, :update_time)

Loading…
Cancel
Save