diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 9a35f276c..5d76fce9b 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -169,7 +169,7 @@ 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 @@ -320,7 +320,7 @@ 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) @@ -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.messages_for_issues + option_number.issues_status + option_number.replay_for_message + option_number.replay_for_memo + option_number.memo * 2 + 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.memo * 2 + option_number.changeset * 4 + option_number.document * 4 + option_number.attachment * 4 + option_number.issue_done_ratio * 2 + option_number.post_issue * 4 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 #更新对帖子的回复数量 diff --git a/app/models/query.rb b/app/models/query.rb index 7f51aa53c..65c78e71f 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -493,26 +493,27 @@ class Query < ActiveRecord::Base def project_statement project_clauses = [] # unless project.descendants.blank? - if project && project.descendants && project.descendants.active && !project.descendants.active.empty? - ids = [project.id] - if has_filter?("subproject_id") - case operator_for("subproject_id") - when '=' - # include the selected subprojects - ids += values_for("subproject_id").each(&:to_i) - when '!*' - # main project only - else - # all subprojects - ids += project.descendants.collect(&:id) - end - elsif Setting.display_subprojects_issues? - ids += project.descendants.collect(&:id) - end - project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') - elsif project + # if project && project.descendants && project.descendants.active && !project.descendants.active.empty? + # ids = [project.id] + # if has_filter?("subproject_id") + # case operator_for("subproject_id") + # when '=' + # # include the selected subprojects + # ids += values_for("subproject_id").each(&:to_i) + # when '!*' + # # main project only + # else + # # all subprojects + # ids += project.descendants.collect(&:id) + # end + # elsif Setting.display_subprojects_issues? + # ids += project.descendants.collect(&:id) + # end + # project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') + # elsif project + if project project_clauses << "#{Project.table_name}.id = %d" % project.id - end + end # end project_clauses.any? ? project_clauses.join(' AND ') : nil end