Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
Conflicts: db/schema.rb
This commit is contained in:
commit
05b9b26314
|
@ -759,6 +759,18 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def paginateHelper_for_members obj, pre_size=10
|
||||
@obj_count = StudentsForCourse.find_by_sql("select count(id) as mem_count from students_for_courses where course_id = #{@course.id}")[0][:mem_count].to_s.to_i
|
||||
@obj_pages = Paginator.new @obj_count, pre_size, params['page']
|
||||
if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation
|
||||
obj.limit(@obj_pages.per_page).offset(0)
|
||||
elsif obj.kind_of? Array
|
||||
obj[0, @obj_pages.per_page]
|
||||
else
|
||||
logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}"
|
||||
raise RuntimeError, 'unknow type, Please input you type into this helper.'
|
||||
end
|
||||
end
|
||||
|
||||
#查找首页相关信息
|
||||
def find_first_page
|
||||
|
|
|
@ -23,7 +23,7 @@ class CoursesController < ApplicationController
|
|||
|
||||
before_filter :require_login, :only => [:join, :unjoin]
|
||||
#before_filter :allow_join, :only => [:join]
|
||||
@@result = nil
|
||||
|
||||
def join
|
||||
if User.current.logged?
|
||||
course = Course.find_by_id params[:object_id]
|
||||
|
@ -213,12 +213,13 @@ 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(student_homework_score, q)
|
||||
@results = searchmember_by_name(student_homework_score(0,0,0), q)
|
||||
|
||||
elsif params[:ingroup]
|
||||
@group = CourseGroup.find(params[:search_group_id])
|
||||
@results =searchgroupmember_by_name(student_homework_score, @group, q)
|
||||
@results = searchmember_by_name(student_homework_score(@group.id,0,0), q)
|
||||
end
|
||||
|
||||
@is_remote = true
|
||||
@result_count = @results.count
|
||||
@results = paginateHelper @results
|
||||
|
||||
|
@ -287,7 +288,7 @@ class CoursesController < ApplicationController
|
|||
@group = group
|
||||
|
||||
@course_groups = @course.course_groups
|
||||
@membercount = @members.count
|
||||
|
||||
search_group_members group
|
||||
end
|
||||
def unjoin_group
|
||||
|
@ -299,7 +300,6 @@ class CoursesController < ApplicationController
|
|||
@group = group
|
||||
@course_groups = @course.course_groups
|
||||
|
||||
@membercount = @members.count
|
||||
search_group_members group
|
||||
end
|
||||
def searchgroupmembers
|
||||
|
@ -309,15 +309,19 @@ class CoursesController < ApplicationController
|
|||
@is_remote = true
|
||||
if params[:group_id] && params[:group_id] != "0"
|
||||
@group = CourseGroup.find(params[:group_id])
|
||||
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
|
||||
else
|
||||
@results = student_homework_score
|
||||
end
|
||||
@@result = @results
|
||||
|
||||
@members = searchStudent(@course)
|
||||
@membercount = @members.count
|
||||
@results = paginateHelper @results
|
||||
@results = student_homework_score(@group.id,0, 0)
|
||||
@results = paginateHelper @results, 10
|
||||
|
||||
|
||||
else
|
||||
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
||||
@results = student_homework_score(0,page_from, 10)
|
||||
@results = paginateHelper_for_members @results, 10
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
@ -325,30 +329,36 @@ class CoursesController < ApplicationController
|
|||
## 有角色参数的才是课程,没有的就是项目
|
||||
if (User.current.admin? || @course.is_public == 1 || (@course.is_public == 0 && User.current.member_of_course?(@course)))
|
||||
@render_file = 'member_list'
|
||||
@teachers= searchTeacherAndAssistant(@course)
|
||||
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@role = params[:role]
|
||||
@role = params[:role].nil? ? '2':params[:role]
|
||||
@is_remote = true
|
||||
@course_groups = @course.course_groups if @course.course_groups
|
||||
@show_serch = params[:role] == '2'
|
||||
case params[:role]
|
||||
case @role
|
||||
when '1'
|
||||
@subPage_title = l :label_teacher_list
|
||||
@members = @teachers
|
||||
@members = searchTeacherAndAssistant(@course)
|
||||
@members = paginateHelper @members, 10
|
||||
when '2'
|
||||
@subPage_title = l :label_student_list
|
||||
@members = student_homework_score
|
||||
page = params[:page].nil? ? 0 : (params['page'].to_i - 1)
|
||||
@members = student_homework_score(0,page, 10)
|
||||
|
||||
@members = paginateHelper_for_members @members, 10
|
||||
|
||||
# @member_scores = @@member_scores
|
||||
# @members = searchStudent_sort(@course, 'desc', @@member_scores)
|
||||
@membercount = @members.count
|
||||
|
||||
else
|
||||
@subPage_title = ''
|
||||
@members = @course.member_principals.includes(:roles, :principal).all.sort
|
||||
end
|
||||
@@result = @members
|
||||
@members = paginateHelper @members
|
||||
render :layout => 'base_courses'
|
||||
respond_to do |format|
|
||||
if params[:page]
|
||||
format.js
|
||||
else
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# render :layout => 'base_courses'
|
||||
else
|
||||
render_403
|
||||
end
|
||||
|
@ -356,19 +366,19 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
|
||||
def member_score_sort
|
||||
@teachers= searchTeacherAndAssistant(@course)
|
||||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@role = params[:role]
|
||||
@course_groups = @course.course_groups if @course.course_groups
|
||||
@show_serch = params[:role] == '2'
|
||||
@subPage_title = l :label_student_list
|
||||
@render_file = 'member_list'
|
||||
|
||||
unless @@result.nil?
|
||||
@results = @@result.reverse
|
||||
@@result = @results
|
||||
end
|
||||
@results = paginateHelper @results
|
||||
# @teachers= searchTeacherAndAssistant(@course)
|
||||
# @canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
# @role = params[:role]
|
||||
# @course_groups = @course.course_groups if @course.course_groups
|
||||
# @show_serch = params[:role] == '2'
|
||||
# @subPage_title = l :label_student_list
|
||||
# @render_file = 'member_list'
|
||||
# @results = params[:result] if params[:result]
|
||||
# unless @result.nil?
|
||||
# @results = @result.reverse
|
||||
#
|
||||
# end
|
||||
# @results = paginateHelper @results
|
||||
end
|
||||
# 显示每个学生的作业评分详情
|
||||
def show_member_score
|
||||
|
@ -377,19 +387,11 @@ class CoursesController < ApplicationController
|
|||
respond_to do |format|
|
||||
format.html {render :layout => 'course_base'}
|
||||
format.js
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
#判断指定用户是否为课程教师
|
||||
def isCourseTeacher(id)
|
||||
result = false
|
||||
if @teachers.find_by_user_id(id) != nil
|
||||
result = true
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def handle_course courses, activities
|
||||
course_activity_count_array=activities.values()
|
||||
|
||||
|
@ -880,11 +882,13 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def student_homework_score
|
||||
def student_homework_score(groupid,start_from, nums)
|
||||
#teachers = find_course_teachers(@course)
|
||||
start_from = start_from * nums
|
||||
sql = ActiveRecord::Base.connection()
|
||||
|
||||
homework_scores = Member.find_by_sql("call member_score(#{@course.id},#{groupid},#{start_from},#{nums})")
|
||||
|
||||
homework_scores = Member.find_by_sql("call member_score(#{@course.id})")
|
||||
sql.close()
|
||||
homework_scores
|
||||
end
|
||||
|
@ -900,10 +904,10 @@ class CoursesController < ApplicationController
|
|||
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
|
||||
@is_remote = true
|
||||
|
||||
@members = searchStudent(@course)
|
||||
@membercount = @members.count
|
||||
@results = student_homework_score.find_all {|mem| mem.course_group_id == group.id}
|
||||
@@result = @results
|
||||
@results = paginateHelper @results
|
||||
|
||||
page_from = params[:page].nil? ? 0 : (params[:page].to_i - 1)
|
||||
@results = student_homework_score(group.id,0,0)
|
||||
@results = paginateHelper @results, 10
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -129,7 +129,7 @@ class MembersController < ApplicationController
|
|||
member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
|
||||
role = Role.find_by_id(params[:membership][:role_ids])
|
||||
# 这里的判断只能通过角色名,可以弄成常量
|
||||
if role.name == "学生"
|
||||
if role.name == "学生" || role.name == "Student"
|
||||
StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id)
|
||||
end
|
||||
members << member
|
||||
|
@ -210,7 +210,7 @@ class MembersController < ApplicationController
|
|||
if (params[:membership][:role_ids])
|
||||
role = Role.find(params[:membership][:role_ids][0])
|
||||
# 这里的判断只能通过角色名,可以弄成常量
|
||||
if role.name == "学生"
|
||||
if role.name == "学生" || role.name == "Student"
|
||||
StudentsForCourse.create(:student_id => @member.user_id, :course_id =>@course.id)
|
||||
else
|
||||
joined = StudentsForCourse.where('student_id = ? and course_id = ?', @member.user_id,@course.id)
|
||||
|
|
|
@ -173,6 +173,7 @@ class Query < ActiveRecord::Base
|
|||
:string => [ "=", "~", "!", "!~", "!*", "*" ],
|
||||
:text => [ "~", "!~", "!*", "*" ],
|
||||
:integer => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||||
:integer_done => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||||
:float => [ "=", ">=", "<=", "><", "!*", "*" ],
|
||||
:relation => ["=", "=p", "=!p", "!p", "!*", "*"]
|
||||
}
|
||||
|
@ -217,6 +218,8 @@ class Query < ActiveRecord::Base
|
|||
case type_for(field)
|
||||
when :integer
|
||||
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+$/) }
|
||||
when :integer_done
|
||||
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+$/) || (v.match(/^[+-]?\d+$/) && (v.to_i<0 || v.to_i> 100)) }
|
||||
when :float
|
||||
add_filter_error(field, :invalid) if values_for(field).detect {|v| v.present? && !v.match(/^[+-]?\d+(\.\d*)?$/) }
|
||||
when :date, :date_past
|
||||
|
@ -602,6 +605,12 @@ class Query < ActiveRecord::Base
|
|||
else
|
||||
sql = "#{db_table}.#{db_field} = #{value.first.to_i}"
|
||||
end
|
||||
when :integer_done
|
||||
if is_custom_filter
|
||||
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) = #{value.first.to_i})"
|
||||
else
|
||||
sql = "#{db_table}.#{db_field} = #{value.first.to_i}"
|
||||
end
|
||||
when :float
|
||||
if is_custom_filter
|
||||
sql = "(#{db_table}.#{db_field} <> '' AND CAST(CASE #{db_table}.#{db_field} WHEN '' THEN '0' ELSE #{db_table}.#{db_field} END AS decimal(30,3)) BETWEEN #{value.first.to_f - 1e-5} AND #{value.first.to_f + 1e-5})"
|
||||
|
|
|
@ -62,6 +62,11 @@
|
|||
:is_student_batch_homework => @is_student_batch_homework}%>
|
||||
</div>
|
||||
</div>
|
||||
<% if @is_teacher %>
|
||||
<!--<div>
|
||||
导出 <a>csv</a>
|
||||
</div>-->
|
||||
<% end %>
|
||||
</div>
|
||||
<div id="show_homework_attach_model"></div>
|
||||
</body>
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
var classname = document.getElementById(id).className
|
||||
if(classname == 'st_up') {
|
||||
document.getElementById(id).className = 'st_down'
|
||||
|
||||
}
|
||||
else
|
||||
document.getElementById(id).className = 'st_up'
|
||||
|
||||
}
|
||||
</script>
|
||||
<div style="margin-left: 15px" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
|
||||
|
@ -34,7 +36,7 @@
|
|||
<div class="st_box">
|
||||
<ul class="st_box_top" style="margin-left: 17px;">
|
||||
<% if @subPage_title == l(:label_student_list) %>
|
||||
<li class="ml358"><%= link_to '作业积分', member_score_sort_course_path ,method: 'get', remote: true, :onclick => "change_pic('pic')"%>
|
||||
<li class="ml358"><%= link_to '作业积分', member_score_sort_course_path ,:result => members,method: 'get', remote: true, :onclick => "change_pic('pic')"%>
|
||||
<a id="pic" href="#" class="st_down"></a>
|
||||
</li>
|
||||
<li class="ml50">
|
||||
|
@ -101,7 +103,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="pagination">
|
||||
<%= pagination_links_full @obj_pages, @obj_count, :remote =>true, :per_page_links => false %>
|
||||
<%= pagination_links_full @obj_pages, @obj_count,:per_page_links => false, :remote =>@is_remote %>
|
||||
</div>
|
||||
<% else %>
|
||||
<p class="nodata">
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<% if @subPage_title && @subPage_title == l(:label_student_list)%>
|
||||
<%= form_tag( searchmembers_course_path(@course), method: 'get',:class => "f_l",:style => "margin-left: 5px; ",:remote=>true) do %>
|
||||
<%= text_field_tag 'name', params[:name], name: "name", :class => 'f_1', :style => "height:15px; float: left;"%>
|
||||
<% if @group %>
|
||||
<%= hidden_field "search_group_id", params[:search_group_id],:value => "#{@group.id}", name: 'search_group_id' %>
|
||||
<%= submit_tag l(:label_search_member), :name => "ingroup",:class => "f_2", :style => "float: left "%>
|
||||
<% else %>
|
||||
<%= submit_tag l(:label_search_member),:style => "float: left", :name => 'incourse',:onclick => "checkclass('group_name_0')",:class => "f_2"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
|
@ -57,20 +57,10 @@
|
|||
<%= stylesheet_link_tag 'course_group', :media => 'all' %>
|
||||
<script type="text/javascript" src="javascripts/jquery-1.8.3-ui-1.9.2-ujs-2.0.3.js"></script>
|
||||
<div class="st_list">
|
||||
<div class="st_search" style="margin-left: 14px">
|
||||
<div class="st_search" style="margin-left: 14px" >
|
||||
<span class="f_l"><%= @subPage_title %></span>
|
||||
<span>
|
||||
<% if @subPage_title && @subPage_title == l(:label_student_list)%>
|
||||
<%= form_tag( searchmembers_course_path(@course), method: 'get',:class => "f_l",:style => "margin-left: 5px; ",:remote=>true) do %>
|
||||
<%= text_field_tag 'name', params[:name], name: "name", :class => 'f_1', :style => "height:15px; float: left;"%>
|
||||
<% if @group %>
|
||||
<%= hidden_field "search_group_id", params[:search_group_id],:value => "#{@group.id}", name: 'search_group_id' %>
|
||||
<%= submit_tag l(:label_search_member), :name => "ingroup",:class => "f_2", :style => "float: left "%>
|
||||
<% else %>
|
||||
<%= submit_tag l(:label_search_member),:style => "float: left", :name => 'incourse',:onclick => "checkclass('group_name_0')",:class => "f_2"%>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<span id = "search_members">
|
||||
<%= render :partial => 'searchmembers' %>
|
||||
</span>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @members})%>");
|
|
@ -1,4 +1,5 @@
|
|||
/**
|
||||
* Created by Administrator on 2014/12/3.
|
||||
*/
|
||||
$("#search_members").html("<%= escape_javascript( render :partial => 'searchmembers')%>");
|
||||
$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>");
|
|
@ -1,97 +1,100 @@
|
|||
|
||||
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 ;
|
||||
#encoding=UTF-8
|
||||
class SelectMemberScore < ActiveRecord::Migration
|
||||
def up
|
||||
sql = ("
|
||||
|
||||
CREATE
|
||||
|
||||
PROCEDURE `member_score`(IN courseid INT)
|
||||
|
||||
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;
|
||||
|
||||
")
|
||||
execute(sql)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,100 @@
|
|||
class ProMemberScore < ActiveRecord::Migration
|
||||
def up
|
||||
sql_delete = ("DROP PROCEDURE IF EXISTS `member_score`;")
|
||||
sql = ("
|
||||
CREATE PROCEDURE `member_score`(IN courseid INT, IN groupid INT,IN start_from INT, IN nums INT)
|
||||
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;
|
||||
IF nums <> 0 THEN
|
||||
SELECT * FROM mems ORDER BY score DESC LIMIT start_from, nums;
|
||||
ELSE
|
||||
SELECT * FROM mems WHERE course_group_id = groupid ORDER BY score DESC;
|
||||
END IF;
|
||||
END;
|
||||
|
||||
")
|
||||
execute(sql_delete)
|
||||
execute(sql)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue