From 6607e72ca461f05e4f6c7dd1c759de2765d49a9a Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Sun, 6 Sep 2015 12:08:24 +0800 Subject: [PATCH] =?UTF-8?q?user=5Fscore=5Fhelper.rb=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/user_score_helper.rb | 192 +++++++++++++++---------------- 1 file changed, 96 insertions(+), 96 deletions(-) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index c94763e31..9a35f276c 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -27,7 +27,7 @@ module UserScoreHelper 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.each do |m| if Memo.find(m.parent_id).author.id != user.id issue_c = issue_c + 1 @@ -35,18 +35,18 @@ module UserScoreHelper issue_c = issue_c - 1 end end - - + + pmemos = Memo.where('author_id = ? AND parent_id IS NULL', user.id) pmemos.each do |pm| issue_c = issue_c + pm.replies_count 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 - - - + + + return issue_c end @@ -58,14 +58,14 @@ module UserScoreHelper def calculate_skill_count(user) - + praise_count_l0 = 0 praise_count_l1 = 0 praise_count_l2 = 0 tread_count_l0 = 0 tread_count_l1 = 0 tread_count_l2 = 0 - issues = Issue.where('author_id = ?', user.id) + issues = Issue.where('author_id = ?', user.id) issues.each do |i| pts = PraiseTread.where('praise_tread_object_id = ?', i.id) pts.each do |p| @@ -75,7 +75,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -97,7 +97,7 @@ module UserScoreHelper - + bids = Bid.where('author_id = ?', user.id) bids.each do |b| ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id) @@ -108,7 +108,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -127,7 +127,7 @@ module UserScoreHelper end end end - + contests = Contest.where('author_id = ?', user.id) contests.each do |c| ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id) @@ -138,7 +138,7 @@ module UserScoreHelper if p.praise_or_tread == 1 praise_count_l0 = praise_count_l0 + 1 else - tread_count_l0 = tread_count_l0 + 1 + tread_count_l0 = tread_count_l0 + 1 end end if templevel.to_i == 1 @@ -154,12 +154,12 @@ module UserScoreHelper else tread_count_l2 + tread_count_l2 + 1 end - end - end + end + end end - - - + + + # case level # when 0 skill_score = praise_count - 0.5 * tread_count # when 1 skill_score = 2 * praise_count - 1.5 * tread_count @@ -169,10 +169,10 @@ module UserScoreHelper # end 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 - + skill_score = skill_score.to_f - tread_user_count.to_f @@ -182,17 +182,17 @@ module UserScoreHelper return skill_score - - - + + + end - + def calculate_level(user) commit_count = user.changesets.count max_praise_num = 0 - - - issues = Issue.where('author_id = ?', user.id) + + + issues = Issue.where('author_id = ?', user.id) issues.each do |i| ptcs = PraiseTreadCache.where('object_id = ?', i.id) ptcs.each do |p| @@ -201,7 +201,7 @@ module UserScoreHelper end end end - + bids = Bid.where('author_id = ?', user.id) bids.each do |b| ptcs = PraiseTreadCache.where('object_id = ?', b.id) @@ -211,7 +211,7 @@ module UserScoreHelper end end end - + contests = Contest.where('author_id = ?', user.id) contests.each do |c| ptcs = PraiseTreadCache.where('object_id = ?', c.id) @@ -219,12 +219,12 @@ module UserScoreHelper if p.praise_num.to_i > max_praise_num.to_i max_praise_num = p.praise_num end - end + end end - - + + best_answer_num = 0 - + isManager = 0 members = Member.where('user_id = ?', user.id) members.each do |m| @@ -238,21 +238,21 @@ module UserScoreHelper end - + level = 0 - + if max_praise_num > 4 level = 1 end if commit_count > 0 and commit_count < 101 level = 1 - end + end if commit_count > 100 or isManager == 1 level = 2 end - + return level - + end def calculate_activity_count(user) @@ -282,23 +282,23 @@ module UserScoreHelper def calculate_issue(user) commit_count = user.changesets.count - + issue_details_count = 0 issues = Issue.where('assigned_to_id = ?', user.id) - + change_count = 0 issues.each do |issue| js = issue.journals js.each do |j| change_count = change_count + j.details.where("prop_key = ?", "done_ratio").count end - - + + issue_details_count = change_count + issue_details_count end - + return (commit_count + issue_details_count) - + 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 return attachments - + end - + def calculate_user_score(user) collaboration = calculate_collaboration_count(user) influence = calculate_influence_count(user) @@ -320,9 +320,9 @@ module UserScoreHelper #user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill, # :activity => activity, :file => file, :issue => issue, :level => level) 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 - + def update_user_score(user) collaboration = calculate_collaboration_count(user) influence = calculate_influence_count(user) @@ -331,7 +331,7 @@ module UserScoreHelper issue = calculate_issue(user) ##activity = calculate_activity_count(user) - + level = calculate_level(user) user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill, :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}'"); 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.nil? - result.project_id = project.id - end - else - result = option_number.first - end - result + 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.nil? + result.project_id = project.id + end + else + result = option_number.first + end + result end def get_option_num_by_id(user_id,type,project_id=nil) @@ -433,7 +433,7 @@ module UserScoreHelper #协同得分 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 #影响力得分 def influence(option_number) @@ -441,11 +441,11 @@ module UserScoreHelper end #技术得分 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 #项目贡献得分 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 #更新发帖数 @@ -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}") result = 0 users.each do |user| - result = user.m_count + result = user.m_count end result end @@ -481,15 +481,15 @@ WHERE messages.parent_id IS NULL AND messages.author_id = #{user.id}") end def memo_score(user,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 + 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 WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count FROM `users` where id = #{user.id}") - 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 + 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 WHERE messages.parent_id IS NULL AND messages.author_id = `users`.id) AS m_count FROM `users` where id = #{user.id}") - 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 != ''") result = 0 if users.count > 0 - result = users.first.m_count + result = users.first.m_count end result else @@ -521,7 +521,7 @@ FROM `users` where id = #{user.id}") def messges_for_issue_score(user,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 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 @@ -594,11 +594,11 @@ FROM `users` where id = #{user.id}") end 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}'") - 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}'") - end + end end #更新对帖子的回复数量