后台统计所有用户分数算法优化
This commit is contained in:
parent
1e234a9adf
commit
5482ba3207
|
@ -381,6 +381,46 @@ module UserScoreHelper
|
|||
result
|
||||
end
|
||||
|
||||
def get_option_num_by_id(user_id,type,project_id=nil)
|
||||
if project_id.nil?
|
||||
option_number = OptionNumber.where("user_id = '#{user_id}' and score_type = '#{type}'");
|
||||
else
|
||||
option_number = OptionNumber.where("user_id = '#{user_id}' and score_type = '#{type}' and project_id = '#{project_id}'");
|
||||
end
|
||||
|
||||
result = nil
|
||||
if option_number.nil? || option_number.count == 0
|
||||
result = OptionNumber.new
|
||||
result.user_id = user_id
|
||||
result.memo = 0
|
||||
result.messages_for_issues = 0
|
||||
result.issues_status = 0
|
||||
result.replay_for_message = 0
|
||||
result.replay_for_memo = 0
|
||||
result.follow = 0
|
||||
result.tread = 0
|
||||
result.praise_by_one = 0
|
||||
result.praise_by_two = 0
|
||||
result.praise_by_three = 0
|
||||
result.tread_by_one = 0
|
||||
result.tread_by_two = 0
|
||||
result.tread_by_three = 0
|
||||
result.changeset = 0
|
||||
result.document = 0
|
||||
result.attachment = 0
|
||||
result.issue_done_ratio = 0
|
||||
result.post_issue = 0
|
||||
result.total_score = 0
|
||||
result.score_type =type
|
||||
unless project_id.nil?
|
||||
result.project_id = project_id
|
||||
end
|
||||
else
|
||||
result = option_number.first
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
#更新分数
|
||||
def update_score(option_number)
|
||||
option_number.total_score = collaboration(option_number) + influence(option_number) + skill(option_number) + active(option_number)
|
||||
|
@ -419,9 +459,8 @@ module UserScoreHelper
|
|||
def memo_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count #+ Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count
|
||||
users = User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id
|
||||
WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
|
||||
FROM `users` where id = #{user.id}")
|
||||
users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id
|
||||
WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
|
||||
result = 0
|
||||
users.each do |user|
|
||||
result = user.m_count
|
||||
|
@ -430,9 +469,8 @@ FROM `users` where id = #{user.id}")
|
|||
#user.messages.where("parent_id IS NULL").count
|
||||
else
|
||||
#Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count
|
||||
users = User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id
|
||||
WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
|
||||
FROM `users` where id = #{user.id}")
|
||||
users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id
|
||||
WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
|
||||
result = 0
|
||||
users.each do |user|
|
||||
result = user.m_count
|
||||
|
@ -464,7 +502,7 @@ FROM `users` where id = #{user.id}")
|
|||
def messges_for_issue_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Journal.includes(:user).where("user_id = '#{user.id}' and notes is not null and notes != ''").all.count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != '') AS m_count FROM users where id = #{user.id}")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -472,7 +510,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Journal.includes(:user).joins(:issue).where("#{Journal.table_name}.user_id = '#{user.id}' and #{Issue.table_name}.project_id = '#{project.id}' and #{Journal.table_name}.notes != '' and #{Journal.table_name}.notes is not null").all.count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = users.id AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}') AS m_count FROM users where id = #{user.id}")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals join issues on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.user_id = #{user.id} AND journals.notes IS NOT NULL AND journals.notes != ''and #{Issue.table_name}.project_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -499,7 +537,7 @@ FROM `users` where id = #{user.id}")
|
|||
def issues_status_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id) AS m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' and journals.user_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -507,7 +545,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count
|
||||
User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = users.id and issues.project_id = '#{project.id}') AS m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' and journals.user_id = #{user.id} and issues.project_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -537,7 +575,7 @@ FROM `users` where id = #{user.id}")
|
|||
def replay_for_message_num(user,project=nil)
|
||||
if project.nil?
|
||||
#JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project'").count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project') as m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = JournalsForMessage.find_by_sql("SELECT COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -545,7 +583,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project' and jour_id = '#{project.id}'").count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) From journals_for_messages WHERE m_parent_id IS NOT NULL and user_id = users.id and jour_type = 'Project' and jour_id = '#{project.id}') as m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = JournalsForMessage.find_by_sql("SELECT COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and user_id = #{user.id} and jour_type = 'Project' and jour_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -573,7 +611,7 @@ FROM `users` where id = #{user.id}")
|
|||
def replay_for_memo_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id != -1").all.count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = users.id AND boards.project_id != -1) as m_count FROM users WHERE users.id = #{user.id}")
|
||||
users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = #{user.id} AND boards.project_id != -1")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -581,7 +619,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Message.includes(:author).joins(:board).where("#{Message.table_name}.parent_id IS NOT NULL and #{Message.table_name}.author_id = '#{user.id}' and #{Board.table_name}.project_id = #{project.id}").all.count
|
||||
users = User.find_by_sql("SELECT users.id,(SELECT COUNT(*) FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = users.id AND boards.project_id = #{project.id}) FROM users WHERE users.id = #{user.id}")
|
||||
users = Message.find_by_sql("SELECT COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND messages.author_id = #{user.id} AND boards.project_id = #{project.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -607,11 +645,12 @@ FROM `users` where id = #{user.id}")
|
|||
|
||||
def follow_num(user)
|
||||
#Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count
|
||||
users = User.find_by_sql("SELECT users.id, (SELECT COUNT(*) FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = users.id) as m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = Watcher.find_by_sql("SELECT COUNT(*) as m_count FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' and watchable_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
def follow_score(user)
|
||||
|
@ -758,7 +797,7 @@ FROM `users` where id = #{user.id}")
|
|||
def changeset_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Changeset.includes(:user).where("user_id = '#{user.id}'").all.count
|
||||
users = User.find_by_sql("SELECT users.id, (SELECT COUNT(*) FROM #{Changeset.table_name} WHERE user_id = users.id) as m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = Changeset.find_by_sql("SELECT COUNT(*) as m_count FROM #{Changeset.table_name} WHERE user_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -766,7 +805,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Changeset.includes(:user).joins(:repository).where("#{Changeset.table_name}.user_id = '#{user.id}' and #{Repository.table_name}.project_id = #{project.id}").all.count
|
||||
users = User.find_by_sql("SELECT users.id, (SELECT COUNT(*) FROM #{Changeset.table_name} JOIN #{Repository.table_name} ON #{Changeset.table_name}.repository_id = #{Repository.table_name}.id WHERE #{Changeset.table_name}.user_id = users.id and #{Repository.table_name}.project_id = #{project.id}) as m_count FROM users WHERE users.id = '#{user.id}'")
|
||||
users = Changeset.find_by_sql("SELECT COUNT(*) as m_count FROM #{Changeset.table_name} JOIN #{Repository.table_name} ON #{Changeset.table_name}.repository_id = #{Repository.table_name}.id WHERE #{Changeset.table_name}.user_id = #{user.id} and #{Repository.table_name}.project_id = #{project.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -786,7 +825,7 @@ FROM `users` where id = #{user.id}")
|
|||
def document_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Document.includes(:user).where("user_id = '#{user.id}'").all.count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{User.table_name}.id) as m_count FROM #{User.table_name} where #{User.table_name}.id = #{user.id}")
|
||||
users = Document.find_by_sql("SELECT COUNT(*) as m_count FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -794,7 +833,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Document.includes(:user,:project).where("user_id = '#{user.id}' and project_id = '#{project.id}'").all.count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{User.table_name}.id and #{Document.table_name}.project_id = '#{project.id}') as m_count FROM #{User.table_name} where #{User.table_name}.id = #{user.id}")
|
||||
users = Document.find_by_sql("SELECT COUNT(*) as m_count FROM #{Document.table_name} WHERE #{Document.table_name}.user_id = #{user.id} and #{Document.table_name}.project_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -814,7 +853,7 @@ FROM `users` where id = #{user.id}")
|
|||
def attachment_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project'").all.count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project') as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Attachment.find_by_sql("SELECT COUNT(*) as m_count FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -822,7 +861,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Attachment.includes(:author,:container).where("author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}").all.count
|
||||
User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}) as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Attachment.find_by_sql("SELECT COUNT(*) as m_count FROM #{Attachment.table_name} WHERE author_id = '#{user.id}' and container_type = 'Project' and container_id = #{project.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_coumt
|
||||
|
@ -841,7 +880,7 @@ FROM `users` where id = #{user.id}")
|
|||
def issue_done_ratio_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{User.table_name}.id) as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -849,7 +888,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Journal.joins(:issue,:details,:user).where("#{Issue.table_name}.project_id = '#{project.id}' and #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{User.table_name}.id and #{Issue.table_name}.project_id = '#{project.id}') as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Journal.find_by_sql("SELECT COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' and #{Journal.table_name}.user_id = #{user.id} and #{Issue.table_name}.project_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -869,7 +908,7 @@ FROM `users` where id = #{user.id}")
|
|||
def post_issue_num(user,project=nil)
|
||||
if project.nil?
|
||||
#Issue.includes(:author).where("author_id = '#{user.id}'").all.count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Issue.table_name} WHERE author_id = #{User.table_name}.id ) as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Issue.find_by_sql("SELECT COUNT(*) as m_count FROM #{Issue.table_name} WHERE author_id = #{user.id}")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
@ -877,7 +916,7 @@ FROM `users` where id = #{user.id}")
|
|||
result
|
||||
else
|
||||
#Issue.includes(:author).where("author_id = '#{user.id}' and project_id = '#{project.id}'").all.count
|
||||
users = User.find_by_sql("SELECT #{User.table_name}.id,(SELECT COUNT(*) FROM #{Issue.table_name} WHERE author_id = #{User.table_name}.id and project_id = '#{project.id}' ) as m_count FROM #{User.table_name} WHERE #{User.table_name}.id = #{user.id}")
|
||||
users = Issue.find_by_sql("SELECT COUNT(*) as m_count FROM #{Issue.table_name} WHERE author_id = #{user.id} and project_id = '#{project.id}'")
|
||||
result = 0
|
||||
if users.count > 0
|
||||
result = users.first.m_count
|
||||
|
|
|
@ -5,16 +5,16 @@ end
|
|||
|
||||
namespace :user_new_score do
|
||||
desc "calculating user score"
|
||||
task :calculate => :environment do
|
||||
task :calculating => :environment do
|
||||
include UserScoreHelper
|
||||
User.all.each do |user|
|
||||
result = user_scores(user,1)
|
||||
result = user_scores(user,1).total_score
|
||||
puts "score of #{user.login} is #{result}"
|
||||
end
|
||||
|
||||
Project.where("project_type != 1").all.each do |project|
|
||||
project.member_principals.includes(:roles, :principal).all.each do |member|
|
||||
result = user_scores(member.user,2,project)
|
||||
result = user_scores(member.user,2,project).total_score
|
||||
puts "#{user.login}/'s score in #{project.name} is #{result}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,453 @@
|
|||
desc "User Score description"
|
||||
task :user_score_new do
|
||||
puts "user_score sync."
|
||||
end
|
||||
|
||||
namespace :user_score_new do
|
||||
desc "calculating user score"
|
||||
task :calculated => :environment do
|
||||
include UserScoreHelper
|
||||
puts "truncating table...#{Rails.env}"
|
||||
puts "loading..."
|
||||
# collaboration 协同得分
|
||||
users = {}
|
||||
grades = {}
|
||||
# 发帖
|
||||
Message.find_by_sql("SELECT `messages`.author_id AS u_id,`boards`.project_id AS p_id, COUNT(*) AS memo_number FROM `messages` JOIN `boards` ON `messages`.board_id = `boards`.id WHERE `messages`.parent_id IS NULL AND `boards`.project_id != -1 GROUP BY `messages`.author_id,`boards`.project_id ").each do|message|
|
||||
option_num = get_option_num_by_id(message.u_id,2,message.p_id)
|
||||
option_num.memo = message.memo_number
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{message.u_id}'s memo number in project #{message.p_id}: #{message.memo_number}"
|
||||
end
|
||||
|
||||
Message.find_by_sql("SELECT `messages`.author_id AS u_id, COUNT(*) AS memo_number FROM `messages` JOIN `boards` ON `messages`.board_id = `boards`.id WHERE `messages`.parent_id IS NULL AND `boards`.project_id != -1 GROUP BY `messages`.author_id").each do|message|
|
||||
option_num = get_option_num_by_id(message.u_id,1)
|
||||
option_num.memo = message.memo_number
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{message.u_id}'s memo number: #{message.memo_number}"
|
||||
end
|
||||
|
||||
|
||||
puts "post_message calculate Completed."
|
||||
#
|
||||
## 对缺陷的留言
|
||||
Journal.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM journals WHERE journals.notes IS NOT NULL AND journals.notes != '' GROUP BY u_id").each do |journal|
|
||||
option_num = get_option_num_by_id(journal.u_id,1)
|
||||
option_num.messages_for_issues = journal.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{journal.u_id}'s messages_for_issues number: #{journal.m_count}"
|
||||
end
|
||||
|
||||
Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, #{Issue.table_name}.project_id AS p_id ,COUNT(*) as m_count FROM journals join #{Issue.table_name} on #{Journal.table_name}.journalized_type = 'Issue' and #{Journal.table_name}.journalized_id = #{Issue.table_name}.id WHERE journals.notes IS NOT NULL AND journals.notes != '' GROUP BY u_id,p_id").each do |journal|
|
||||
option_num = get_option_num_by_id(journal.u_id,2,journal.p_id)
|
||||
option_num.messages_for_issues = journal.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{journal.u_id}'s messages_for_issues number in project #{journal.p_id}: #{journal.m_count}"
|
||||
end
|
||||
|
||||
puts ":post_issue_message calculate Completed"
|
||||
#
|
||||
## 更改一次缺陷状态
|
||||
Journal.find_by_sql("SELECT journals.user_id AS u_id, COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id WHERE journal_details.prop_key = 'status_id' GROUP BY u_id").each do |journal|
|
||||
option_num = get_option_num_by_id(journal.u_id,1)
|
||||
option_num.issues_status = journal.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{journal.u_id}'s issues_status number: #{journal.m_count}"
|
||||
end
|
||||
|
||||
Journal.find_by_sql("SELECT journals.user_id AS u_id,issues.project_id AS p_id,COUNT(*) as m_count FROM journals JOIN journal_details on journals.id = journal_details.journal_id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE journal_details.prop_key = 'status_id' GROUP BY u_id,p_id").each do |journal|
|
||||
option_num = get_option_num_by_id(journal.u_id,2,journal.p_id)
|
||||
option_num.issues_status = journal.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{journal.u_id}'s issues_status number in project #{journal.p_id}: #{journal.m_count}"
|
||||
end
|
||||
|
||||
puts ":change_issue_status calculate Completed"
|
||||
#
|
||||
## 对留言的回复
|
||||
JournalsForMessage.find_by_sql("SELECT user_id AS u_id,COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and jour_type = 'Project' GROUP BY u_id").each do |jfm|
|
||||
option_num = get_option_num_by_id(jfm.u_id,1)
|
||||
option_num.replay_for_message = jfm.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{jfm.u_id}'s replay_for_message number: #{jfm.m_count}"
|
||||
end
|
||||
|
||||
JournalsForMessage.find_by_sql("SELECT user_id AS u_id,jour_id AS p_id,COUNT(*) as m_count From #{JournalsForMessage.table_name} WHERE m_parent_id IS NOT NULL and jour_type = 'Project' GROUP BY u_id,p_id").each do |jfm|
|
||||
option_num = get_option_num_by_id(jfm.u_id,2,jfm.p_id)
|
||||
option_num.replay_for_message = jfm.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{jfm.u_id}'s replay_for_message number in project #{jfm.p_id}: #{jfm.m_count}"
|
||||
end
|
||||
|
||||
puts ":reply_message calculate Completed"
|
||||
#
|
||||
## 对帖子的回复
|
||||
Message.find_by_sql("SELECT messages.author_id AS u_id, COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND boards.project_id != -1 GROUP BY u_id").each do |message|
|
||||
option_num = get_option_num_by_id(message.u_id,1)
|
||||
option_num.replay_for_memo = message.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{message.u_id}'s replay_for_memo number: #{message.m_count}"
|
||||
end
|
||||
|
||||
Message.find_by_sql("SELECT messages.author_id AS u_id,boards.project_id AS p_id,COUNT(*) as m_count FROM messages JOIN boards on messages.board_id = boards.id WHERE messages.parent_id IS NOT NULL AND boards.project_id != -1 GROUP BY u_id,p_id").each do |message|
|
||||
option_num = get_option_num_by_id(message.u_id,2,message.p_id)
|
||||
option_num.replay_for_memo = message.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{message.u_id}'s replay_for_memo number in project #{message.p_id}: #{message.m_count}"
|
||||
end
|
||||
|
||||
puts ":reply_posting calculate Completed."
|
||||
#
|
||||
#UserScore.transaction do
|
||||
# users.each do |user_id, score|
|
||||
# UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
|
||||
# end
|
||||
#end
|
||||
#puts "=== UserScore#collaboration calculate Completed. collaboration users count: #{users.count}"
|
||||
#puts ""
|
||||
#
|
||||
#users.clear
|
||||
#
|
||||
## influence 影响力得分
|
||||
##关注
|
||||
Watcher.find_by_sql("SELECT watchable_id AS u_id ,COUNT(*) as m_count FROM #{Watcher.table_name} WHERE watchable_type = 'Principal' GROUP BY u_id").each do |watcher|
|
||||
option_num = get_option_num_by_id(watcher.u_id,1)
|
||||
option_num.follow = watcher.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{watcher.u_id}'s follow number: #{watcher.m_count}"
|
||||
end
|
||||
puts ":followed_by calculate Completed."
|
||||
#
|
||||
#UserScore.transaction do
|
||||
# users_influence.each do |user_id, score|
|
||||
# UserScore.find_or_create_by_user_id(user_id).update_attribute(:influence, score)
|
||||
# end
|
||||
#end
|
||||
#puts "=== UserScore#influence calculate Completed. influence users count: #{users_influence.count}"
|
||||
#puts ""
|
||||
## skill 技术得分
|
||||
|
||||
#计算相关user的等级
|
||||
PraiseTread.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM `praise_treads` WHERE praise_tread_object_type IN ( 'Issue','Message') GROUP BY u_id").each do |pt|
|
||||
user = User.find(pt.u_id)
|
||||
level = UserLevels.get_level(user)
|
||||
puts "user #{user.login}'s level is #{level}"
|
||||
end
|
||||
## 踩帖
|
||||
PraiseTread.find_by_sql("SELECT user_id AS u_id,COUNT(*) AS m_count FROM `praise_treads` WHERE praise_tread_object_type IN ( 'Issue','Message') AND praise_or_tread = 0 GROUP BY u_id").each do |pt|
|
||||
#踩别人扣分
|
||||
option_num = get_option_num_by_id(pt.u_id,1)
|
||||
option_num.tread = pt.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{pt.u_id}'s tread number: #{pt.m_count}"
|
||||
end
|
||||
|
||||
|
||||
#SELECT AS u_id,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id = `praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id
|
||||
PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,u_level").each do |pt|
|
||||
#缺陷被人踩的次数
|
||||
option_num = get_option_num_by_id(pt.target_u_id,1)
|
||||
if pt.u_level == 1
|
||||
option_num.tread_by_one = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by one-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.tread_by_two = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by two-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.tread_by_three = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by three-level member #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
PraiseTread.find_by_sql("SELECT `praise_treads`.user_id AS u_id,`issues`.project_id AS p_id, COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id,p_id").each do |pt|
|
||||
#项目中踩别人缺陷的次数
|
||||
option_num = get_option_num_by_id(pt.u_id,2,pt.p_id)
|
||||
option_num.tread = pt.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{pt.u_id}'s tread number: #{pt.m_count}"
|
||||
end
|
||||
|
||||
#项目中被人踩缺陷的次数
|
||||
PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`issues`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,p_id,u_level").each do |pt|
|
||||
option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id)
|
||||
if pt.u_level == 1
|
||||
option_num.tread_by_one = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by one-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.tread_by_two = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by two-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.tread_by_three = pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by three-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 0 GROUP BY target_u_id,u_level").each do |pt|
|
||||
#讨论区被人踩的次数
|
||||
option_num = get_option_num_by_id(pt.target_u_id,1)
|
||||
if pt.u_level == 1
|
||||
option_num.tread_by_one += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by one-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.tread_by_two += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by two-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.tread_by_three += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by three-level member #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
PraiseTread.find_by_sql("SELECT `praise_treads`.user_id AS u_id,`boards`.project_id AS p_id, COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 0 GROUP BY u_id , p_id").each do |pt|
|
||||
#项目讨论区中踩别人的次数
|
||||
option_num = get_option_num_by_id(pt.u_id,2,pt.p_id)
|
||||
option_num.tread += pt.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{pt.u_id}'s tread number: #{pt.m_count}"
|
||||
end
|
||||
|
||||
#项目中被人踩的次数
|
||||
PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`boards`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 0 GROUP BY target_u_id,p_id,u_level").each do |pt|
|
||||
option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id)
|
||||
if pt.u_level == 1
|
||||
option_num.tread_by_one += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by one-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.tread_by_two += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by two-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.tread_by_three += pt.m_count
|
||||
puts "user #{pt.target_u_id} tread by three-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
#顶贴
|
||||
#SELECT AS u_id,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id = `praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' WHERE praise_or_tread = 0 GROUP BY u_id
|
||||
PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,u_level").each do |pt|
|
||||
#缺陷被人顶的次数
|
||||
option_num = get_option_num_by_id(pt.target_u_id,1)
|
||||
if pt.u_level == 1
|
||||
option_num.praise_by_one = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by one-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.praise_by_two = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by two-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.praise_by_three = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by three-level member #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
#项目中被人顶缺陷的次数
|
||||
PraiseTread.find_by_sql("SELECT `issues`.author_id AS target_u_id,`issues`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN issues ON `issues`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Issue' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,p_id,u_level").each do |pt|
|
||||
option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id)
|
||||
if pt.u_level == 1
|
||||
option_num.praise_by_one = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by one-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.praise_by_two = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by two-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.praise_by_three = pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by three-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id WHERE praise_or_tread = 1 GROUP BY target_u_id,u_level").each do |pt|
|
||||
#讨论区被人顶的次数
|
||||
option_num = get_option_num_by_id(pt.target_u_id,1)
|
||||
if pt.u_level == 1
|
||||
option_num.praise_by_one += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by one-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.praise_by_two += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by two-level member #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.praise_by_three += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by three-level member #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
#项目中被人踩的次数
|
||||
PraiseTread.find_by_sql("SELECT `messages`.author_id AS target_u_id,`boards`.project_id AS p_id,`user_levels`.level AS u_level,COUNT(*) AS m_count FROM `praise_treads` JOIN messages ON `messages`.id =`praise_treads`.praise_tread_object_id AND `praise_treads`.praise_tread_object_type = 'Message' JOIN `user_levels` ON `praise_treads`.user_id = `user_levels`.user_id JOIN `boards` ON `boards`.id = `messages`.board_id AND `boards`.project_id != '-1' WHERE praise_or_tread = 1 GROUP BY target_u_id,p_id,u_level").each do |pt|
|
||||
option_num = get_option_num_by_id(pt.target_u_id,2,pt.p_id)
|
||||
if pt.u_level == 1
|
||||
option_num.praise_by_one += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by one-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 2
|
||||
option_num.praise_by_two += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by two-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
elsif pt.u_level == 3
|
||||
option_num.praise_by_three += pt.m_count
|
||||
puts "user #{pt.target_u_id} praise by three-level member in project #{pt.p_id} #{pt.m_count} times "
|
||||
else
|
||||
puts "level error!:#{pt.u_level}"
|
||||
next
|
||||
end
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
end
|
||||
|
||||
puts "UserScore#skill calculate Completed."
|
||||
#puts ""
|
||||
#
|
||||
## active 项目贡献得分
|
||||
## 提交代码
|
||||
Changeset.find_by_sql("SELECT user_id AS u_id, COUNT(*) AS m_count FROM `changesets` GROUP BY u_id").each do |changeset|
|
||||
unless changeset.u_id.nil?
|
||||
option_num = get_option_num_by_id(changeset.u_id,1)
|
||||
option_num.changeset = changeset.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{changeset.u_id}'s changeset number: #{changeset.m_count}"
|
||||
end
|
||||
end
|
||||
|
||||
Changeset.find_by_sql("SELECT `changesets`.user_id AS u_id, `repositories`.project_id AS p_id,COUNT(*) AS m_count FROM `changesets` JOIN `repositories` ON `repositories`.id = `changesets`.repository_id GROUP BY u_id,p_id ").each do |changeset|
|
||||
unless changeset.nil?
|
||||
option_num = get_option_num_by_id(changeset.u_id,2,changeset.p_id)
|
||||
option_num.changeset = changeset.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{changeset.u_id}'s changeset number in project #{changeset.p_id}: #{changeset.m_count}"
|
||||
end
|
||||
end
|
||||
|
||||
puts ":push_code calculate Completed."
|
||||
##提交文档
|
||||
Document.find_by_sql("SELECT user_id AS u_id ,COUNT(*) AS m_count FROM `documents` GROUP BY user_id").each do |document|
|
||||
option_num = get_option_num_by_id(document.u_id,1)
|
||||
option_num.document = document.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{document.u_id}'s document number: #{document.m_count}"
|
||||
end
|
||||
|
||||
Document.find_by_sql("SELECT user_id AS u_id , project_id AS p_id, COUNT(*) AS m_count FROM `documents` GROUP BY u_id,p_id").each do |document|
|
||||
option_num = get_option_num_by_id(document.u_id,2,document.p_id)
|
||||
option_num.document = document.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{document.u_id}'s document number in project #{document.p_id}: #{document.m_count}"
|
||||
end
|
||||
|
||||
puts ":push_document calculate Completed."
|
||||
##提交附件
|
||||
Attachment.find_by_sql("SELECT author_id AS u_id,COUNT(*) as m_count FROM #{Attachment.table_name} WHERE container_type = 'Project' GROUP By u_id").each do |attachment|
|
||||
option_num = get_option_num_by_id(attachment.u_id,1)
|
||||
option_num.attachment = attachment.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{attachment.u_id}'s attachment number: #{attachment.m_count}"
|
||||
end
|
||||
|
||||
Attachment.find_by_sql("SELECT author_id AS u_id,container_id AS p_id,COUNT(*) as m_count FROM #{Attachment.table_name} WHERE container_type = 'Project' GROUP By u_id,p_id").each do |attachment|
|
||||
option_num = get_option_num_by_id(attachment.u_id,2,attachment.p_id)
|
||||
option_num.attachment = attachment.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{attachment.u_id}'s attachment number in project #{attachment.p_id}: #{attachment.m_count}"
|
||||
end
|
||||
|
||||
puts ":push_file calculate Completed."
|
||||
##更新完成度
|
||||
Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' GROUP BY u_id ").each do |j|
|
||||
option_num = get_option_num_by_id(j.u_id,1)
|
||||
option_num.issue_done_ratio = j.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{j.u_id}'s issue_done_ratio number: #{j.m_count}"
|
||||
end
|
||||
|
||||
Journal.find_by_sql("SELECT #{Journal.table_name}.user_id AS u_id, #{Issue.table_name}.project_id AS p_id,COUNT(*) as m_count FROM #{Journal.table_name} JOIN #{JournalDetail.table_name} ON #{JournalDetail.table_name}.journal_id = #{Journal.table_name}.id JOIN issues ON issues.id = journals.journalized_id and journalized_type = 'Issue' WHERE #{JournalDetail.table_name}.prop_key = 'done_ratio' GROUP BY u_id,p_id ").each do |j|
|
||||
option_num = get_option_num_by_id(j.u_id,2,j.p_id)
|
||||
option_num.issue_done_ratio = j.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{j.u_id}'s issue_done_ratio number in project #{j.p_id}: #{j.m_count}"
|
||||
end
|
||||
|
||||
puts ":update_issue_ratio calculate Completed."
|
||||
##发布缺陷
|
||||
Issue.find_by_sql("SELECT author_id AS u_id,COUNT(*) as m_count FROM #{Issue.table_name} GROUP BY u_id").each do |issues|
|
||||
option_num = get_option_num_by_id(issues.u_id,1)
|
||||
option_num.post_issue = issues.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{issues.u_id}'s issues number: #{issues.m_count}"
|
||||
end
|
||||
|
||||
Issue.find_by_sql("SELECT author_id AS u_id,project_id AS p_id,COUNT(*) as m_count FROM #{Issue.table_name} GROUP BY u_id,p_id").each do |issues|
|
||||
option_num = get_option_num_by_id(issues.u_id,2,issues.p_id)
|
||||
option_num.post_issue = issues.m_count
|
||||
option_num.save
|
||||
update_score(option_num)
|
||||
puts "#{issues.u_id}'s issues number in project #{issues.p_id}: #{issues.m_count}"
|
||||
end
|
||||
puts ":post_issue calculate Completed."
|
||||
#
|
||||
#
|
||||
#UserScore.transaction do
|
||||
# users_active.each do |user_id, score|
|
||||
# UserScore.find_or_create_by_user_id(user_id).update_attribute(:active, score)
|
||||
# end
|
||||
#end
|
||||
#puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
|
||||
#UserGrade.transaction do
|
||||
# grades.each do |grade_id,score|
|
||||
# grade = UserGrade.find(grade_id)
|
||||
# grade.grade = score
|
||||
# grade.save
|
||||
# end
|
||||
#end
|
||||
#puts "=== UserGrid calculate Completed. UserGrids count: #{grades.count}"
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue