merge jrating
This commit is contained in:
commit
e802424e2a
|
@ -10,4 +10,4 @@
|
||||||
/public/images/avatars/*
|
/public/images/avatars/*
|
||||||
/Gemfile
|
/Gemfile
|
||||||
/Gemfile.lock
|
/Gemfile.lock
|
||||||
/db/schema.da
|
/db/schema.rb
|
||||||
|
|
|
@ -0,0 +1,108 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
#
|
||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
module UserScoreHelper
|
||||||
|
def calculate_collaboration_count(user)
|
||||||
|
issue_c = 0
|
||||||
|
issues = Issue.where('author_id = ?', user.id)
|
||||||
|
issues.each do |issue|
|
||||||
|
issue_c = issue_c + issue.journals.where("user_id <> ?", user.id).count
|
||||||
|
end
|
||||||
|
issue_c = issue_c + Journal.where("user_id = ?", user.id)
|
||||||
|
|
||||||
|
return issue_c
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_influence_count(user)
|
||||||
|
watcher_count = watcher_users(User.current.id).count
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_skill_count(user)
|
||||||
|
0
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_level(user)
|
||||||
|
1
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_activity_count(user)
|
||||||
|
# commit_count = user.changesets.count
|
||||||
|
# issue_details_count = 0
|
||||||
|
# issues = Issue.where('assigned_to_id = ?', user.id)
|
||||||
|
# issues.each do |issue|
|
||||||
|
# change_count = issue.journals.where("prop_key = ?", "done_ratio").count
|
||||||
|
# issue_details_count = change_count + issue_details_count
|
||||||
|
# end
|
||||||
|
# file_count = user.file_commit.count
|
||||||
|
# issue_count = Issue.where('author_id = ?', user.id).count
|
||||||
|
f = user.user_score.file
|
||||||
|
i = user.user_score.issue
|
||||||
|
f_max = UserScore.find_max_file
|
||||||
|
f_min = UserScore.find_min_file
|
||||||
|
i_max = UserScore.find_max_issue
|
||||||
|
i_min = UserScore.find_min_issue
|
||||||
|
score = 100 * ((f - f_min)/(f_max - f_min) + (i - i_min)/(i_max - i_min))
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_file(user)
|
||||||
|
file_count = user.file_commit.count
|
||||||
|
issue_count = Issue.where('author_id = ?', user.id).count
|
||||||
|
return (file_count + issue_count)
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_issue(user)
|
||||||
|
commit_count = user.changesets.count
|
||||||
|
|
||||||
|
issue_details_count = 0
|
||||||
|
issues = Issue.where('assigned_to_id = ?', user.id)
|
||||||
|
|
||||||
|
issues.each do |issue|
|
||||||
|
change_count = issue.journals.where("prop_key = ?", "done_ratio").count
|
||||||
|
issue_details_count = change_count + issue_details_count
|
||||||
|
end
|
||||||
|
|
||||||
|
return (commit_count + issue_details_count)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def calculate_user_score(user)
|
||||||
|
collaboration = calculate_collaboration_count(user)
|
||||||
|
influence = calculate_influence_count(user)
|
||||||
|
skill = calculate_skill_count(user)
|
||||||
|
activity = calculate_activity_count(user)
|
||||||
|
file = calculate_file(user)
|
||||||
|
issue = calculate_issue(user)
|
||||||
|
level = calculate_level(user)
|
||||||
|
user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
|
||||||
|
:activity => activity, :file => file, :issue => issue, :level => level)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_user_score(user)
|
||||||
|
collaboration = calculate_collaboration_count(user)
|
||||||
|
influence = calculate_influence_count(user)
|
||||||
|
skill = calculate_skill_count(user)
|
||||||
|
activity = calculate_activity_count(user)
|
||||||
|
file = calculate_file(user)
|
||||||
|
issue = calculate_issue(user)
|
||||||
|
level = calculate_level(user)
|
||||||
|
user.user_score.update_attributes(:collaboration => collaboration, :influence => influence, :skill => skill,
|
||||||
|
:activity => activity, :file => file, :issue => issue, :level => level)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -96,6 +96,7 @@ class User < Principal
|
||||||
has_many :students_for_courses
|
has_many :students_for_courses
|
||||||
has_many :courses, :through => :students_for_courses, :source => :project
|
has_many :courses, :through => :students_for_courses, :source => :project
|
||||||
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
|
||||||
|
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_tpye = 'Project' or container_type = 'Version'"
|
||||||
####
|
####
|
||||||
# added by bai
|
# added by bai
|
||||||
has_many :join_in_contests, :dependent => :destroy
|
has_many :join_in_contests, :dependent => :destroy
|
||||||
|
@ -104,6 +105,7 @@ class User < Principal
|
||||||
has_many :wiki_contents, :foreign_key => 'author_id'
|
has_many :wiki_contents, :foreign_key => 'author_id'
|
||||||
has_many :journals
|
has_many :journals
|
||||||
has_many :messages, :foreign_key => 'author_id'
|
has_many :messages, :foreign_key => 'author_id'
|
||||||
|
has_one :user_socre, :dependent => :destroy
|
||||||
# end
|
# end
|
||||||
|
|
||||||
######added by nie
|
######added by nie
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 2
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
class UserScore < ActiveRecord::Base
|
||||||
|
belongs_to :user
|
||||||
|
|
||||||
|
def self.find_max_file
|
||||||
|
self.maximum(:file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_min_file
|
||||||
|
self.minimum(:file)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_max_issue
|
||||||
|
self.maximum(:issue)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.find_min_issue
|
||||||
|
self.minimum(:file)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,13 @@
|
||||||
|
class CreateUserScore < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :user_scores do |t|
|
||||||
|
t.integer :user_id, :null => false
|
||||||
|
t.integer :collaboration
|
||||||
|
t.integer :influence
|
||||||
|
t.integer :skill
|
||||||
|
t.integer :active
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,7 @@
|
||||||
|
class AddFiledToUserPreference < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :user_scores, :level, :integer
|
||||||
|
add_column :user_scores, :file, :integer
|
||||||
|
add_column :user_scores, :issue, :integer
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
|
||||||
|
|
||||||
|
one:
|
||||||
|
user_id: 1
|
||||||
|
bid_id: 1
|
||||||
|
|
||||||
|
two:
|
||||||
|
user_id: 1
|
||||||
|
bid_id: 1
|
|
@ -0,0 +1,7 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class JoinInContestTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
Loading…
Reference in New Issue