From 6baa87a8ea9921e77a8d910010ad5ac777d8d76b Mon Sep 17 00:00:00 2001 From: nieguanghui Date: Fri, 11 Apr 2014 10:53:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A1=B9=E7=9B=AE=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=88=86=E6=95=B0=E6=98=BE=E7=A4=BA=E4=B8=8D=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E4=BD=9C=E4=B8=9A=E4=B8=AD=E9=A1=B9=E7=9B=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=88=86=E6=95=B0=E5=92=8C=E9=A1=B9=E7=9B=AE=E5=86=85?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=95=B0=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 1 + app/views/layouts/base_users.html.erb | 2 +- .../users/_activity_score_index.html.erb | 4 ++-- app/views/users/_score_index.html.erb | 2 +- app/views/users/_show_score.html.erb | 2 +- app/views/users/_user_show.html.erb | 2 +- .../20130828004955_stored_status_procedure.rb | 22 +++++++++++-------- 7 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 674e774d0..b9d752eb6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -82,6 +82,7 @@ class User < Principal #####fq has_many :jours, :class_name => 'JournalsForMessage', :dependent => :destroy + has_many :journals_messages, :class_name => 'JournalsForMessage', :foreign_key => "user_id", :dependent => :destroy has_many :bids, :foreign_key => 'author_id', :dependent => :destroy has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :new_jours, :as => :jour, :class_name => 'JournalsForMessage', :conditions => "status=1" diff --git a/app/views/layouts/base_users.html.erb b/app/views/layouts/base_users.html.erb index 232103273..2063528cc 100644 --- a/app/views/layouts/base_users.html.erb +++ b/app/views/layouts/base_users.html.erb @@ -78,7 +78,7 @@ <% user_changesets_score = user_changesets_count * 0.3 %> <% finall_user_project_score = journals_score + user_changesets_score %> - <% journals_for_messages_count = @user.journals_for_messages.count %> + <% journals_for_messages_count = @user.journals_messages.count %> <% activities_count = @user.activities.count %> <% journals_for_messages_score = journals_for_messages_count * 0.05 %> <% activities_score = activities_count * 0.2 %> diff --git a/app/views/users/_activity_score_index.html.erb b/app/views/users/_activity_score_index.html.erb index fd1947812..fa9aad180 100644 --- a/app/views/users/_activity_score_index.html.erb +++ b/app/views/users/_activity_score_index.html.erb @@ -1,10 +1,10 @@ -<% journals_for_messages_count = @user.journals_for_messages.count %> +<% journals_for_messages_count = @user.journals_messages.count %> <% journals_for_messages_score = journals_for_messages_count * 0.05 %> <% activities_count = @user.activities.count %> <% activities_score = activities_count * 0.2 %> <% finall_activity_score = journals_for_messages_score + activities_score %> -
<%= l(:label_message_number) %> * 0.05 = <%= @user.journals_for_messages.count %> * 0.05 = <%= format("%.2f" , journals_for_messages_score).to_f %>
+
<%= l(:label_message_number) %> * 0.05 = <%= @user.journals_messages.count %> * 0.05 = <%= format("%.2f" , journals_for_messages_score).to_f %>
<%= l(:label_activity_number) %> * 0.2 = <%= @user.activities.count %> * 0.2 = <%= format("%.2f" , activities_score).to_f %>
<%= l(:label_user_score_of_activity) %> = <%= format("%.2f" , journals_for_messages_score).to_f %> + <%= format("%.2f" , activities_score).to_f %> = <%= format("%.2f" , finall_activity_score).to_f %>
diff --git a/app/views/users/_score_index.html.erb b/app/views/users/_score_index.html.erb index 8c2f98541..814e9d9ec 100644 --- a/app/views/users/_score_index.html.erb +++ b/app/views/users/_score_index.html.erb @@ -9,7 +9,7 @@ <% user_changesets_score = user_changesets_count * 0.3 %> <% finall_user_project_score = journals_score + user_changesets_score %> -<% journals_for_messages_count = @user.journals_for_messages.count %> +<% journals_for_messages_count = @user.journals_messages.count %> <% activities_count = @user.activities.count %> <% journals_for_messages_score = journals_for_messages_count * 0.05 %> <% activities_score = activities_count * 0.2 %> diff --git a/app/views/users/_show_score.html.erb b/app/views/users/_show_score.html.erb index 7001f7a94..0297a4e02 100644 --- a/app/views/users/_show_score.html.erb +++ b/app/views/users/_show_score.html.erb @@ -11,7 +11,7 @@ <% user_changesets_score = user_changesets_count * 0.3 %> <% finall_user_project_score = journals_score + user_changesets_score %> -<% journals_for_messages_count = @user.journals_for_messages.count %> +<% journals_for_messages_count = @user.journals_messages.count %> <% activities_count = @user.activities.count %> <% journals_for_messages_score = journals_for_messages_count * 0.05 %> <% activities_score = activities_count * 0.2 %> diff --git a/app/views/users/_user_show.html.erb b/app/views/users/_user_show.html.erb index 71157d070..905265c8b 100644 --- a/app/views/users/_user_show.html.erb +++ b/app/views/users/_user_show.html.erb @@ -13,7 +13,7 @@ <% user_changesets_score = user_changesets_count * 0.3 %> <% finall_user_project_score = journals_score + user_changesets_score %> - <% journals_for_messages_count = user.journals_for_messages.count %> + <% journals_for_messages_count = user.journals_messages.count %> <% activities_count = user.activities.count %> <% journals_for_messages_score = journals_for_messages_count * 0.05 %> <% activities_score = activities_count * 0.2 %> diff --git a/db/migrate/20130828004955_stored_status_procedure.rb b/db/migrate/20130828004955_stored_status_procedure.rb index 884c47bba..248fc488c 100644 --- a/db/migrate/20130828004955_stored_status_procedure.rb +++ b/db/migrate/20130828004955_stored_status_procedure.rb @@ -8,17 +8,15 @@ BEGIN DECLARE user_changesets_count int(10); DECLARE _done tinyint(1) DEFAULT 0; DECLARE cur_user CURSOR FOR - SELECT - user_id, - COUNT(*) - FROM changesets - WHERE user_id != '' - GROUP BY user_id; + SELECT + users.id + FROM users + WHERE users.type = 'User' AND users.status = 1 AND users.admin = 0; DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; OPEN cur_user; loop_xxx: LOOP - FETCH cur_user INTO user_uid, user_changesets_count; + FETCH cur_user INTO user_uid ; IF _done = 1 THEN LEAVE loop_xxx; END IF; @@ -35,7 +33,7 @@ LOOP SELECT COUNT(*) INTO journals_for_messages_count FROM journals_for_messages - WHERE user_id = user_uid; + WHERE user_id = user_uid ; SELECT COUNT(*) INTO journals_count FROM journals @@ -60,6 +58,12 @@ LOOP COUNT(*) INTO activities_count FROM activities WHERE user_id = user_uid; + SELECT + COUNT(*) INTO user_changesets_count + FROM changesets + WHERE changesets.user_id = user_uid; + + SET total_count = journals_for_messages_count * 0.05 + journals_count * 0.1 + @@ -97,7 +101,7 @@ BEGIN projects.id FROM projects WHERE projects.status <> 9 - AND projects.is_public = 1 ; + AND projects.is_public = 1 AND projects.project_type = 0 ; DECLARE CONTINUE HANDLER FOR NOT FOUND SET _done = 1; OPEN cur_project;