增加项目评分 个人评分 ,个人在项目中的评分机制

This commit is contained in:
nieguanghui 2013-10-21 09:42:09 +08:00
parent 5d0b5812b3
commit b04fe3d1bb
24 changed files with 553 additions and 88 deletions

View File

@ -307,11 +307,14 @@ class BidsController < ApplicationController
# a = [1] # a = [1]
# @project = Project.where("id in []", a) # @project = Project.where("id in []", a)
@user = @bid.author @user = @bid.author
@bidding_project = @bid.biding_projects @bidding_project = @bid.biding_projects.all
@bidding_project = @bidding_project.sort {|a,b| b.project.project_status.grade <=> a.project.project_status.grade}
if @bid.homework_type == 1 if @bid.homework_type == 1
@homework = HomeworkAttach.new @homework = HomeworkAttach.new
@homework_list = @bid.homeworks @homework_list = @bid.homeworks
end end
respond_to do |format| respond_to do |format|
if @bid.reward_type == 3 if @bid.reward_type == 3
format.html { format.html {

View File

@ -48,12 +48,14 @@ class MembersController < ApplicationController
def create def create
members = [] members = []
project_info = [] project_info = []
user_grade = []
if params[:membership] if params[:membership]
if params[:membership][:user_ids] if params[:membership][:user_ids]
attrs = params[:membership].dup attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids) user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id| user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grade << UserGrade.new(:user_id => user_id, :project_id => @project.id)
## added by nie ## added by nie
if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id) project_info << ProjectInfo.new(:user_id => user_id, :project_id => @project.id)
@ -65,13 +67,14 @@ class MembersController < ApplicationController
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id])
## added by nie ## added by nie
if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") if(params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
project_info << ProjectInfo.new(:role_ids => params[:membership][:role_ids], :user_id => params[:membership][:user_id]) project_info << ProjectInfo.new(:project_id => @project.id, :user_id => params[:membership][:user_id])
end end
## end ## end
end end
@project.members << members @project.members << members
# added by nie # added by nie
@project.project_infos << project_info @project.project_infos << project_info
@project.user_grades << user_grade
# end # end
end end
@ -124,13 +127,20 @@ class MembersController < ApplicationController
def destroy def destroy
if request.delete? && @member.deletable? if request.delete? && @member.deletable?
@member.destroy @member.destroy
end # end
user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id) user_admin = ProjectInfo.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_admin.size > 0 if user_admin.size > 0
user_admin.each do |user| user_admin.each do |user|
user.destroy user.destroy
end end
end end
user_grade = UserGrade.where("user_id = ? and project_id = ?", @member.user_id, @project.id)
if user_grade.size > 0
user_grade.each do |grade|
grade.destroy
end
end
end
respond_to do |format| respond_to do |format|
format.html { redirect_to_settings_in_projects } format.html { redirect_to_settings_in_projects }
format.js format.js

View File

@ -146,8 +146,20 @@ class ProjectsController < ApplicationController
# #
# end # end
# end # end
# @projects = Project.where("project_type <> ? or project_type is null", 1)
# @projects.each do |project| # @projects.each do |project|
# ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count) # @id = project.id
# @users = Member.find_by_sql("SELECT
# members.user_id
# FROM members
# INNER JOIN users
# ON members.user_id = users.id
# WHERE members.project_id = #{@id}
# AND (users.type = 'User' AND users.status = 1);")
# @users.each do |user|
# UserGrade.create(:project_id => project.id, :user_id => user.user_id)
# end
# #ProjectStatus.create(:changesets_count => project.changesets.count, :project_id => project.id, :watchers_count => project.watcher_users.count)
# end # end
# @projects_status = Project.visible.like(params[:name]) if params[:name].present? # @projects_status = Project.visible.like(params[:name]) if params[:name].present?
@project_count = @projects_status.count @project_count = @projects_status.count
@ -175,13 +187,13 @@ class ProjectsController < ApplicationController
when '1' when '1'
@offset ||= @project_pages.reverse_offset @offset ||= @project_pages.reverse_offset
unless @offset == 0 unless @offset == 0
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse
else else
limit = @project_count % @limit limit = @project_count % @limit
if limit == 0 if limit == 0
limit = @limit limit = @limit
end end
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse
end end
@s_type = 1 @s_type = 1
@ -202,13 +214,13 @@ class ProjectsController < ApplicationController
else else
@offset ||= @project_pages.reverse_offset @offset ||= @project_pages.reverse_offset
unless @offset == 0 unless @offset == 0
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse @projects_status = @projects_status.reorder('grade').offset(@offset).limit(@limit).all.reverse
else else
limit = @project_count % @limit limit = @project_count % @limit
if limit == 0 if limit == 0
limit = @limit limit = @limit
end end
@projects_status = @projects_status.reorder('changesets_count').offset(@offset).limit(limit).all.reverse @projects_status = @projects_status.reorder('grade').offset(@offset).limit(limit).all.reverse
end end
@s_type = 1 @s_type = 1
# @projects = @projects.sort {|x,y| y.created_on <=> x.created_on } # @projects = @projects.sort {|x,y| y.created_on <=> x.created_on }
@ -524,8 +536,9 @@ class ProjectsController < ApplicationController
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
m = Member.new(:user => User.current, :roles => [r]) m = Member.new(:user => User.current, :roles => [r])
project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id) project = ProjectInfo.new(:user_id => User.current.id, :project_id => @project.id)
if (params[:project][:is_public] == '1' && @course_tag != "1") || (@course_tag=="1" && params[:project][:is_public] == '1') UserGrade.create(:user_id => User.current.id, :project_id => @project.id, :grade => 0)
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @course_tag) if params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :grade => 0, :project_type => @course_tag)
end end
@project.members << m @project.members << m
@project.project_infos << project @project.project_infos << project
@ -747,6 +760,20 @@ class ProjectsController < ApplicationController
if @project.project_type == 1 if @project.project_type == 1
render :layout => 'base_courses' render :layout => 'base_courses'
end end
# roles = Role.find_all_givable
# members = @project.member_principals.includes(:roles, :principal).all.sort
#
# users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]}
#
# temp = []
# users.each do |user|
# members.each do |member|
# if member[:user_id] == user[:user_id]
# temp << member
# end
# end
# end
# temps = temp.reverse
end end
# def news # def news
@ -790,7 +817,7 @@ class ProjectsController < ApplicationController
project_status = ProjectStatus.find_by_project_id(@project.id) project_status = ProjectStatus.find_by_project_id(@project.id)
project_status.destroy project_status.destroy
elsif params[:project][:is_public] == '1' elsif params[:project][:is_public] == '1'
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => 1) project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0,:grade => 0, :project_type => 1)
end end
respond_to do |format| respond_to do |format|

View File

@ -280,13 +280,13 @@ class UsersController < ApplicationController
when '1' when '1'
@offset ||= @user_pages.reverse_offset @offset ||= @user_pages.reverse_offset
unless @offset == 0 unless @offset == 0
@users_statuses = scope.reorder('changesets_count').offset(@offset).limit(@limit).all.reverse @users_statuses = scope.reorder('grade').offset(@offset).limit(@limit).all.reverse
else else
limit = @user_count % @limit limit = @user_count % @limit
if limit == 0 if limit == 0
limit = @limit limit = @limit
end end
@users_statuses = scope.reorder('changesets_count').offset(@offset).limit(limit).all.reverse @users_statuses = scope.reorder('grade').offset(@offset).limit(limit).all.reverse
end end
@s_type = 1 @s_type = 1
#sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count} #sort {|x,y| y.user_status.changesets_count <=> x.user_status.changesets_count}

View File

@ -254,12 +254,14 @@ module ApplicationHelper
s << "</span>" s << "</span>"
end end
if @project.project_type == 1 if @project.project_type == 1
unless Course.find_by_extra(@project.identifier).nil?
unless Course.find_by_extra(@project.identifier).tea_id == User.current.id unless Course.find_by_extra(@project.identifier).tea_id == User.current.id
s << "<span style = 'float: right;'>" s << "<span style = 'float: right;'>"
s << join_in_course(@project, User.current)#, ['whiteButton']) s << join_in_course(@project, User.current)#, ['whiteButton'])
s << "</span>" s << "</span>"
end end
end end
end
s << (render :partial => 'projects/project', :locals => {:project => project}).to_s s << (render :partial => 'projects/project', :locals => {:project => project}).to_s
s << "</div>\n" s << "</div>\n"
ancestors << project ancestors << project

View File

@ -70,6 +70,7 @@ class Project < ActiveRecord::Base
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy has_one :project_status, :class_name => "ProjectStatus", :dependent => :destroy
has_many :user_grades, :class_name => "UserGrade", :dependent => :destroy
#end #end
has_one :wiki, :dependent => :destroy has_one :wiki, :dependent => :destroy

4
app/models/user_grade.rb Normal file
View File

@ -0,0 +1,4 @@
class UserGrade < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :project
end

View File

@ -8,12 +8,14 @@
<td width="50px" valign="top" colspan="2" align="middle"> <td width="50px" valign="top" colspan="2" align="middle">
<div style="width: 50px; height: 50px;"> <div style="width: 50px; height: 50px;">
<%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %> <%= link_to image_tag(url_to_avatar(b_project.project), :class => 'avatar3'), :class => "avatar" %>
</div></td> </div></td>
<td width="65%" valign="top"> <td width="65%" valign="top">
<table width="100%" valign="top"> <table width="100%" valign="top">
<tr> <tr>
<td colspan="2" valign="top" width="50%"><strong> <td colspan="2" valign="top" width="50%"><strong>
<%= link_to(b_project.project.name, project_path(b_project.project)) %> <%= link_to(b_project.project.name, project_path(b_project.project)) %>
</strong><a class="font_lighter"><%= l(:label_join_bidding)%></a> </strong><a class="font_lighter"><%= l(:label_join_bidding)%></a>
</td> </td>
@ -21,7 +23,7 @@
<td style="color: red;" align="right" valign="0.1em" width="15%"> <td style="color: red;" align="right" valign="0.1em" width="15%">
<strong><span id="reward_result_<%=b_project.id%>"> <strong><span id="reward_result_<%=b_project.id%>">
<%= l(:label_system_grade) %>:<%= (b_project.project.project_status.grade.nil? ? 0 : b_project.project.project_status.grade) unless (b_project.project.project_status.nil? && b_project.project.nil?) %>
<% if get_prize(b_project).nil? or get_prize(b_project) == "" %> <% if get_prize(b_project).nil? or get_prize(b_project) == "" %>
<% if @bid.deadline < Date.today %> <% if @bid.deadline < Date.today %>
<%= l(:label_noawards)%> <%= l(:label_noawards)%>

View File

@ -87,18 +87,11 @@
<div class="licences"> <div class="licences">
<%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(@project.created_on)) %> <%= content_tag('span', "#{l(:label_create_time)}: ") %><%= content_tag('span', format_time(@project.created_on)) %>
</div> </div>
<div class="grade">
<%= content_tag('span', "#{l(:label_project_grade)}: ")%><span style='color:red'><%= @project.project_status.grade%></span>
</div>
<!-- added by liuping --> <!-- added by liuping -->
<!-- <% unless User.current.member_of?(@project) %>
<%= watcher_link(@project, User.current) %>
<% end %>
<span style="float: right; margin-right: 100px">
<% if @project.project_type == 1 %>
<% unless Course.find_by_extra(@project.identifier).tea_id == User.current.id %>
<%= join_in_course(@project, User.current)%>
<% end %>
<% end %> -->
</span> </span>

View File

@ -4,8 +4,20 @@
<%= error_messages_for 'member' %> <%= error_messages_for 'member' %>
<% roles = Role.find_all_givable <% roles = Role.find_all_givable
members = @project.member_principals.includes(:roles, :principal).all.sort %> members = @project.member_principals.includes(:roles, :principal).all.sort %>
<% if members.any? %> <%
users = UserGrade.find_by_sql("select * from user_grades where project_id = #{@project.id}").sort {|a,b| a[:grade] <=> b[:grade]}
%>
<% temp = [] %>
<% users.each do |user|%>
<% members.each do |member|%> <% members.each do |member|%>
<% if member[:user_id] == user[:user_id] %>
<% temp << member%>
<% end %>
<% end %>
<% end %>
<% temps = temp.reverse %>
<% if temps.any? %>
<% temps.each do |member| %>
<div class="well"> <div class="well">
<!--Modified by nie--> <!--Modified by nie-->
<% next if member.new_record? %> <% next if member.new_record? %>
@ -14,6 +26,7 @@
<% end %> <% end %>
<%= member.user.nil? ? '' : (link_to image_tag(url_to_avatar(member.user), :class => 'avatar'), :class => "avatar") %> <%= member.user.nil? ? '' : (link_to image_tag(url_to_avatar(member.user), :class => 'avatar'), :class => "avatar") %>
<%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %> <%= content_tag "div", link_to_user(member.principal), :class => "nomargin avatar_name" %>
<!-- added by huang modified by bai--> <!-- added by huang modified by bai-->
<% if @project.project_type == 1 %> <% if @project.project_type == 1 %>
<div class ="clear avatar_name"> <p> <div class ="clear avatar_name"> <p>
@ -26,9 +39,17 @@
<% else %> <% else %>
<% end %> <% end %>
</p></div> </p>
</div>
<% else%> <% else%>
<%= content_tag "div", content_tag("p", member.roles.sort.collect(&:to_s).join(', ')), :class => "clear avatar_name" %> <%= content_tag "div", content_tag("p", member.roles.sort.collect(&:to_s).join(', ')), :class => "clear avatar_name" %>
<% users.each do |user|%>
<% if user[:user_id] == member[:user_id]%>
<div class="clear avatar_user">
<p><%= l(:label_user_for_project_grade) %>: <span style="color:red"><%= user[:grade] %></span></p>
</div>
<% end %>
<% end %>
<% end %> <% end %>
<!-- end --> <!-- end -->
<%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %> <%= call_hook(:view_projects_settings_members_table_row, { :project => @project, :member => member}) %>
@ -41,3 +62,5 @@
</p> </p>
<% end %> <% end %>
</div> </div>

View File

@ -28,25 +28,13 @@
</div> </div>
<%end%> <%end%>
<!-- <div class="pagination_list">
<ul>
<li>
<%= link_to l(:label_sort_by_time), projects_path(:project_sort_type => '0'),:class=>"test_new" %>
</li>
<li>
<%= link_to l(:label_sort_by_active), projects_path(:project_sort_type => '1'),:class=>"test_new" %>
</li>
<li>
<%= link_to l(:label_sort_by_influence), projects_path(:project_sort_type => '2'),:class=>"test_new" %>
</li>
</ul>
</div> -->
<div id="projects-index"> <div id="projects-index">
<%= render_project_hierarchy(@projects)%> <%= render_project_hierarchy(@projects)%>
</div> </div>
<!-- <p class="pagination"><%= pagination_links_full @project_pages%></p> -->
<div class="pagination"> <div class="pagination">
<ul> <ul>
<%= pagination_links_full @project_pages %> <%= pagination_links_full @project_pages %>

View File

@ -117,10 +117,16 @@
<div> <div>
<%= link_to image_tag(url_to_avatar(user), :class => 'avatar'), user_path(user) %> <%= link_to image_tag(url_to_avatar(user), :class => 'avatar'), user_path(user) %>
<%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %> <%= content_tag "span", link_to_user(user), :class => "nomargin avatar_name" %>
<!-- <%= content_tag "div", "#{l(:label_user_grade)}:" %><%= user.user_status.grade %> -->
</div> </div>
<div style="margin-top: 20px;margin-left:66px"> <div style="margin-top: 20px;margin-left:66px">
<%= l(:label_x_has_fans,:count=>user.watcher_users.count)%> <%= l(:label_x_has_fans,:count=>user.watcher_users.count)%>
<%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %> <%= l(:label_has_watchers,:count=>User.watched_by(user.id).count) %>
</div>
<div style="position:relative;float:left;margin-top:-20px;margin-left: 724px">
<%= l(:label_user_grade) %>: <span style="color:red"><%= user.user_status.grade %></span>
</div> </div>
<div class="user-bottom"> <div class="user-bottom">
@ -139,7 +145,7 @@
<div class="pagination"> <div class="pagination">
<ul> <ul>
<%= pagination_links_full @user_pages, @user_count %> <%= pagination_links_full @user_pages, @user_count %>
<ul> </ul>
</div> </div>
<% html_title(l(:label_user_plural)) -%> <% html_title(l(:label_user_plural)) -%>
<% end -%> <% end -%>

View File

@ -1631,6 +1631,11 @@ zh:
role_of_course: 课程角色 role_of_course: 课程角色
label_student: 学生 label_student: 学生
label_project_grade: 项目得分
label_user_grade: 个人得分
label_user_for_project_grade: 个人得分
label_system_grade: 系统评分
label_teacher: 老师 label_teacher: 老师
label_ta: 助教 label_ta: 助教
label_in_course: 在课程中 label_in_course: 在课程中

View File

@ -4,19 +4,45 @@ class StoredStatusProcedure < ActiveRecord::Migration
execute " execute "
create procedure `sp_user_status_cursor`() create procedure `sp_user_status_cursor`()
begin begin
declare v_uid bigint(22); declare user_uid bigint(22);
declare v int(10); declare user_changesets_count int(10);
declare _done TINYINT(1) default 0; declare _done tinyint(1) default 0;
declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id; declare cur_user cursor for select user_id, count(*) from changesets where user_id != '' group by user_id;
declare continue handler for not found set _done = 1; declare continue handler for not found set _done = 1;
open cur_user; open cur_user;
loop_xxx:loop loop_xxx:loop
fetch cur_user into v_uid,v; fetch cur_user into user_uid,user_changesets_count;
if _done=1 then if _done=1 then
leave loop_xxx; leave loop_xxx;
end if; end if;
begin begin
update user_statuses set changesets_count = v where user_id = v_uid; declare journals_for_messages_count int(10);
declare journals_count int(10);
declare comments_count int(10);
declare messages_count int(10);
declare news_count int(10);
declare wiki_contents_count int(10);
declare activities_count int(10);
declare total_count numeric(8,2);
select count(*) into journals_for_messages_count from journals_for_messages where user_id = user_uid;
select count(*) into journals_count from journals where user_id = user_uid;
select count(*) into comments_count from comments where author_id = user_uid;
select count(*) into messages_count from messages where author_id = user_uid;
select count(*) into news_count from news where author_id = user_uid;
select count(*) into wiki_contents_count from wiki_contents where author_id = user_uid;
select count(*) into activities_count from activities where user_id = user_uid;
set total_count = journals_for_messages_count*0.05 +
journals_count*0.1 +
comments_count*0.1 +
messages_count*0.05 +
news_count*0.1 +
wiki_contents_count*0.1 +
activities_count*0.2 +
user_changesets_count*0.3;
update user_statuses set changesets_count = user_changesets_count, grade = total_count where user_id = user_uid;
commit; commit;
end; end;
end loop; end loop;
@ -24,34 +50,281 @@ end;
" "
execute " execute "
create event if not exists e_test create event if not exists e_test
on schedule every 1 day starts'2013_08_27 01:50:00' on schedule every 1 day starts'2013-08-27 01:50:00'
on completion preserve on completion preserve
do call `sp_user_status_cursor`(); do call `sp_user_status_cursor`();
" "
execute " execute "
create procedure `sp_project_status_cursor`() CREATE PROCEDURE `sp_project_status_cursor` ()
begin BEGIN
declare v_uid bigint(22); DECLARE project_uid bigint(22);
declare v int(10); DECLARE project_changesets_count int(10);
declare _done TINYINT(1) default 0; DECLARE _done tinyint(1) DEFAULT 0;
declare cur_user cursor for select project_id,count(*) from (select project_id,repositories.id from repositories inner join changesets where repositories.id = changesets.repository_id and project_id in (SELECT `projects`.id FROM `projects` WHERE (((projects.status <> 9) AND (projects.is_public = 1)))))t group by project_id;
declare continue handler for not found set _done = 1; DECLARE cur_project CURSOR FOR
open cur_user; SELECT
loop_xxx:loop project_id,
fetch cur_user into v_uid,v; COUNT(*)
if _done=1 then FROM (SELECT
leave loop_xxx; project_id,
end if; repositories.id
begin FROM repositories
update project_statuses set changesets_count = v where project_id = v_uid; INNER JOIN changesets
commit; WHERE repositories.id = changesets.repository_id
end; AND project_id IN (SELECT
end loop; projects.id
end; FROM projects
WHERE (((projects.status <> 9)
AND (projects.is_public = 1))))) t
GROUP BY project_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1;
OPEN cur_project;
loop_xxx:
LOOP
FETCH cur_project INTO project_uid, project_changesets_count;
IF _done = 1 THEN
LEAVE loop_xxx;
END IF;
BEGIN
DECLARE total_count numeric(8, 2);
DECLARE news_id int(10);
DECLARE issues_id int(10);
DECLARE issues_count int(10);
DECLARE news_count int(10);
DECLARE time_entries_count int(10);
DECLARE documents_count int(10);
DECLARE issues_jour_count_total int(10) DEFAULT 0;
DECLARE issues_jour_count int(10);
DECLARE news_jour_count_total int(10) DEFAULT 0;
DECLARE news_jour_count int(10);
DECLARE boards_messages_count int(10);
DECLARE cur_user_id int(10);
DECLARE cur_user_issues_journals_count int(10);
DECLARE cur_user_news_journals_count int(10);
DECLARE cur_user_issues_count int(10);
DECLARE cur_user_news_count int(10);
DECLARE cur_user_issues_id int(10);
DECLARE cur_user_news_id int(10);
DECLARE _inner_done_one tinyint(1) DEFAULT 0;
DECLARE cur_issues CURSOR FOR
SELECT
issues.id
FROM issues
WHERE project_id = project_uid;
DECLARE cur_news CURSOR FOR
SELECT
news.id
FROM news
WHERE project_id = project_uid;
DECLARE cur_user CURSOR FOR
SELECT
members.user_id
FROM members
INNER JOIN users
ON members.user_id = users.id
WHERE members.project_id = project_uid
AND (users.type = 'User' AND users.status = 1);
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_done_one = 1;
OPEN cur_issues;
loop_issues:
LOOP
FETCH cur_issues INTO issues_id;
IF _inner_done_one = 1 THEN
LEAVE loop_issues;
END IF;
BEGIN
SELECT
COUNT(*) INTO issues_jour_count
FROM `journals`
WHERE `journals`.`journalized_id` = issues_id AND `journals`.`journalized_type` = 'Issue';
SET issues_jour_count_total = issues_jour_count_total + issues_jour_count;
END;
END LOOP;
-- CLOSE cur_issues;
SET _inner_done_one = 0;
OPEN cur_news;
loop_news:
LOOP
FETCH cur_news INTO news_id;
IF _inner_done_one = 1 THEN
LEAVE loop_news;
END IF;
BEGIN
SELECT
COUNT(*) INTO news_jour_count
FROM `journals`
WHERE `journals`.`journalized_id` = news_id AND `journals`.`journalized_type` = 'News';
SET news_jour_count_total = news_jour_count_total + news_jour_count;
END;
END LOOP;
-- CLOSE cur_news;
SET _inner_done_one = 0;
OPEN cur_user;
loop_user:
LOOP
FETCH cur_user INTO cur_user_id;
IF _inner_done_one = 1 THEN
LEAVE loop_user;
END IF;
BEGIN
DECLARE total_cur_user_issues_journals_count int(10) DEFAULT 0;
DECLARE total_cur_user_news_journals_count int(10) DEFAULT 0;
DECLARE cur_user_changesets_count INT(10);
DECLARE user_total_count numeric(8, 2);
DECLARE _inner_inner_done tinyint(1) DEFAULT 0;
DECLARE cur_user_issues CURSOR FOR
SELECT
issues.id
FROM issues
WHERE project_id = project_uid AND author_id = cur_user_id;
DECLARE cur_user_news CURSOR FOR
SELECT
news.id
FROM news
WHERE project_id = project_uid AND author_id = cur_user_id;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET _inner_inner_done = 1;
OPEN cur_user_issues;
loop_user_issues:
LOOP
FETCH cur_issues INTO cur_user_issues_id;
IF _inner_inner_done = 1 THEN
LEAVE loop_user_issues;
END IF;
BEGIN
SELECT
COUNT(*) INTO cur_user_issues_journals_count
FROM journals
WHERE journalized_id = cur_user_issues_id AND user_id = cur_user_id
AND journalized_type = 'Issues';
SET total_cur_user_issues_journals_count = total_cur_user_issues_journals_count +
cur_user_issues_journals_count;
END;
END LOOP;
-- CLOSE cur_user_issues;
SET _inner_inner_done = 0;
OPEN cur_user_news;
loop_user_news:
LOOP
FETCH cur_user_news INTO cur_user_news_id;
IF _inner_inner_done = 1 THEN
LEAVE loop_user_news;
END IF;
BEGIN
SELECT
COUNT(*) INTO cur_user_news_journals_count
FROM journals
WHERE journalized_id = cur_user_news_id AND user_id = cur_user_id AND journalized_type = 'News';
SET total_cur_user_news_journals_count = total_cur_user_news_journals_count +
cur_user_news_journals_count;
END;
END LOOP;
SELECT
COUNT(*) INTO cur_user_issues_count
FROM issues
WHERE project_id = project_uid AND author_id = cur_user_id;
SELECT
COUNT(*) INTO cur_user_news_count
FROM news
WHERE project_id = project_uid AND author_id = cur_user_id;
SELECT
COUNT(*) INTO cur_user_changesets_count
FROM changesets
WHERE user_id = cur_user_id AND
repository_id IN (SELECT
id
FROM repositories
WHERE project_id = project_uid);
SET user_total_count = cur_user_issues_count*0.2 +
cur_user_news_count*0.2 +
total_cur_user_issues_journals_count*0.1 +
total_cur_user_news_journals_count*0.1 +
cur_user_changesets_count*0.4;
UPDATE user_grades
SET grade = user_total_count
WHERE user_id = cur_user_id AND project_id = project_uid;
COMMIT;
END;
END LOOP;
SELECT
COUNT(*) INTO issues_count
FROM issues
WHERE project_id = project_uid;
SELECT
COUNT(*) INTO news_count
FROM news
WHERE project_id = project_uid;
SELECT
COUNT(*) INTO documents_count
FROM documents
WHERE project_id = project_uid;
SELECT
SUM(boards.messages_count) INTO boards_messages_count
FROM boards
WHERE project_id = project_uid;
IF boards_messages_count IS NULL THEN
SET boards_messages_count = 0;
SET total_count = issues_count * 0.2 +
issues_jour_count_total * 0.1 +
news_count * 0.1 +
news_jour_count_total * 0.1 +
documents_count * 0.1 +
project_changesets_count * 0.3 +
boards_messages_count * 0.1;
ELSE
SET total_count = issues_count * 0.2 +
issues_jour_count_total * 0.1 +
news_count * 0.1 +
news_jour_count_total * 0.1 +
documents_count * 0.1 +
project_changesets_count * 0.3 +
boards_messages_count * 0.1;
END IF;
IF total_count IS NOT NULL THEN
UPDATE project_statuses
SET changesets_count = project_changesets_count,
grade = total_count
WHERE project_id = project_uid;
ELSE
UPDATE project_statuses
SET changesets_count = project_changesets_count,
grade = 0
WHERE project_id = project_uid;
END IF;
COMMIT;
END;
END LOOP;
END;
" "
execute " execute "
create event if not exists e_project_status_test create event if not exists e_project_status_test
on schedule every 1 day starts'2013_08_27 01:50:00' on schedule every 1 day starts'2013-08-27 01:50:00'
on completion preserve on completion preserve
do call `sp_project_status_cursor`(); do call `sp_project_status_cursor`();
" "

View File

@ -0,0 +1,5 @@
class AddGradeToProjectStatuses < ActiveRecord::Migration
def change
add_column :project_statuses, :grade, :float, :default => 0
end
end

View File

@ -0,0 +1,5 @@
class AddGradeToUserStatuses < ActiveRecord::Migration
def change
add_column :user_statuses, :grade, :float, :default => 0
end
end

View File

@ -0,0 +1,10 @@
class CreateUserGrades < ActiveRecord::Migration
def change
create_table :user_grades do |t|
t.integer :user_id, :null => false
t.integer :project_id, :null => false
t.float :grade, :default => 0
t.timestamps
end
end
end

View File

@ -0,0 +1,7 @@
class AddIndexToUserGrades < ActiveRecord::Migration
def change
add_index :user_grades, :grade
add_index :user_grades, :project_id
add_index :user_grades, :user_id
end
end

View File

@ -0,0 +1,5 @@
class AddMissingIndexToUserStatuses < ActiveRecord::Migration
def change
add_index :user_statuses, :grade
end
end

View File

@ -0,0 +1,5 @@
class AddMissingIndexToProjectStatuses < ActiveRecord::Migration
def change
add_index :project_statuses, :grade
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20131009074454) do ActiveRecord::Schema.define(:version => 20131017140123) do
create_table "a_user_watchers", :force => true do |t| create_table "a_user_watchers", :force => true do |t|
t.string "name" t.string "name"
@ -506,9 +506,12 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.integer "watchers_count" t.integer "watchers_count"
t.integer "project_id" t.integer "project_id"
t.integer "project_type" t.integer "project_type"
t.integer "gitlab_group_id", :limit => 8
t.float "grade"
end end
add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count" add_index "project_statuses", ["changesets_count"], :name => "index_project_statuses_on_changesets_count"
add_index "project_statuses", ["grade"], :name => "index_project_statuses_on_grade"
add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count" add_index "project_statuses", ["watchers_count"], :name => "index_project_statuses_on_watchers_count"
create_table "project_tags", :force => true do |t| create_table "project_tags", :force => true do |t|
@ -574,6 +577,7 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.text "extra_info" t.text "extra_info"
t.string "identifier" t.string "identifier"
t.boolean "is_default", :default => false t.boolean "is_default", :default => false
t.string "git_project_id"
end end
add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id" add_index "repositories", ["project_id"], :name => "index_repositories_on_project_id"
@ -703,8 +707,21 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.string "teacher_realname" t.string "teacher_realname"
t.string "student_realname" t.string "student_realname"
t.string "location_city" t.string "location_city"
t.string "git_token"
end end
create_table "user_grades", :force => true do |t|
t.integer "user_id", :null => false
t.integer "project_id", :null => false
t.float "grade", :default => 0.0
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "user_grades", ["grade"], :name => "index_user_grades_on_grade"
add_index "user_grades", ["project_id"], :name => "index_user_grades_on_project_id"
add_index "user_grades", ["user_id"], :name => "index_user_grades_on_user_id"
create_table "user_preferences", :force => true do |t| create_table "user_preferences", :force => true do |t|
t.integer "user_id", :default => 0, :null => false t.integer "user_id", :default => 0, :null => false
t.text "others" t.text "others"
@ -720,9 +737,11 @@ ActiveRecord::Schema.define(:version => 20131009074454) do
t.integer "user_id" t.integer "user_id"
t.datetime "created_at", :null => false t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false t.datetime "updated_at", :null => false
t.float "grade", :default => 0.0
end end
add_index "user_statuses", ["changesets_count"], :name => "index_user_statuses_on_changesets_count" add_index "user_statuses", ["changesets_count"], :name => "index_user_statuses_on_changesets_count"
add_index "user_statuses", ["grade"], :name => "index_user_statuses_on_grade"
add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count" add_index "user_statuses", ["watchers_count"], :name => "index_user_statuses_on_watchers_count"
create_table "user_tags", :force => true do |t| create_table "user_tags", :force => true do |t|

View File

@ -0,0 +1,68 @@
<div class="content_frame">
<% if @memberships.empty? %>
<% if @user != User.current %>
<p class="font_description">
<%= l(:label_project_course_un) %>
</p>
<% else %>
<p class="font_description">
<%= l(:label_project_course_unadd) %>
<% if User.current.user_extensions.identity == 0 %>
<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %>
<% end %>
</p>
<% end %>
<% else %>
<% if User.current.user_extensions.identity == 0 %>
<%= link_to"#{l(:label_course_new)}",{:controller=>'projects',:action=>'new', :course => 1}, :class => 'icon icon-add' %>
<% end %>
<ul class="user_project_sort">
<% for membership in @memberships %>
<li>
<table width="660" border="0" align="center" style="border-bottom: 1px dashed rgb(204, 204, 204); margin-bottom: 10px;font-size:14px;">
<tr>
<td colspan="2" valign="top" width="50" ><% if get_avatar?(membership.project)%>
<%= link_to image_tag(url_to_avatar(membership.project), :class => 'avatar'), project_path(membership.project) %>
<% else %>
<%= link_to image_tag('../images/avatars/Project/course.jpg', :class => "avatar"), project_path(membership.project)%>
<% end %></td>
<td>
<table width="580" border="0">
<tr>
<td colspan="2" valign="top"><span><%= link_to_project(membership.project) %></span>
<span style="float: right"><%= l(:label_homework) %> (<span class=""><%= link_to (membership.project.homeworks.count), {:controller => 'projects', :action => 'homework', :id => membership.project.identifier} %></span>)
&nbsp;&nbsp;&nbsp;
<%= l(:label_course_news)%> (<span style="color: #ed8924"><%= link_to (membership.project.news.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %></span>)
<!-- <%= l(:label_member)%>(<span style="color: #ed8924"><%= link_to (membership.project.members.count), {:controller => 'news', :action => 'index', :project_id => membership.project.identifier} %></span>) </span> --></td>
</tr>
<tr>
<td colspan="2" width="580" >
<p class="font_description">
<%= membership.project.description%>
</p></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= format_time(membership.created_on) %></span></td><!-- modified by ming -->
<td align="right" >
<% if membership.roles.sort.collect(&:to_s).join(', ') =='Manager' %>
Teacher
<% elsif membership.roles.sort.collect(&:to_s).join(', ') =='Reporter' %>
Student
<% elsif membership.roles.sort.collect(&:to_s).join(', ') =='TA' %>
TA
<% end %>
</td>
</tr>
</table></td>
</tr>
</table>
</li>
<% end %>
</ul>
<% end %>
<%= call_hook :view_account_left_bottom, :user => @user %>
</div>

View File

@ -1877,9 +1877,13 @@ a.font-user-after-color{
height:25px; height:25px;
line-height:23px; line-height:23px;
} }
/*end*/
.create-share{ div.avatar_user{
position: relative;
float:left;
margin-top:-30px;
margin-left: 550px;
}.create-share{
border-radius: 5px; border-radius: 5px;
padding-top: 3px; padding-top: 3px;
margin-top: 5px; margin-top: 5px;