人物分数统计,行为得分,项目相关。提交代码pending

user_scores表结构有问题,重新构建表结构
bundle exec rake db:migrate:down VERSION=20140410021724
bundle exec rake db:migrate:up VERSION=20140410021724
This commit is contained in:
yanxd 2014-06-09 10:40:59 +08:00
parent 61d0532f14
commit 6bd71ce9f1
4 changed files with 76 additions and 7 deletions

View File

@ -56,6 +56,7 @@ class Attachment < ActiveRecord::Base
@@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails") @@thumbnails_storage_path = File.join(Rails.root, "tmp", "thumbnails")
before_save :files_to_final_location before_save :files_to_final_location
before_save :be_user_score # user_score
after_destroy :delete_from_disk after_destroy :delete_from_disk
# Returns an unsaved copy of the attachment # Returns an unsaved copy of the attachment
@ -361,4 +362,17 @@ class Attachment < ActiveRecord::Base
end end
"#{timestamp}_#{ascii}" "#{timestamp}_#{ascii}"
end end
# update user score
def be_user_score
if self.container_id_changed?
type = self.container_type
types = %w|Document News Version Project Issue Message WikiPage|
if types.include?(type)
UserScore.project(:push_file, User.current, { attachment_id: self.id })
end
end
end
end end

View File

@ -19,6 +19,10 @@ class Document < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
belongs_to :project belongs_to :project
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
before_save :be_user_score # user_score
acts_as_attachable :delete_permission => :delete_documents acts_as_attachable :delete_permission => :delete_documents
acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project
@ -54,4 +58,11 @@ class Document < ActiveRecord::Base
end end
@updated_on @updated_on
end end
# update user score
def be_user_score
if self.new_record?
UserScore.project(:push_document, User.current, { document_id: self.id })
end
end
end end

View File

@ -77,6 +77,8 @@ class Issue < ActiveRecord::Base
# fq # fq
after_create :act_as_activity after_create :act_as_activity
before_save :be_user_score
# after_create :be_user_score
# end # end
delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true delegate :notes, :notes=, :private_notes, :private_notes=, :to => :current_journal, :allow_nil => true
@ -1484,4 +1486,14 @@ class Issue < ActiveRecord::Base
and #{visible_condition(User.current, :project => project)} and #{visible_condition(User.current, :project => project)}
group by s.id, s.is_closed, j.id") group by s.id, s.is_closed, j.id")
end end
# update user score
def be_user_score
if self.new_record?
UserScore.project(:post_issue, User.current, { issue_id: self.id })
elsif self.done_ratio_changed?
UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id })
end
end
end end

View File

@ -49,14 +49,21 @@ class UserScore < ActiveRecord::Base
def self.joint(operate, current_user, target_user, options={}) def self.joint(operate, current_user, target_user, options={})
case operate case operate
when :post_message # current_user 发帖了 when :post_message # current_user 发帖了
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})"
when :post_issue # current_user 对 target_user 的缺陷留言了 when :post_issue # current_user 对 target_user 的缺陷留言了
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})"
when :change_issue_status # current_user 更改了缺陷的状态 when :change_issue_status # current_user 更改了缺陷的状态
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})"
when :reply_message # current_user 对 target_user 留言的回复 when :reply_message # current_user 对 target_user 留言的回复
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})"
when :reply_posting # current_user 对 target_user 帖子的回复 when :reply_posting # current_user 对 target_user 帖子的回复
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})"
else else
Rails.logger.error "[UserScore#joint] ===> #{operate} is not define." Rails.logger.error "[UserScore#joint] ===> #{operate} is not define."
return false return false
end end
rescue => e
Rails.logger.error "[UserScore#joint] ===> Exception: #{e}."
end end
# 前略·影响力得分 # 前略·影响力得分
@ -72,10 +79,13 @@ class UserScore < ActiveRecord::Base
def self.influence(operate, current_user, target_user, options={}) def self.influence(operate, current_user, target_user, options={})
case operate case operate
when :followed_by # current_user 关注了target_user when :followed_by # current_user 关注了target_user
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
else else
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
return false return false
end end
rescue => e
Rails.logger.error "[UserScore#influence] ===> Exception: #{e}."
end end
# 前略·技术得分 # 前略·技术得分
@ -90,13 +100,18 @@ class UserScore < ActiveRecord::Base
# Returns boolean. 返回积分保存结果 # Returns boolean. 返回积分保存结果
def self.skill(operate, current_user, target_user, options={}) def self.skill(operate, current_user, target_user, options={})
case operate case operate
when :treading # current_user 踩了 target_user 的帖子 # when :treading # current_user 踩了 target_user 的帖子
# Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treading #{target_user}'s posting. options => (#{options.to_s})"
when :treaded_by_user # current_user 踩了 target_user 的帖子 when :treaded_by_user # current_user 踩了 target_user 的帖子
when :praise_by_user # current_user 顶了 target_user 的帖子 Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treaded_by #{target_user}. options => (#{options.to_s})"
when :praised_by_user # current_user 顶了 target_user 的帖子
Rails.logger.info "[UserScore#skill] ===> User: #{current_user} praised_by #{target_user}. options => (#{options.to_s})"
else else
Rails.logger.error "[UserScore#skill] ===> #{operate} is not define." Rails.logger.error "[UserScore#skill] ===> #{operate} is not define."
return false return false
end end
rescue => e
Rails.logger.error "[UserScore#skill] ===> Exception: #{e}."
end end
# 前略·项目得分 # 前略·项目得分
@ -110,24 +125,41 @@ class UserScore < ActiveRecord::Base
# #
# Returns boolean. 返回积分保存结果 # Returns boolean. 返回积分保存结果
def self.project(operate, current_user, options={}) def self.project(operate, current_user, options={})
current_user, target_user = get_users(current_user, nil)
user_score = current_user.user_score_attr
case operate case operate
when :push_code # current_user 提交了代码 when :push_code # current_user 提交了代码
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"
when :push_document # current_user when :push_document # current_user
user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})"
when :push_file # current_user when :push_file # current_user
when :update_issue # current_user user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})"
when :update_issue_ratio # current_user
user_score.active = user_score.active.to_i + 2
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})"
when :post_issue # current_user when :post_issue # current_user
user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})"
else else
Rails.logger.error "[UserScore#project] ===> #{operate} is not define." Rails.logger.error "[UserScore#project] ===> #{operate} is not define."
return false return false
end end
rescue => e
Rails.logger.error "[UserScore#project] ===> Exception: #{e}."
end end
private private
def get_users(current_user, target_user) def self.get_users(current_user, target_user)
cUser = (current_user.kind_of?User) ? user : User.find_by_id(user) cUser = (current_user.kind_of?User) ? current_user : User.find_by_id(current_user)
tUser = (target_user.kind_of?User) ? user : User.find_by_id(user) tUser = (target_user.kind_of?User) ? target_user : User.find_by_id(target_user)
@current_user, @target_user = cUser, tUser [cUser, tUser]
end end
end end