优化《学生列表作业评分查询太慢》功能
Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
parent
d81240e63c
commit
683acfcafc
|
@ -218,6 +218,7 @@ class CoursesController < ApplicationController
|
|||
@group = CourseGroup.find(params[:search_group_id])
|
||||
@results = searchgroupstudent_by_name(@group, @course, q)
|
||||
end
|
||||
@member_scores = @@member_scores
|
||||
@result_count = @results.count
|
||||
@results = paginateHelper @results
|
||||
|
||||
|
@ -316,6 +317,7 @@ class CoursesController < ApplicationController
|
|||
@results = searchStudent(@course)
|
||||
end
|
||||
@@result = @results
|
||||
@member_scores = @@member_scores
|
||||
@members = searchStudent(@course)
|
||||
@membercount = @members.count
|
||||
@results = paginateHelper @results
|
||||
|
@ -325,6 +327,7 @@ class CoursesController < ApplicationController
|
|||
@render_file = 'member_list'
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
@member_scores = @@member_scores
|
||||
@members = searchStudent(@course)
|
||||
@membercount = @members.count
|
||||
@results = searchStudent_by_group(group, @course)
|
||||
|
@ -346,8 +349,9 @@ class CoursesController < ApplicationController
|
|||
@members = searchTeacherAndAssistant(@course)
|
||||
when '2'
|
||||
@subPage_title = l :label_student_list
|
||||
|
||||
@members = searchStudent_sort(@course, 'desc')
|
||||
@@member_scores = student_homework_score
|
||||
@member_scores = @@member_scores
|
||||
@members = searchStudent_sort(@course, 'desc', @@member_scores)
|
||||
@membercount = @members.count
|
||||
|
||||
else
|
||||
|
@ -371,6 +375,7 @@ class CoursesController < ApplicationController
|
|||
@show_serch = params[:role] == '2'
|
||||
@subPage_title = l :label_student_list
|
||||
@render_file = 'member_list'
|
||||
@member_scores = @@member_scores
|
||||
unless @@result.nil?
|
||||
@results = @@result.reverse
|
||||
@@result = @results
|
||||
|
@ -379,6 +384,7 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
# 显示每个学生的作业评分详情
|
||||
def show_member_score
|
||||
@member_scores = @@member_scores
|
||||
@member_score = Member.find(params[:member_id]) if params[:member_id]
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'course_base'}
|
||||
|
@ -886,5 +892,22 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def student_homework_score
|
||||
teachers = find_course_teachers(@course)
|
||||
|
||||
score_count = 0
|
||||
homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.user_id as user_id,homework_attaches.bid_id as bid_id, bids.name as name,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
|
||||
AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) ) AS t_score,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
|
||||
AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
|
||||
FROM homework_attaches, bids where
|
||||
homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{@course.id}
|
||||
and homework_attaches.bid_id = bids.id)")
|
||||
homework_scores
|
||||
end
|
||||
#获取课程的老师列表
|
||||
def find_course_teachers course
|
||||
searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -175,7 +175,7 @@ module CoursesHelper
|
|||
end
|
||||
members
|
||||
end
|
||||
def searchStudent_sort project, sort_by
|
||||
def searchStudent_sort project, sort_by, member_scores
|
||||
#searchPeopleByRoles(project, StudentRoles)
|
||||
members = []
|
||||
|
||||
|
@ -185,7 +185,7 @@ module CoursesHelper
|
|||
|
||||
end
|
||||
end
|
||||
members.sort!{ |mem1, mem2| mem1.student_homework_score[1].to_f <=> mem2.student_homework_score[1].to_f}
|
||||
members.sort!{ |mem1, mem2| mem1.student_homework_score(member_scores)[1].to_f <=> mem2.student_homework_score(member_scores)[1].to_f}
|
||||
if sort_by == "desc"
|
||||
members.reverse!
|
||||
end
|
||||
|
|
|
@ -115,19 +115,10 @@ class Member < ActiveRecord::Base
|
|||
end
|
||||
|
||||
# 查找每个学生每个作业的评分
|
||||
def student_homework_score
|
||||
teachers = find_course_teachers(self.course)
|
||||
|
||||
def student_homework_score homework_scores
|
||||
score_count = 0
|
||||
homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.bid_id as bid_id, bids.name as name,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
|
||||
AND rateable_id = homework_attaches.id AND rater_id IN (#{teachers}) ) AS t_score,
|
||||
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach'
|
||||
AND rateable_id = homework_attaches.id AND rater_id NOT IN (#{teachers})) AS s_score
|
||||
FROM homework_attaches, bids where homework_attaches.user_id = #{self.user_id}
|
||||
and homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses where course_id = #{self.course_id}
|
||||
and homework_attaches.bid_id = bids.id)")
|
||||
homework_scores.each do |homework|
|
||||
homework_score = homework_scores.find_all { |e| e.user_id == self.user_id}
|
||||
homework_score.each do |homework|
|
||||
if !homework.t_score.nil? && homework.t_score != 0
|
||||
score = homework.t_score
|
||||
else
|
||||
|
@ -139,7 +130,7 @@ class Member < ActiveRecord::Base
|
|||
end
|
||||
score_count = score_count + score
|
||||
end
|
||||
[homework_scores, format("%0.2f", score_count)]
|
||||
[homework_score, format("%0.2f", score_count)]
|
||||
end
|
||||
protected
|
||||
|
||||
|
@ -148,10 +139,7 @@ class Member < ActiveRecord::Base
|
|||
end
|
||||
|
||||
|
||||
#获取课程的老师列表
|
||||
def find_course_teachers course
|
||||
searchTeacherAndAssistant(course).map{|teacher| teacher.user_id}.join(",")
|
||||
end
|
||||
|
||||
def searchTeacherAndAssistant project
|
||||
#searchPeopleByRoles(project, TeacherRoles)
|
||||
members = []
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<% end %>
|
||||
</ul>
|
||||
<% if @subPage_title == l(:label_student_list) %>
|
||||
<%= link_to member.student_homework_score[1].to_s, {
|
||||
<%= link_to member.student_homework_score(@member_scores)[1].to_s, {
|
||||
:action => 'show_member_score',
|
||||
:member_id => member.id,
|
||||
:remote => true},
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
<% end %>
|
||||
</ul>
|
||||
<% if @subPage_title == l(:label_student_list) %>
|
||||
<%= link_to member.student_homework_score[1].to_s, {
|
||||
<%= link_to member.student_homework_score(@member_scores)[1].to_s, {
|
||||
:action => 'show_member_score',
|
||||
:member_id => member.id,
|
||||
:remote => true},
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<h2><%= @member_score.user.name %> 历次作业积分</h2>
|
||||
<ul class="tscore_box">
|
||||
<li ><span class="c_blue02 w280">作业名称</span><span class="c_blue02 w70">得分</span></li>
|
||||
<% @member_score.student_homework_score[0].each do |homework_score| %>
|
||||
<% @member_score.student_homework_score(@member_scores)[0].each do |homework_score| %>
|
||||
<% if !homework_score.t_score.nil? && homework_score.t_score != 0 %>
|
||||
<% score = homework_score.t_score %>
|
||||
<% else %>
|
||||
|
@ -51,7 +51,7 @@
|
|||
<% end %>
|
||||
<li><span class="c_grey02 w280"><%= homework_score.name %></span><span class="c_red w70"><%= format("%0.2f",score) %></span></li>
|
||||
<% end %>
|
||||
<li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score[1] %></span></li>
|
||||
<li><span class="c_blue03 w280">作业积分(总得分)</span><span class="c_red w70"><%= @member_score.student_homework_score(@member_scores)[1] %></span></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue