user_score_helper.rb还原

This commit is contained in:
sw 2015-09-06 12:08:24 +08:00
parent c4320f1bcc
commit 6607e72ca4
1 changed files with 96 additions and 96 deletions

View File

@ -27,7 +27,7 @@ module UserScoreHelper
issue_c = issue_c + Journal.where("user_id = ?", user.id).count issue_c = issue_c + Journal.where("user_id = ?", user.id).count
############################ ############################
memos = Memo.where('author_id = ? AND parent_id IS NOT NULL', user.id) memos = Memo.where('author_id = ? AND parent_id IS NOT NULL', user.id)
memos.each do |m| memos.each do |m|
if Memo.find(m.parent_id).author.id != user.id if Memo.find(m.parent_id).author.id != user.id
issue_c = issue_c + 1 issue_c = issue_c + 1
@ -35,18 +35,18 @@ module UserScoreHelper
issue_c = issue_c - 1 issue_c = issue_c - 1
end end
end end
pmemos = Memo.where('author_id = ? AND parent_id IS NULL', user.id) pmemos = Memo.where('author_id = ? AND parent_id IS NULL', user.id)
pmemos.each do |pm| pmemos.each do |pm|
issue_c = issue_c + pm.replies_count issue_c = issue_c + pm.replies_count
end end
############################ ############################
issue_c = issue_c + JournalsForMessage.where('user_id = ? AND reply_id IS NOT NULL AND reply_id <> ?', user.id, user.id).count + JournalsForMessage.where('reply_id = ? AND user_id <> ?', user.id, user.id).count issue_c = issue_c + JournalsForMessage.where('user_id = ? AND reply_id IS NOT NULL AND reply_id <> ?', user.id, user.id).count + JournalsForMessage.where('reply_id = ? AND user_id <> ?', user.id, user.id).count
return issue_c return issue_c
end end
@ -58,14 +58,14 @@ module UserScoreHelper
def calculate_skill_count(user) def calculate_skill_count(user)
praise_count_l0 = 0 praise_count_l0 = 0
praise_count_l1 = 0 praise_count_l1 = 0
praise_count_l2 = 0 praise_count_l2 = 0
tread_count_l0 = 0 tread_count_l0 = 0
tread_count_l1 = 0 tread_count_l1 = 0
tread_count_l2 = 0 tread_count_l2 = 0
issues = Issue.where('author_id = ?', user.id) issues = Issue.where('author_id = ?', user.id)
issues.each do |i| issues.each do |i|
pts = PraiseTread.where('praise_tread_object_id = ?', i.id) pts = PraiseTread.where('praise_tread_object_id = ?', i.id)
pts.each do |p| pts.each do |p|
@ -75,7 +75,7 @@ module UserScoreHelper
if p.praise_or_tread == 1 if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1 praise_count_l0 = praise_count_l0 + 1
else else
tread_count_l0 = tread_count_l0 + 1 tread_count_l0 = tread_count_l0 + 1
end end
end end
if templevel.to_i == 1 if templevel.to_i == 1
@ -97,7 +97,7 @@ module UserScoreHelper
bids = Bid.where('author_id = ?', user.id) bids = Bid.where('author_id = ?', user.id)
bids.each do |b| bids.each do |b|
ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id) ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id)
@ -108,7 +108,7 @@ module UserScoreHelper
if p.praise_or_tread == 1 if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1 praise_count_l0 = praise_count_l0 + 1
else else
tread_count_l0 = tread_count_l0 + 1 tread_count_l0 = tread_count_l0 + 1
end end
end end
if templevel.to_i == 1 if templevel.to_i == 1
@ -127,7 +127,7 @@ module UserScoreHelper
end end
end end
end end
contests = Contest.where('author_id = ?', user.id) contests = Contest.where('author_id = ?', user.id)
contests.each do |c| contests.each do |c|
ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id) ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id)
@ -138,7 +138,7 @@ module UserScoreHelper
if p.praise_or_tread == 1 if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1 praise_count_l0 = praise_count_l0 + 1
else else
tread_count_l0 = tread_count_l0 + 1 tread_count_l0 = tread_count_l0 + 1
end end
end end
if templevel.to_i == 1 if templevel.to_i == 1
@ -154,12 +154,12 @@ module UserScoreHelper
else else
tread_count_l2 + tread_count_l2 + 1 tread_count_l2 + tread_count_l2 + 1
end end
end end
end end
end end
# case level # case level
# when 0 skill_score = praise_count - 0.5 * tread_count # when 0 skill_score = praise_count - 0.5 * tread_count
# when 1 skill_score = 2 * praise_count - 1.5 * tread_count # when 1 skill_score = 2 * praise_count - 1.5 * tread_count
@ -169,10 +169,10 @@ module UserScoreHelper
# end # end
skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f
- 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f - 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f
tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count
skill_score = skill_score.to_f - tread_user_count.to_f skill_score = skill_score.to_f - tread_user_count.to_f
@ -182,17 +182,17 @@ module UserScoreHelper
return skill_score return skill_score
end end
def calculate_level(user) def calculate_level(user)
commit_count = user.changesets.count commit_count = user.changesets.count
max_praise_num = 0 max_praise_num = 0
issues = Issue.where('author_id = ?', user.id) issues = Issue.where('author_id = ?', user.id)
issues.each do |i| issues.each do |i|
ptcs = PraiseTreadCache.where('object_id = ?', i.id) ptcs = PraiseTreadCache.where('object_id = ?', i.id)
ptcs.each do |p| ptcs.each do |p|
@ -201,7 +201,7 @@ module UserScoreHelper
end end
end end
end end
bids = Bid.where('author_id = ?', user.id) bids = Bid.where('author_id = ?', user.id)
bids.each do |b| bids.each do |b|
ptcs = PraiseTreadCache.where('object_id = ?', b.id) ptcs = PraiseTreadCache.where('object_id = ?', b.id)
@ -211,7 +211,7 @@ module UserScoreHelper
end end
end end
end end
contests = Contest.where('author_id = ?', user.id) contests = Contest.where('author_id = ?', user.id)
contests.each do |c| contests.each do |c|
ptcs = PraiseTreadCache.where('object_id = ?', c.id) ptcs = PraiseTreadCache.where('object_id = ?', c.id)
@ -219,12 +219,12 @@ module UserScoreHelper
if p.praise_num.to_i > max_praise_num.to_i if p.praise_num.to_i > max_praise_num.to_i
max_praise_num = p.praise_num max_praise_num = p.praise_num
end end
end end
end end
best_answer_num = 0 best_answer_num = 0
isManager = 0 isManager = 0
members = Member.where('user_id = ?', user.id) members = Member.where('user_id = ?', user.id)
members.each do |m| members.each do |m|
@ -238,21 +238,21 @@ module UserScoreHelper
end end
level = 0 level = 0
if max_praise_num > 4 if max_praise_num > 4
level = 1 level = 1
end end
if commit_count > 0 and commit_count < 101 if commit_count > 0 and commit_count < 101
level = 1 level = 1
end end
if commit_count > 100 or isManager == 1 if commit_count > 100 or isManager == 1
level = 2 level = 2
end end
return level return level
end end
def calculate_activity_count(user) def calculate_activity_count(user)
@ -282,23 +282,23 @@ module UserScoreHelper
def calculate_issue(user) def calculate_issue(user)
commit_count = user.changesets.count commit_count = user.changesets.count
issue_details_count = 0 issue_details_count = 0
issues = Issue.where('assigned_to_id = ?', user.id) issues = Issue.where('assigned_to_id = ?', user.id)
change_count = 0 change_count = 0
issues.each do |issue| issues.each do |issue|
js = issue.journals js = issue.journals
js.each do |j| js.each do |j|
change_count = change_count + j.details.where("prop_key = ?", "done_ratio").count change_count = change_count + j.details.where("prop_key = ?", "done_ratio").count
end end
issue_details_count = change_count + issue_details_count issue_details_count = change_count + issue_details_count
end end
return (commit_count + issue_details_count) return (commit_count + issue_details_count)
end end
@ -306,9 +306,9 @@ module UserScoreHelper
attachments = Attachment.where("container_type IS NOT NULL AND container_type <> 'Issue' AND author_id = ?", user.id).count attachments = Attachment.where("container_type IS NOT NULL AND container_type <> 'Issue' AND author_id = ?", user.id).count
return attachments return attachments
end end
def calculate_user_score(user) def calculate_user_score(user)
collaboration = calculate_collaboration_count(user) collaboration = calculate_collaboration_count(user)
influence = calculate_influence_count(user) influence = calculate_influence_count(user)
@ -320,9 +320,9 @@ module UserScoreHelper
#user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, #user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
# :activity => activity, :file => file, :issue => issue, :level => level) # :activity => activity, :file => file, :issue => issue, :level => level)
UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
:activity => activity, :file => file, :issue => issue, :level => level) :activity => activity, :file => file, :issue => issue, :level => level)
end end
def update_user_score(user) def update_user_score(user)
collaboration = calculate_collaboration_count(user) collaboration = calculate_collaboration_count(user)
influence = calculate_influence_count(user) influence = calculate_influence_count(user)
@ -331,7 +331,7 @@ module UserScoreHelper
issue = calculate_issue(user) issue = calculate_issue(user)
##activity = calculate_activity_count(user) ##activity = calculate_activity_count(user)
level = calculate_level(user) level = calculate_level(user)
user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill, user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill,
:activity => activity, :file => file, :issue => issue, :level => level) :activity => activity, :file => file, :issue => issue, :level => level)
@ -348,37 +348,37 @@ module UserScoreHelper
option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project.id}'"); option_number = OptionNumber.where("user_id = '#{user.id}' and score_type = '#{type}' and project_id = '#{project.id}'");
end end
result = nil result = nil
if option_number.nil? || option_number.count == 0 if option_number.nil? || option_number.count == 0
result = OptionNumber.new result = OptionNumber.new
result.user_id = user.id result.user_id = user.id
result.memo = 0 result.memo = 0
result.messages_for_issues = 0 result.messages_for_issues = 0
result.issues_status = 0 result.issues_status = 0
result.replay_for_message = 0 result.replay_for_message = 0
result.replay_for_memo = 0 result.replay_for_memo = 0
result.follow = 0 result.follow = 0
result.tread = 0 result.tread = 0
result.praise_by_one = 0 result.praise_by_one = 0
result.praise_by_two = 0 result.praise_by_two = 0
result.praise_by_three = 0 result.praise_by_three = 0
result.tread_by_one = 0 result.tread_by_one = 0
result.tread_by_two = 0 result.tread_by_two = 0
result.tread_by_three = 0 result.tread_by_three = 0
result.changeset = 0 result.changeset = 0
result.document = 0 result.document = 0
result.attachment = 0 result.attachment = 0
result.issue_done_ratio = 0 result.issue_done_ratio = 0
result.post_issue = 0 result.post_issue = 0
result.total_score = 0 result.total_score = 0
result.score_type =type result.score_type =type
unless project.nil? unless project.nil?
result.project_id = project.id result.project_id = project.id
end end
else else
result = option_number.first result = option_number.first
end end
result result
end end
def get_option_num_by_id(user_id,type,project_id=nil) def get_option_num_by_id(user_id,type,project_id=nil)
@ -433,7 +433,7 @@ module UserScoreHelper
#协同得分 #协同得分
def collaboration(option_number) def collaboration(option_number)
option_number.memo * 2 + option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo option_number.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo
end end
#影响力得分 #影响力得分
def influence(option_number) def influence(option_number)
@ -441,11 +441,11 @@ module UserScoreHelper
end end
#技术得分 #技术得分
def skill(option_number) def skill(option_number)
option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6 option_number.praise_by_one * 4 + option_number.praise_by_two * 6 + option_number.praise_by_three * 8 - option_number.tread * 2 - option_number.tread_by_one * 2 - option_number.tread_by_two * 4 - option_number.tread_by_three * 6
end end
#项目贡献得分 #项目贡献得分
def active(option_number) def active(option_number)
option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 + option_number.memo * 2
end end
#更新发帖数 #更新发帖数
@ -473,7 +473,7 @@ WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}") WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
result = 0 result = 0
users.each do |user| users.each do |user|
result = user.m_count result = user.m_count
end end
result result
end end
@ -481,15 +481,15 @@ WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}")
end end
def memo_score(user,project=nil) def memo_score(user,project=nil)
if project.nil? if project.nil?
User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id != -1 AND messages.board_id = boards.id User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 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 WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
FROM `users` where id = #{user.id}") FROM `users` where id = #{user.id}")
else else
User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 FROM `messages` JOIN `boards` ON boards.project_id = '#{project.id}' AND messages.board_id = boards.id User.find_by_sql("SELECT `users`.id,(SELECT COUNT(*) * 2 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 WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count
FROM `users` where id = #{user.id}") FROM `users` where id = #{user.id}")
end end
end end
#更新对缺陷留言数 #更新对缺陷留言数
@ -505,7 +505,7 @@ 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 != ''") 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 result = 0
if users.count > 0 if users.count > 0
result = users.first.m_count result = users.first.m_count
end end
result result
else else
@ -521,7 +521,7 @@ FROM `users` where id = #{user.id}")
def messges_for_issue_score(user,project=nil) def messges_for_issue_score(user,project=nil)
if project.nil? if project.nil?
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_score FROM users where id = #{user.id}") 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_score FROM users where id = #{user.id}")
else else
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_score FROM users where id = #{user.id}") 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_score FROM users where id = #{user.id}")
end end
@ -594,11 +594,11 @@ FROM `users` where id = #{user.id}")
end end
def replay_for_message_score(user,project=nil) def replay_for_message_score(user,project=nil)
if project.nil? if project.nil?
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_score FROM users WHERE users.id = '#{user.id}'") 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_score FROM users WHERE users.id = '#{user.id}'")
else else
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_score FROM users WHERE users.id = '#{user.id}'") 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_score FROM users WHERE users.id = '#{user.id}'")
end end
end end
#更新对帖子的回复数量 #更新对帖子的回复数量