score statistics init
This commit is contained in:
parent
787e043650
commit
541b22b84d
|
@ -62,6 +62,7 @@ class DocumentsController < ApplicationController
|
|||
def create
|
||||
@document = @project.documents.build
|
||||
@document.safe_attributes = params[:document]
|
||||
@document.user = User.current
|
||||
@document.save_attachments(params[:attachments])
|
||||
if @document.save
|
||||
render_attachment_warning_if_needed(@document)
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
class Document < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id"
|
||||
|
||||
before_save :be_user_score # user_score
|
||||
|
@ -62,7 +63,7 @@ class Document < ActiveRecord::Base
|
|||
# update user score
|
||||
def be_user_score
|
||||
if self.new_record?
|
||||
UserScore.project(:push_document, User.current, { document_id: self.id })
|
||||
UserScore.project(:push_document, self.user, { document_id: self.id })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -112,6 +112,7 @@ class User < Principal
|
|||
has_many :journals
|
||||
has_many :messages, :foreign_key => 'author_id'
|
||||
has_one :user_score, :dependent => :destroy
|
||||
has_many :documents # 项目中关联的文档再次与人关联
|
||||
# end
|
||||
|
||||
######added by nie
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddUserIdToDocuments < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :documents, :user_id, :integer, default: 0
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20140605025247) do
|
||||
ActiveRecord::Schema.define(:version => 20140609061903) do
|
||||
|
||||
create_table "activities", :force => true do |t|
|
||||
t.integer "act_id", :null => false
|
||||
|
@ -288,6 +288,7 @@ ActiveRecord::Schema.define(:version => 20140605025247) do
|
|||
t.string "title", :limit => 60, :default => "", :null => false
|
||||
t.text "description"
|
||||
t.datetime "created_on"
|
||||
t.integer "user_id", :default => 0
|
||||
end
|
||||
|
||||
add_index "documents", ["category_id"], :name => "index_documents_on_category_id"
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
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
|
Loading…
Reference in New Issue