This commit is contained in:
sw 2014-12-26 15:37:22 +08:00
commit 2e1387b9e4
6 changed files with 133 additions and 32 deletions

View File

@ -759,6 +759,7 @@ class ApplicationController < ActionController::Base
end
end
#查找首页相关信息
def find_first_page
@first_page = FirstPage.find_by_page_type('project')

View File

@ -213,10 +213,10 @@ class CoursesController < ApplicationController
q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
if params[:incourse]
@results = searchmember_by_name(@@member_scores, q)
@results = searchmember_by_name(student_homework_score, q)
elsif params[:ingroup]
@group = CourseGroup.find(params[:search_group_id])
@results = @results =searchgroupmember_by_name(@@member_scores, @group, q)
@results =searchgroupmember_by_name(student_homework_score, @group, q)
end
@result_count = @results.count
@ -285,7 +285,7 @@ class CoursesController < ApplicationController
member.course_group_id = group.id
member.save
@group = group
@members = searchStudent(@course)
@course_groups = @course.course_groups
@membercount = @members.count
search_group_members group
@ -298,7 +298,7 @@ class CoursesController < ApplicationController
member.save
@group = group
@course_groups = @course.course_groups
@members = searchStudent(@course)
@membercount = @members.count
search_group_members group
end
@ -309,9 +309,9 @@ class CoursesController < ApplicationController
@is_remote = true
if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id])
@results = @@member_scores.find_all {|mem| mem.course_group_id == group.id}
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
else
@results = @@member_scores
@results = student_homework_score
end
@@result = @results
@ -336,9 +336,8 @@ class CoursesController < ApplicationController
@members = @teachers
when '2'
@subPage_title = l :label_student_list
teachers = @teachers.map{|teacher| teacher.user_id}.join(",")
@@member_scores = student_homework_score teachers
@members = @@member_scores
@members = student_homework_score
# @member_scores = @@member_scores
# @members = searchStudent_sort(@course, 'desc', @@member_scores)
@membercount = @members.count
@ -881,17 +880,12 @@ class CoursesController < ApplicationController
end
end
def student_homework_score teachers
homework_scores = Member.find_by_sql("SELECT id, user_id,course_id, course_group_id,created_on,IFNULL(SUM(CASE WHEN t_score <> 0 AND t_score IS NOT NULL THEN t_score ELSE s_score END),0) as score
FROM (
SELECT members.id as id, members.user_id AS user_id, members.course_id AS course_id, members.created_on as created_on,members.course_group_id AS course_group_id,
(SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN (3040,4762,4765)) AS t_score,
(SELECT AVG(seems_rateable_rates.stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN (3040,4762,4765)) AS s_score
FROM `homework_attaches` , members
WHERE members.course_id = #{@course.id}
AND members.user_id NOT IN (#{teachers}) AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = #{@course.id})
AND homework_attaches.user_id = members.user_id
) AS table1 GROUP BY user_id ORDER BY score DESC")
def student_homework_score
#teachers = find_course_teachers(@course)
sql = ActiveRecord::Base.connection()
homework_scores = Member.find_by_sql("call member_score(#{@course.id})")
sql.close()
homework_scores
end
#获取课程的老师列表
@ -908,7 +902,7 @@ class CoursesController < ApplicationController
@members = searchStudent(@course)
@membercount = @members.count
@results = @@member_scores.find_all {|mem| mem.course_group_id == group.id}
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
@@result = @results
@results = paginateHelper @results
end

View File

@ -395,8 +395,7 @@ class FilesController < ApplicationController
render :layout => 'base_courses'
}
end
end
else
show_attachments @containers
@attachtype = params[:type].to_i
@contenttype = params[:contentType].to_s
@ -405,6 +404,9 @@ class FilesController < ApplicationController
format.js
format.html
end
end
end
end

View File

@ -194,19 +194,23 @@ module CoursesHelper
def searchmember_by_name members, name
#searchPeopleByRoles(project, StudentRoles)
mems = []
if name != ""
members.each do |m|
username = m.user[:lastname].to_s + m.user[:firstname].to_s
if(m.user[:login].to_s.include?(name) || m.user.user_extensions[:student_id].to_s.include?(name) || username.include?(name))
mems << m
end
end
else
mems = members
end
mems
end
def searchgroupmember_by_name members, name, group
#searchPeopleByRoles(project, StudentRoles)
mems = []
if name != ""
members.each do |m|
if m.course_group_id == group.id
username = m.user[:lastname].to_s + m.user[:firstname].to_s
@ -215,6 +219,9 @@ module CoursesHelper
end
end
end
else
mems = members
end
mems
end
def searchgroupstudent_by_name(group, project, name)

View File

@ -53,7 +53,7 @@
<% members.each do |member| %>
<div class="cl"></div><!--st_box_top end-->
<div class="st_boxlist">
<% next if member.new_record? %>
<a href="#" class="st_img" style="float:left;">
<%= member.user.nil? ? '' : (image_tag(url_to_avatar(member.user), :width => 40, :height => 40)) %>
</a>
@ -101,7 +101,7 @@
</div>
</div>
<div class="pagination">
<%= pagination_links_full @obj_pages, @obj_count, :per_page_links => false %>
<%= pagination_links_full @obj_pages, @obj_count, :remote =>true, :per_page_links => false %>
</div>
<% else %>
<p class="nodata">

97
data/member_score.sql Normal file
View File

@ -0,0 +1,97 @@
DELIMITER $$
CREATE
/*[DEFINER = { user | CURRENT_USER }]*/
PROCEDURE `member_score`(IN courseid INT)
/*LANGUAGE SQL
| [NOT] DETERMINISTIC
| { CONTAINS SQL | NO SQL | READS SQL DATA | MODIFIES SQL DATA }
| SQL SECURITY { DEFINER | INVOKER }
| COMMENT 'string'*/
BEGIN
CREATE TEMPORARY TABLE IF NOT EXISTS course_teachers (
id INT
);
TRUNCATE TABLE course_teachers;
CREATE TEMPORARY TABLE IF NOT EXISTS mems (
id INT ,
user_id INT,
course_id INT,
created_on DATETIME,
course_group_id INT,
score FLOAT DEFAULT 0
);
TRUNCATE TABLE mems;
CREATE TEMPORARY TABLE IF NOT EXISTS mem_home (
id INT,
user_id INT,
course_id INT,
created_on DATETIME,
course_group_id INT,
home_id INT,
score FLOAT DEFAULT 0
);
TRUNCATE TABLE mem_home;
CREATE TEMPORARY TABLE IF NOT EXISTS t_scores (
home_id INT,
score FLOAT
);
TRUNCATE TABLE t_scores;
CREATE TEMPORARY TABLE IF NOT EXISTS s_scores (
home_id INT,
score FLOAT
);
TRUNCATE TABLE s_scores;
CREATE TEMPORARY TABLE IF NOT EXISTS scores (
user_id INT,
score FLOAT
);
TRUNCATE TABLE scores;
INSERT INTO course_teachers (SELECT members.user_id FROM members WHERE members.user_id NOT IN (SELECT student_id FROM students_for_courses WHERE course_id = courseid));
#查出所有的学生
INSERT INTO mems (id, user_id, course_id, created_on, course_group_id)
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id
FROM members WHERE course_id = courseid AND members.user_id NOT IN (SELECT id FROM course_teachers));
# 查出所有的学生列表及其作业
INSERT INTO mem_home (id, user_id, course_id, created_on, course_group_id,home_id)
(SELECT members.id, members.user_id, members.course_id, members.created_on, members.course_group_id, homework_attaches.id
FROM members, homework_attaches WHERE course_id = courseid
AND members.user_id = homework_attaches.user_id AND members.user_id NOT IN (SELECT id FROM course_teachers)
AND homework_attaches.bid_id IN (SELECT bid_id FROM homework_for_courses WHERE course_id = courseid ));
INSERT INTO t_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
AND rater_id IN (SELECT id FROM course_teachers)
GROUP BY rateable_id);
INSERT INTO s_scores (home_id, score) (SELECT rateable_id,AVG(seems_rateable_rates.stars)
FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id IN (SELECT mem_home.home_id FROM mem_home)
AND rater_id NOT IN (SELECT id FROM course_teachers)
GROUP BY rateable_id) ;
UPDATE mem_home, t_scores SET mem_home.score = t_scores.score WHERE mem_home.home_id = t_scores.home_id ;
UPDATE mem_home, s_scores SET mem_home.score = s_scores.score WHERE mem_home.home_id = s_scores.home_id AND mem_home.score = 0;
INSERT INTO scores (user_id, score) (SELECT user_id, SUM(score) FROM mem_home GROUP BY user_id);
UPDATE mems, scores SET mems.score = scores.score WHERE mems.user_id = scores.user_id;
SELECT * FROM mems ORDER BY score DESC;
END$$
DELIMITER ;