Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
This commit is contained in:
commit
33baf88886
|
@ -98,7 +98,9 @@ class Changeset < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def project
|
def project
|
||||||
repository.project
|
unless repository.nil?
|
||||||
|
repository.project
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def author
|
def author
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140626012511) do
|
ActiveRecord::Schema.define(:version => 20140617013146) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -374,13 +374,12 @@ ActiveRecord::Schema.define(:version => 20140626012511) do
|
||||||
create_table "homework_attaches", :force => true do |t|
|
create_table "homework_attaches", :force => true do |t|
|
||||||
t.integer "bid_id"
|
t.integer "bid_id"
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
t.string "reward"
|
t.string "reward"
|
||||||
t.string "name"
|
t.string "name"
|
||||||
t.string "description"
|
t.string "description"
|
||||||
t.integer "state"
|
t.integer "state"
|
||||||
t.integer "project_id", :default => 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "homework_for_courses", :force => true do |t|
|
create_table "homework_for_courses", :force => true do |t|
|
||||||
|
|
|
@ -11,21 +11,48 @@ namespace :user_score do
|
||||||
puts "loading..."
|
puts "loading..."
|
||||||
# collaboration 协同得分
|
# collaboration 协同得分
|
||||||
users = {}
|
users = {}
|
||||||
|
grades = {}
|
||||||
# 发帖
|
# 发帖
|
||||||
Message.includes(:author).where("parent_id IS NULL").all.each do |m|
|
Message.includes(:author).where("parent_id IS NULL").all.each do |m|
|
||||||
users[m.author.id] = users[m.author.id].to_i + 2
|
users[m.author.id] = users[m.author.id].to_i + 2
|
||||||
|
project = m.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id => m.author.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 2
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
puts ":post_message calculate Completed. collaboration users count: #{users.count}"
|
puts ":post_message calculate Completed. collaboration users count: #{users.count}"
|
||||||
|
|
||||||
# 对缺陷的留言
|
# 对缺陷的留言
|
||||||
Journal.includes(:user).all.each do |j|
|
Journal.includes(:user).all.each do |j|
|
||||||
users[j.user.id] = users[j.user.id].to_i + 1
|
users[j.user.id] = users[j.user.id].to_i + 1
|
||||||
|
project = j.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":post_issue_message calculate Completed. collaboration users count: #{users.count}"
|
puts ":post_issue_message calculate Completed. collaboration users count: #{users.count}"
|
||||||
|
|
||||||
# 更改一次缺陷状态
|
# 更改一次缺陷状态
|
||||||
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id'").each do |j|
|
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
|
users[j.user.id] = users[j.user.id].to_i + 1
|
||||||
|
project = j.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 1
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}"
|
puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}"
|
||||||
|
|
||||||
|
@ -38,6 +65,14 @@ namespace :user_score do
|
||||||
# 对帖子的回复
|
# 对帖子的回复
|
||||||
Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
|
Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
|
||||||
users[m.author.id] = users[m.author.id].to_i + 1
|
users[m.author.id] = users[m.author.id].to_i + 1
|
||||||
|
project = m.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>m.author.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
|
puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
|
||||||
|
|
||||||
|
@ -76,24 +111,74 @@ namespace :user_score do
|
||||||
end
|
end
|
||||||
target_user = obj.author
|
target_user = obj.author
|
||||||
level = UserLevels.get_level(pt.user)#pt.user.get_level
|
level = UserLevels.get_level(pt.user)#pt.user.get_level
|
||||||
|
project = pt.project
|
||||||
if pt.praise_or_tread == 0
|
if pt.praise_or_tread == 0
|
||||||
#踩帖
|
#踩帖
|
||||||
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
|
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(pt.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>pt.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i - 2
|
||||||
|
end
|
||||||
if level == 1
|
if level == 1
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i - 2
|
||||||
|
end
|
||||||
elsif level == 2
|
elsif level == 2
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i - 4
|
||||||
|
end
|
||||||
elsif level == 3
|
elsif level == 3
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i - 6
|
||||||
|
end
|
||||||
end
|
end
|
||||||
elsif pt.praise_or_tread == 1
|
elsif pt.praise_or_tread == 1
|
||||||
#顶贴
|
#顶贴
|
||||||
if level == 1
|
if level == 1
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
elsif level == 2
|
elsif level == 2
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 6
|
||||||
|
end
|
||||||
elsif level == 3
|
elsif level == 3
|
||||||
users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread
|
users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 8
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -114,6 +199,14 @@ namespace :user_score do
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4
|
users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4
|
||||||
|
project = changeset.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(changeset.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>changeset.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":push_code calculate Completed. active users count: #{users_active.count}"
|
puts ":push_code calculate Completed. active users count: #{users_active.count}"
|
||||||
#提交文档
|
#提交文档
|
||||||
|
@ -122,6 +215,14 @@ namespace :user_score do
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
users_active[document.user.id] = users_active[document.user.id].to_i + 4
|
users_active[document.user.id] = users_active[document.user.id].to_i + 4
|
||||||
|
project = document.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(document.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>document.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":push_document calculate Completed. active users count: #{users_active.count}"
|
puts ":push_document calculate Completed. active users count: #{users_active.count}"
|
||||||
#提交附件
|
#提交附件
|
||||||
|
@ -134,6 +235,17 @@ namespace :user_score do
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
users_active[attachment.author.id] = users_active[attachment.author.id].to_i + 4
|
users_active[attachment.author.id] = users_active[attachment.author.id].to_i + 4
|
||||||
|
if attachment.container.class.to_s == "Project"
|
||||||
|
project = attachment.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(attachment.author.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>attachment.author.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# end
|
# end
|
||||||
#end
|
#end
|
||||||
end
|
end
|
||||||
|
@ -141,11 +253,27 @@ namespace :user_score do
|
||||||
#更新完成度
|
#更新完成度
|
||||||
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio'").each do |j|
|
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio'").each do |j|
|
||||||
users_active[j.user.id] = users_active[j.user.id].to_i + 2
|
users_active[j.user.id] = users_active[j.user.id].to_i + 2
|
||||||
|
project = j.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>j.user.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}"
|
puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}"
|
||||||
#发布缺陷
|
#发布缺陷
|
||||||
Issue.includes(:author).all.each do |issue|
|
Issue.includes(:author).all.each do |issue|
|
||||||
users_active[issue.author.id] = users_active[issue.author.id].to_i + 4
|
users_active[issue.author.id] = users_active[issue.author.id].to_i + 4
|
||||||
|
project = issue.project
|
||||||
|
unless project.nil?
|
||||||
|
user_grade = UserGrade.find_by_user_id_and_project_id(issue.author.id, project.id)
|
||||||
|
if user_grade.nil?
|
||||||
|
user_grade = UserGrade.create(:user_id =>issue.author.id, :project_id => project.id)
|
||||||
|
end
|
||||||
|
grades[user_grade.id] = grades[user_grade.id].to_i + 4
|
||||||
|
end
|
||||||
end
|
end
|
||||||
puts ":post_issue calculate Completed. active users count: #{users_active.count}"
|
puts ":post_issue calculate Completed. active users count: #{users_active.count}"
|
||||||
|
|
||||||
|
@ -156,8 +284,14 @@ namespace :user_score do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
|
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
|
||||||
puts ""
|
UserGrade.transaction do
|
||||||
|
grades.each do |grade_id,score|
|
||||||
|
grade = UserGrade.find(grade_id)
|
||||||
|
grade.grade = score
|
||||||
|
grade.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
puts "=== UserGrid calculate Completed. UserGrids count: #{grades.count}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue