From ba524675e09b2789acdf49b23eb5bdd8ca7666d9 Mon Sep 17 00:00:00 2001 From: alan <547533434@qq.com> Date: Wed, 31 Dec 2014 15:48:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9<=E6=89=93=E5=88=86=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E8=A1=A8=E5=8D=95>bug=20Signed-off-by:=20alan=20<5475?= =?UTF-8?q?33434@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 32 +++++++++---------- app/controllers/homework_attach_controller.rb | 4 ++- app/models/member.rb | 19 +++-------- app/views/courses/_member_list.html.erb | 2 +- app/views/courses/_show_member_score.html.erb | 12 ++----- 5 files changed, 27 insertions(+), 42 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 698344063..eb7246fda 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -399,7 +399,7 @@ class CoursesController < ApplicationController @results = paginateHelper_for_members @results, 10 else - @group = Group.find(group_id) + @group = CourseGroup.find(group_id) @results = student_homework_score(group_id, 0, 0,@score_sort_by) @results = paginateHelper @results, 10 end @@ -913,22 +913,22 @@ class CoursesController < ApplicationController if groupid == 0 if nums == 0 sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = 122 AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = 122) AND members.user_id = homework_attaches.user_id GROUP BY members.user_id - -UNION -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = 122 AND -students_for_courses.course_id = 122 and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = 122 ) + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id +AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id +UNION all +SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND +students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND +members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) ) GROUP BY members.user_id ORDER BY score #{score_sort_by}" else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches - WHERE members.course_id = 122 AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = 122) AND members.user_id = homework_attaches.user_id GROUP BY members.user_id - -UNION -SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = 122 AND -students_for_courses.course_id = 122 and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = 122 ) + WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id +AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id +UNION all +SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} AND +students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND +members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) ) GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{nums}" @@ -936,13 +936,13 @@ GROUP BY members.user_id ORDER BY score #{score_sort_by} limit #{start_from}, #{ else sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches WHERE members.course_id = #{@course.id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{@course.id}) AND members.user_id = homework_attaches.user_id - and members.course_group_id = #{groupid} + and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id}) GROUP BY members.user_id -UNION +UNION all SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{@course.id} and members.course_group_id = #{groupid} AND students_for_courses.course_id = #{@course.id} and members.user_id = students_for_courses.student_id AND -members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = 122 ) +members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id} ) ) GROUP BY members.user_id ORDER BY score #{score_sort_by}" end diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 347c8e11f..c979aded7 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -451,7 +451,9 @@ class HomeworkAttachController < ApplicationController homework.score = @m_score homework.is_teacher_score = 1 else - homework.score = homework.rates(:quality).select("avg(stars)") + sql = "SELECT AVG(stars) as stars FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = #{homework.id}" + score= HomeworkAttach.find_by_sql(sql).first.stars + homework.score = score end else if is_teacher == 1 diff --git a/app/models/member.rb b/app/models/member.rb index 446bb02e7..f1a139f74 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -117,25 +117,16 @@ class Member < ActiveRecord::Base # 查找每个学生每个作业的评分 def student_homework_score score_count = 0 - homework_score = HomeworkAttach.find_by_sql("SELECT bids.`name`, 0 as score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' - AND rateable_id = homework_attaches.id ) AS t_score, - (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' - AND rateable_id = homework_attaches.id ) AS s_score + homework_score = HomeworkAttach.find_by_sql("SELECT bids.name, homework_attaches.score as 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_score.each do |homework| - if !homework.t_score.nil? && homework.t_score != 0 - score = homework.t_score - else - if !homework.s_score.nil? - score= homework.s_score - else - score = 0 - end + mem_score = 0 + if homework[:score] + mem_score = homework[:score] end - score_count = score_count + score + score_count = score_count + mem_score end [homework_score, format("%0.2f", score_count)] end diff --git a/app/views/courses/_member_list.html.erb b/app/views/courses/_member_list.html.erb index 3e446f16e..07eed7170 100644 --- a/app/views/courses/_member_list.html.erb +++ b/app/views/courses/_member_list.html.erb @@ -38,7 +38,7 @@ <% else %>