diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb index cb28f4e6..0623dbee 100644 --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -1,4 +1,6 @@ class TestController < ApplicationController + + helper :UserScore def zip homeworks_attach_path = [] diff --git a/app/controllers/user_score_controller.rb b/app/controllers/user_score_controller.rb new file mode 100644 index 00000000..875229e8 --- /dev/null +++ b/app/controllers/user_score_controller.rb @@ -0,0 +1,6 @@ +class UserScoreController < ApplicationController + helper :UserScoreHelper + + + +end diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 4c9a126f..5b455a01 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 1809c3a9..20624888 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/test/index.html.erb b/app/views/test/index.html.erb index 43101bb4..5b435085 100644 --- a/app/views/test/index.html.erb +++ b/app/views/test/index.html.erb @@ -1,15 +1,26 @@

test

-<% memos=Memo.where('author_id = 5 AND parent_id IS NOT NULL') %> -<% memos.each do |m|%> + +<% users = User.all%> + + + + +<% users.each do |user| %> + + - <% if Memo.find(m.parent_id).author_id != 5 %> - - <% end %> -> - + + + + + + + + <% end %> +
nameCISfilecountissuecountlevel
<%=m.subject%>
<%= user.lastname %><%= user.firstname %><%= calculate_collaboration_count(user) %><%= calculate_influence_count(user) %><%= calculate_skill_count(user) %><%= calculate_file(user) %><%= calculate_issue(user) %><%= calculate_level(user) %>

diff --git a/test/functional/user_score_controller_test.rb b/test/functional/user_score_controller_test.rb new file mode 100644 index 00000000..bf56a207 --- /dev/null +++ b/test/functional/user_score_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserScoreControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end