优化《作业评分》

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-12-24 15:55:08 +08:00
parent 6e0311d928
commit abdd6458d3
1 changed files with 10 additions and 6 deletions

View File

@ -896,15 +896,19 @@ class CoursesController < ApplicationController
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
homeworks = HomeworkAttach.find_by_sql("SELECT homework_attaches.id
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
homeworks = homeworks.map {|homework| homework.id}.join(",")
homework_scores = HomeworkAttach.find_by_sql("SELECT homework_attaches.user_id, AVG(s1.stars) AS t_score,
AVG(s2.stars) AS s_score
FROM homework_attaches, seems_rateable_rates s1,seems_rateable_rates s2 WHERE
homework_attaches.id in (#{homeworks}) and s1.rateable_type = 'HomeworkAttach' and s1.rateable_id = homework_attaches.id
AND s1.rater_id IN (#{teachers}) and s2.rateable_type = 'HomeworkAttach'
and s2.rateable_id = homework_attaches.id
AND s2.rater_id not IN (#{teachers})")
end
#获取课程的老师列表
def find_course_teachers course