socialforge/lib/tasks/userscore.rake

72 lines
2.0 KiB
Ruby

desc "User Score description"
task :user_score do
puts "user_score sync."
end
namespace :user_score do
desc "calculating user score"
# Rails.env = 'production'
task :calculate => :environment do
puts "loading..."
# collaboration 协同得分
users = {}
# 发帖
Message.includes(:author).where("parent_id IS NULL").all.each do |m|
users[m.author.id] = users[m.author.id].to_i + 2
end
puts ":post_message calculate Completed. users count: #{users.count}"
# 对缺陷的留言
Journal.includes(:user).all.each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
end
puts ":post_issue calculate Completed. users count: #{users.count}"
# 更改一次缺陷状态
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id'").each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
end
puts ":change_issue_status calculate Completed. users count: #{users.count}"
# 对留言的回复
JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL").each do |jfm|
users[jfm.user.id] = users[jfm.user.id].to_i + 1
end
puts ":reply_message calculate Completed. users count: #{users.count}"
# 对帖子的回复
Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
users[m.author.id] = users[m.author.id].to_i + 1
end
puts ":reply_posting calculate Completed. users count: #{users.count}"
users.each do |user_id, score|
UserScore.find_or_create_by_user_id(user_id).update_attribute(:collaboration, score)
end
puts "=== UserScore#collaboration calculate Completed. users count: #{users.count}"
users.clear
# influence 影响力得分
# ...
# skill 技术得分
# ...
# active 项目贡献得分
# ...
end
end
desc "create tmp file, to test"
file 'tmp/test.yml' do
require 'yaml'
var = {
:name => "name",
:age => "age",
:agent => "agent"
}
File.open('tmp/test.yml', 'w') do |f|
f.write YAML.dump({'conf' => var })
end
end