新得分显示

This commit is contained in:
z9hang 2014-06-16 17:50:28 +08:00
parent 47e6c3eedd
commit 697a6034b2
16 changed files with 198 additions and 35 deletions

View File

@ -74,19 +74,11 @@ GEM
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.8.2)
mime-types (1.23)
multi_json (1.7.6)
mysql2 (0.3.11-x86-mingw32)
net-ldap (0.3.1)
polyglot (0.3.3)
pry (0.9.12.6-x86-mingw32)
coderay (~> 1.0)
method_source (~> 0.8)
slop (~> 3.4)
win32console (~> 1.3)
pry-nav (0.2.3)
pry (~> 0.9.10)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
@ -121,7 +113,6 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
slop (3.5.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
@ -136,7 +127,6 @@ GEM
uglifier (1.0.3)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
win32console (1.3.2-x86-mingw32)
PLATFORMS
x86-mingw32
@ -154,8 +144,6 @@ DEPENDENCIES
jquery-rails (~> 2.0.2)
mysql2 (~> 0.3.11)
net-ldap (~> 0.3.1)
pry
pry-nav
rack-mini-profiler!
rack-openid
rails (= 3.2.13)

View File

@ -32,12 +32,14 @@ class UsersController < ApplicationController
before_filter :require_admin, :except => [:show, :index, :search, :tag_save, :tag_saveEx,:user_projects, :user_newfeedback, :user_comments, :watch_bids, :watch_contests, :info,
:user_watchlist, :user_fanslist,:update, :user_courses, :user_homeworks, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
#edit has been deleted by huang, 2013-9-23
before_filter :find_user, :only => [:user_fanslist, :user_watchlist, :show, :edit, :update, :destroy, :edit_membership, :user_courses,
:user_homeworks, :destroy_membership, :user_activities, :user_projects, :user_newfeedback, :user_comments,
:watch_bids, :watch_contests, :info, :watch_projects, :show_score, :topic_score_index, :project_score_index,
:activity_score_index, :influence_score_index, :score_index]
:activity_score_index, :influence_score_index, :score_index,:show_new_score, :topic_new_score_index, :project_new_score_index,
:activity_new_score_index, :influence_new_score_index, :score_new_index]
before_filter :auth_user_extension, only: :show
accept_api_auth :index, :show, :create, :update, :destroy,:tag_save , :tag_saveEx
@ -94,6 +96,10 @@ class UsersController < ApplicationController
def show_score
end
def show_new_score
end
# end
##added by fq
@ -767,7 +773,25 @@ class UsersController < ApplicationController
end
# end
def topic_new_score_index
end
def project_new_score_index
end
def activity_new_score_index
end
def influence_new_score_index
end
def score_new_index
end
private
def find_user

View File

@ -160,7 +160,7 @@ class Journal < ActiveRecord::Base
#新建了缺陷留言且留言不为空,不为空白
if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分加分
UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:post_issue_message, User.current,self.issue.author, { message_id: self.id })
end
end
# 减少用户分数 -by zjc
@ -168,7 +168,7 @@ class Journal < ActiveRecord::Base
#删除有效缺陷留言
if !self.notes.nil? && self.notes.gsub(' ','') != ''
#协同得分减分
UserScore.joint(:delete_issue, User.current,self.issue.author, { message_id: self.id })
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
end
end
end

View File

@ -60,11 +60,11 @@ class UserScore < ActiveRecord::Base
user_score.collaboration = user_score.collaboration.to_i - 2
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})"
when :post_issue # current_user 对 target_user 的缺陷留言了 Add Journal
when :post_issue_message # current_user 对 target_user 的缺陷留言了 Add Journal
user_score.collaboration = user_score.collaboration.to_i + 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})"
when :delete_issue # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal
when :delete_issue_message # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal
user_score.collaboration = user_score.collaboration.to_i - 1
user_score.save
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})"
@ -204,19 +204,19 @@ class UserScore < ActiveRecord::Base
user_score = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})"
when :push_document # current_user
when :push_document # current_user 提交了文档 document
user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})"
when :push_file # current_user
when :push_file # current_user 提交了附件 attachment
user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})"
when :update_issue_ratio # current_user
when :update_issue_ratio # current_user 更新了缺陷完成度 issue
user_score.active = user_score.active.to_i + 2
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})"
when :post_issue # current_user
when :post_issue # current_user 发布了缺陷 issue
user_score.active = user_score.active.to_i + 4
user_score.save
Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})"
@ -228,6 +228,12 @@ class UserScore < ActiveRecord::Base
Rails.logger.error "[UserScore#project] ===> Exception: #{e}."
end
#计算总得分
def total_score
score = self.influence.to_i + self.skill.to_i + self.collaboration.to_i + self.active.to_i
score
end
private
def self.get_users(current_user, target_user)

View File

