用户评分理论上完成版.
This commit is contained in:
parent
ded3da6670
commit
00e62ec8f7
|
@ -1,4 +1,6 @@
|
|||
class TestController < ApplicationController
|
||||
|
||||
helper :UserScore
|
||||
|
||||
def zip
|
||||
homeworks_attach_path = []
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
class UserScoreController < ApplicationController
|
||||
helper :UserScoreHelper
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -51,7 +51,7 @@ module UserScoreHelper
|
|||
end
|
||||
|
||||
def calculate_influence_count(user)
|
||||
watcher_count = watcher_users(User.current.id).count
|
||||
watcher_count = Watcher.where("watchable_type = 'principal' AND watchable_id = ?", user.id).count
|
||||
end
|
||||
|
||||
def calculate_skill_count(user)
|
||||
|
@ -92,13 +92,17 @@ module UserScoreHelper
|
|||
|
||||
if level == 0
|
||||
skill_score = praise_count - 0.5 * tread_count
|
||||
elseif level == 1
|
||||
end
|
||||
if level == 1
|
||||
skill_score = 2 * praise_count - 1.5 * tread_count
|
||||
elseif level == 2
|
||||
end
|
||||
if level == 2
|
||||
skill_socre = 3 * praise_count - 2.5 * tread_count
|
||||
elseif level == 3
|
||||
end
|
||||
if level == 3
|
||||
skill_socre = 4 * praise_count - 3.5 * tread_count
|
||||
elseif level == 4
|
||||
end
|
||||
if level == 4
|
||||
skill_socre = 5 * praise_count - 4.5 * tread_count
|
||||
end
|
||||
|
||||
|
@ -175,9 +179,11 @@ module UserScoreHelper
|
|||
|
||||
if max_praise_num > 4
|
||||
level = 1
|
||||
elseif commit_count > 0 and commit_count < 101
|
||||
end
|
||||
if commit_count > 0 and commit_count < 101
|
||||
level = 1
|
||||
elseif commit_count > 100 or isManager == 1
|
||||
end
|
||||
if commit_count > 100 or isManager == 1
|
||||
level = 2
|
||||
end
|
||||
|
||||
|
@ -195,13 +201,13 @@ module UserScoreHelper
|
|||
# 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))
|
||||
#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)
|
||||
|
@ -216,8 +222,14 @@ module UserScoreHelper
|
|||
issue_details_count = 0
|
||||
issues = Issue.where('assigned_to_id = ?', user.id)
|
||||
|
||||
change_count = 0
|
||||
issues.each do |issue|
|
||||
change_count = issue.journals.where("prop_key = ?", "done_ratio").count
|
||||
js = issue.journals
|
||||
js.each do |j|
|
||||
change_count = change_count + j.details.where("prop_key = ?", "done_ratio").count
|
||||
end
|
||||
|
||||
|
||||
issue_details_count = change_count + issue_details_count
|
||||
end
|
||||
|
||||
|
@ -233,7 +245,9 @@ module UserScoreHelper
|
|||
file = calculate_file(user)
|
||||
issue = calculate_issue(user)
|
||||
level = calculate_level(user)
|
||||
user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
|
||||
#user.user_score << UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
|
||||
# :activity => activity, :file => file, :issue => issue, :level => level)
|
||||
UserScore.new(:collaboration => collaboration, :influence => influence, :skill => skill,
|
||||
:activity => activity, :file => file, :issue => issue, :level => level)
|
||||
end
|
||||
|
||||
|
@ -241,12 +255,17 @@ module UserScoreHelper
|
|||
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)
|
||||
|
||||
##activity = calculate_activity_count(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,7 +96,7 @@ class User < Principal
|
|||
has_many :students_for_courses
|
||||
has_many :courses, :through => :students_for_courses, :source => :project
|
||||
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'"
|
||||
has_many :file_commit, :class_name => 'Attachment', :foreign_key => 'author_id', :conditions => "container_type = 'Project' or container_type = 'Version'"
|
||||
####
|
||||
# added by bai
|
||||
has_many :join_in_contests, :dependent => :destroy
|
||||
|
@ -105,7 +105,7 @@ class User < Principal
|
|||
has_many :wiki_contents, :foreign_key => 'author_id'
|
||||
has_many :journals
|
||||
has_many :messages, :foreign_key => 'author_id'
|
||||
has_one :user_socre, :dependent => :destroy
|
||||
has_one :user_score, :dependent => :destroy
|
||||
# end
|
||||
|
||||
######added by nie
|
||||
|
|
|
@ -1,15 +1,26 @@
|
|||
<h3>test</h3>
|
||||
|
||||
<% memos=Memo.where('author_id = 5 AND parent_id IS NOT NULL') %>
|
||||
<% memos.each do |m|%>
|
||||
|
||||
<% users = User.all%>
|
||||
<table>
|
||||
<tr>
|
||||
<th>name</th><th>C</th><th>I</th><th>S</th><th>filecount</th><th>issuecount</th><th>level</th>
|
||||
</tr>
|
||||
<% users.each do |user| %>
|
||||
|
||||
|
||||
|
||||
<tr>
|
||||
<% if Memo.find(m.parent_id).author_id != 5 %>
|
||||
<td><%=m.subject%></td>
|
||||
<% end %>
|
||||
</tr>>
|
||||
|
||||
<td><%= user.lastname %><%= user.firstname %></td>
|
||||
<td><%= calculate_collaboration_count(user) %></td>
|
||||
<td><%= calculate_influence_count(user) %></td>
|
||||
<td><%= calculate_skill_count(user) %></td>
|
||||
<td><%= calculate_file(user) %></td>
|
||||
<td><%= calculate_issue(user) %></td>
|
||||
<td><%= calculate_level(user) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
<hr/>
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserScoreControllerTest < ActionController::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue