增加先按总评得分然后按时间排序

This commit is contained in:
sw 2014-10-30 17:42:08 +08:00
parent f65a852bc8
commit 00fec13367
1 changed files with 15 additions and 2 deletions

View File

@ -27,10 +27,12 @@ class HomeworkAttachController < ApplicationController
#获取已评作业列表
def get_batch_homeworks
teachers = find_course_teachers @course
teacher_proportion = get_teacher_proportion @bid
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*,
(SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers} and stars IS NOT NULL) 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 WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1
FROM homework_attaches WHERE bid_id = #{@bid.id}
ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC) AS table1
WHERE table1.t_score IS NOT NULL")
@homework_list = paginateHelper all_homework_list,10
respond_to do |format|
@ -41,11 +43,12 @@ class HomeworkAttachController < ApplicationController
#获取所有作业列表
def get_homeworks
teachers = find_course_teachers @course
teacher_proportion = get_teacher_proportion @bid
all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*,
(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 WHERE bid_id = #{@bid.id}
ORDER BY s_score DESC,created_at ASC")
ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC")
@homework_list = paginateHelper all_homework_list,10
respond_to do |format|
format.js
@ -393,5 +396,15 @@ class HomeworkAttachController < ApplicationController
end
teachers
end
#获取作业教师评分所占比例
def get_teacher_proportion bid
if bid.proportion
teacher_proportion = bid.proportion * 1.0 / 100
else
teacher_proportion = 1.0
end
teacher_proportion
end
end