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

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"
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

@ -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

@ -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位小数

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

@ -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

@ -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

@ -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

@ -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

@ -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)

Loading…
Cancel
Save