@ -95,14 +95,22 @@
<tr><td class="score">
<%= l(:label_user_grade)%>:
<%= link_to(format("%.2f" , finall_user_score).to_f, {:controller => 'users',
:action => 'show_score',
<%= link_to(format("%.2f" , @user.user_score.total_score).to_f, {:controller => 'users',
:action => 'show_new_score',
:remote => true,
:id => @user.id
}, :style => 'color :#E8770D;') %>
</td>
</tr>
<tr><td class="score">
<%= l(:label_user_grade)%>:
<%= link_to(format("%.2f" , finall_user_score).to_f, {:controller => 'users',
:action => 'show_score',
:remote => true,
:id => @user.id
}, :style => 'color :#E8770D;') %>
</td>
</tr>
<!-- end -->
</table></td>

View File

@ -25,10 +25,10 @@
<% finall_user_score = finall_messages_score + finall_user_project_score + finall_activity_score + finall_influence_score %>
<div><%= l(:label_user_score) %></div>
<div> = <%= l(:label_user_score_of_topic) %> + <%= l(:label_user_score_of_project) %> +
<%= l(:label_user_score_of_activity)%> + <%= l(:label_user_score_of_influence) %></div>
<div> = <%= l(:label_user_score_of_topic) %> + <%= l(:label_user_score_of_project) %> +
<%= l(:label_user_score_of_activity)%> + <%= l(:label_user_score_of_influence) %></div>
<!-- <div>&nbsp;&nbsp;&nbsp;+ <%= l(:label_user_score_of_influence) %></div> -->
<div> = <%= format("%.2f" , finall_messages_score).to_f %> + <%= format("%.2f" , finall_user_project_score).to_f %> +
<%= format("%.2f" , finall_activity_score).to_f %> + <%= format("%.2f" , finall_influence_score).to_f %></div>
<%= format("%.2f" , finall_activity_score).to_f %> + <%= format("%.2f" , finall_influence_score).to_f %></div>
<div> = <%= format("%.2f" , finall_user_score).to_f %></div>
<!-- end -->

View File

@ -0,0 +1,34 @@
<!-- added by bai -->
<% messages_count = @user.messages.count %>
<% messages_score = messages_count * 0.05%>
<% finall_messages_score = messages_score %>
<% journals_count = @user.journals.count %>
<% journals_score = journals_count * 0.1 %>
<% user_changesets_count = @user.changesets.count %>
<% user_changesets_score = user_changesets_count * 0.3 %>
<% finall_user_project_score = journals_score + user_changesets_score %>
<% journals_for_messages_count = @user.journals_messages.count %>
<% activities_count = @user.activities.count %>
<% journals_for_messages_score = journals_for_messages_count * 0.05 %>
<% activities_score = activities_count * 0.2 %>
<% finall_activity_score = journals_for_messages_score + activities_score %>
<% news_count = @user.news.count %>
<% news_score = news_count * 0.1 %>
<% wiki_contents_count = @user.wiki_contents.count %>
<% wiki_contents_score = wiki_contents_count * 0.1 %>
<% comments_count = @user.comments.count %>
<% comments_score = comments_count * 0.1 %>
<% finall_influence_score = news_score + wiki_contents_score + comments_score %>
<% finall_user_score = finall_messages_score + finall_user_project_score + finall_activity_score + finall_influence_score %>
<div><%= l(:label_user_score) %></div>
<div> = <%= l(:label_user_score_of_collaboration) %> + <%= l(:label_user_score_of_influence) %> +
<%= l(:label_user_score_of_skill)%> + <%= l(:label_user_score_of_active) %></div>
<!-- <div>&nbsp;&nbsp;&nbsp;+ <%= l(:label_user_score_of_influence) %></div> -->
<div> = <%= format("%.2f" ,@user.user_score.collaboration.nil? ? 0:@user.user_score.collaboration).to_f %> + <%= format("%.2f" , @user.user_score.influence.nil? ? 0:@user.user_score.influence ).to_f %>
+ <%= format("%.2f" , @user.user_score.skill.nil? ? 0:@user.user_score.skill).to_f %> + <%= format("%.2f" , @user.user_score.active.nil? ? 0:@user.user_score.active).to_f %></div>
<div> = <%= format("%.2f" ,@user.user_score.total_score.nil? ? 0:@user.user_score.total_score).to_f %></div>
<!-- end -->

View File

@ -0,0 +1,76 @@
<!-- added by bai -->
<% messages_count = @user.messages.count %>
<% messages_score = messages_count * 0.05%>
<% finall_messages_score = messages_score %>
<% journals_count = @user.journals.count %>
<% journals_score = journals_count * 0.1 %>
<% user_changesets_count = @user.changesets.count %>
<% user_changesets_score = user_changesets_count * 0.3 %>
<% finall_user_project_score = journals_score + user_changesets_score %>
<% journals_for_messages_count = @user.journals_messages.count %>
<% activities_count = @user.activities.count %>
<% journals_for_messages_score = journals_for_messages_count * 0.05 %>
<% activities_score = activities_count * 0.2 %>
<% finall_activity_score = journals_for_messages_score + activities_score %>
<% news_count = @user.news.count %>
<% news_score = news_count * 0.1 %>
<% wiki_contents_count = @user.wiki_contents.count %>
<% wiki_contents_score = wiki_contents_count * 0.1 %>
<% comments_count = @user.comments.count %>
<% comments_score = comments_count * 0.1 %>
<% finall_influence_score = news_score + wiki_contents_score + comments_score %>
<% finall_user_score = finall_messages_score + finall_user_project_score + finall_activity_score + finall_influence_score %>
<h3 class="title"><%= l(:label_user_score) %></h3>
<div class="inf_user_image">
<table style="border-bottom: solid 1px #80a6d2;" width="100%">
<tr>
<td align="left" valign="middle" ><%= image_tag(url_to_avatar(@user), :class => 'avatar2') %></td>
<td width="35%">
<table>
<tr class="info_font" align="center" style=" word-wrap: break-word; word-break: break-all"><td><%= h @user.name %></td></tr>
<tr class="info_font" align="left" style=" word-wrap: break-word; word-break: break-all"><td><%= @user.user_extensions.show_identity %></td></tr>
</table>
</td>
<td>
<table>
<tr class="info_font"><td><%= l(:label_user_score) %></td></tr>
<tr class="buttons_for_score" style="margin-top:30px;margin-left:144px"><td><span style="color:#ec6300"><%= format("%.2f" , @user.user_score.total_score).to_f %></span></td></tr>
</table>
</td>
</tr>
</table>
<table style="border-bottom: solid 0px #80a6d2;" width="100%">
<tr>
<%= link_to l(:label_user_score), {:controller => 'users', :action => 'score_new_index', :remote => true} %> :
<%= format("%.2f" , @user.user_score.total_score).to_f %>
</tr><br>
<tr>
<%= link_to l(:label_user_score_of_collaboration), {:controller => 'users', :action => 'topic_new_score_index', :remote => true} %> :
<%= format("%.2f" , @user.user_score.collaboration.nil? ? 0:@user.user_score.collaboration).to_f %>
</tr><br>
<tr>
<%= link_to l(:label_user_score_of_influence), {:controller => 'users', :action => 'project_new_score_index', :remote => true} %> :
<%= format("%.2f" , @user.user_score.influence.nil? ? 0:@user.user_score.influence).to_f %>
</tr><br>
<tr>
<%= link_to l(:label_user_score_of_skill), {:controller => 'users', :action => 'activity_new_score_index', :remote => true} %> :
<%= format("%.2f" , @user.user_score.skill.nil? ? 0:@user.user_score.skill).to_f %>
</tr><br>
<tr>
<%= link_to l(:label_user_score_of_active), {:controller => 'users', :action => 'influence_new_score_index', :remote => true} %>
<%= format("%.2f" , @user.user_score.active.nil? ? 0:@user.user_score.active).to_f %>
</tr><br>
</table>
</div>
<div id="show_score_detail" style="padding-left: 6px">
<%= render :partial => 'users/score_new_index', :locals => {:index => 0 } %>
</div>

View File

@ -0,0 +1,6 @@
<div>协同得分:</div>
<div>&nbsp;&nbsp;&nbsp; 发帖 +2</div>
<div>&nbsp;&nbsp;&nbsp; 对缺陷留言 +1</div>
<div>&nbsp;&nbsp;&nbsp; 更改一次缺陷状态 +1</div>
<div>&nbsp;&nbsp;&nbsp; 对留言的回复 +1</div>
<div>&nbsp;&nbsp;&nbsp; 对帖子的回复 +1</div>

View File

@ -0,0 +1,3 @@
<!-- added by bai -->
$('#show_score_detail').html('<%= escape_javascript(render :partial => 'users/score_new_index', :locals => {:index =>0 }) %>');
<!-- end -->

View File

@ -0,0 +1,3 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'users/show_new_score') %>');
showModal('ajax-modal', '400px');
$('#ajax-modal').addClass('new-watcher');

View File

@ -0,0 +1,3 @@
<!-- added by bai -->
$('#show_score_detail').html('<%= escape_javascript(render :partial => 'users/topic_new_score_index', :locals => {:index =>0 }) %>');
<!-- end -->

View File

@ -1677,6 +1677,9 @@ zh:
label_user_score_of_project: 项目得分
label_user_score_of_activity: 活跃度得分
label_user_score_of_influence: 影响力得分
label_user_score_of_collaboration: 协同得分
label_user_score_of_skill: 技术得分
label_user_score_of_active: 项目贡献得分
label_question_top: 问题被顶次数
label_question_down: 问题被踩次数
label_answer_top: 回答被顶次数

View File

@ -232,6 +232,13 @@ RedmineApp::Application.routes.draw do
match 'influence_score_index', :to => 'users#influence_score_index', :via => :get
match 'score_index', :to => 'users#score_index', :via => :get
match 'show_new_score', :to => 'users#show_new_score', :via => :get
match 'topic_new_score_index', :controller => 'users', :action => 'topic_new_score_index', :via => [:get, :post]
match 'project_new_score_index', :to => 'users#project_new_score_index', :via => :get
match 'activity_new_score_index', :to => 'users#activity_new_score_index', :via => :get
match 'influence_new_score_index', :to => 'users#influence_new_score_index', :via => :get
match 'score_new_index', :to => 'users#score_new_index', :via => :get
match 'show_projects_score', :to => 'projects#show_projects_score', :via => [:get, :post]
match 'issue_score_index', :to => 'projects#issue_score_index', :via => [:get, :post]
match 'news_score_index', :to => 'projects#news_score_index', :via => [:get, :post]

View File

@ -924,11 +924,13 @@ ActiveRecord::Schema.define(:version => 20140609061903) do
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
create_table "user_scores", :force => true do |t|
t.integer "user_id"
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "activity"
t.integer "user_id", :null => false
t.integer "collaboration"
t.integer "influence"
t.integer "skill"
t.integer "active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "user_statuses", :force => true do |t|

View File

@ -20,7 +20,7 @@ namespace :user_score do
Journal.includes(:user).all.each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
end
puts ":post_issue 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|