This commit is contained in:
sw 2014-06-26 17:55:18 +08:00
commit 745727b8e7
9 changed files with 338 additions and 13 deletions

View File

@ -120,7 +120,7 @@ class AttachmentsController < ApplicationController
end
if @attachment.container
# Make sure association callbacks are called
@attachment.container.def attachments.delete(@attachment)
@attachment.container.attachments.delete(@attachment)
else
@attachment.destroy
end

View File

@ -918,11 +918,13 @@ class ProjectsController < ApplicationController
# added by bai
def show_projects_score
render :layout => false
end
def issue_score_index
respond_to do |format|
format.js
end
end
def news_score_index

View File

@ -98,7 +98,7 @@ class UsersController < ApplicationController
end
def show_new_score
render :layout => false
end
# end

View File

@ -98,7 +98,9 @@ class Changeset < ActiveRecord::Base
end
def project
repository.project
unless repository.nil?
repository.project
end
end
def author

View File

@ -28,7 +28,7 @@
<h3 class="title"><%= l(:label_projects_score) %></h3>
<div class="inf_user_image">
<table style="border-bottom: solid 1px #80a6d2;", width="100%">
<table style="border-bottom: solid 1px #80a6d2;" width="100%">
<tr>
<td align="left" valign="middle" ><%= image_tag(url_to_avatar(@project), :class => 'avatar2') %></td>
<td>

View File

@ -0,0 +1,97 @@
<!-- added by bai -->
<% issue_count = @project.issues.count %>
<% issue_journal_count = @project.issue_changes.count %>
<% issue_score = issue_count * 0.2 %>
<% issue_journal_score = issue_journal_count * 0.1 %>
<% finall_issue_score = issue_score + issue_journal_score %>
<% new_count = @project.news.count %>
<% new_score = new_count * 0.1 %>
<% finall_new_score = new_score %>
<% document_count = @project.documents.count %>
<% file_score = document_count * 0.1 %>
<% finall_file_score = file_score %>
<% changeset_count = @project.changesets.count %>
<% code_submit_score = changeset_count * 0.3 %>
<% finall_code_submit_score = code_submit_score %>
<% board_message_count = 0 %>
<% @project.boards.each do |board| %>
<% board_message_count += board.messages_count %>
<% end %>
<% topic_score = board_message_count * 0.1 %>
<% finall_topic_score = topic_score %>
<% finall_project_score = finall_issue_score + finall_new_score + finall_file_score + finall_code_submit_score + topic_score %>
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= hubspot_head %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
</head>
<h3 class="title"><%= l(:label_projects_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(@project), :class => 'avatar2') %></td>
<td>
<table>
<tr class="info_font" align="center" style=" word-wrap: break-word; word-break: break-all"><td><%= @project.name %></td>
</tr>
</table>
</td>
<td width="35%">
<table>
<tr class="info_font"><td><%= l(:label_projects_score) %></td></tr>
<tr class="buttons_for_score" style="margin-top:30px;margin-left:144px"><td><span style="color:#ec6300"><%= format("%.2f" , finall_project_score ).to_f %></span></td></tr>
</table>
</td>
</tr>
</table>
</div>
<div class="tabs_new">
<ul>
<li>
<%= link_to l(:label_projects_score), {:controller => 'projects', :action => 'show_projects_score', :remote => true}%> :
<%= format("%.2f" , finall_project_score ).to_f %>
</li>
<li>
<%= link_to l(:label_issue_score), {:controller => 'projects', :action => 'issue_score_index', :remote => true}%> :
<%= format("%.2f" , finall_issue_score).to_f %>
</li>
<li>
<%= link_to l(:label_news_score), {:controller => 'projects', :action => 'news_score_index', :remote => true}%> :
<%= format("%.2f" , finall_new_score).to_f %>
</li>
<li>
<%= link_to l(:label_file_score), {:controller => 'projects', :action => 'file_score_index', :remote => true}%> :
<%= format("%.2f" , finall_file_score).to_f %>
</li>
<li>
<%= link_to l(:label_code_submit_score), {:controller => 'projects', :action => 'code_submit_score_index', :remote => true}%> :
<%= format("%.2f" , finall_code_submit_score).to_f %>
</li>
<li>
<%= link_to l(:label_topic_score), {:controller => 'projects', :action => 'projects_topic_score_index', :remote => true}%> :
<%= format("%.2f" , finall_topic_score).to_f %>
</li>
</ul>
</div>
<div id="show_score_detail">
<%= render :partial => 'projects/project_score_index', :locals => {:index => 0 } %>
</div>
<!-- end -->

View File

@ -0,0 +1,91 @@
<!-- 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 %>
<head>
<meta charset="utf-8" />
<title><%= h html_title %></title>
<meta name="description" content="<%= Redmine::Info.app_name %>" />
<meta name="keywords" content="issue,bug,tracker" />
<%= csrf_meta_tag %>
<%= favicon %>
<%= stylesheet_link_tag 'jquery/jquery-ui-1.9.2', 'application', 'nyan', :media => 'all' %>
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
<%= javascript_heads %>
<%= heads_for_theme %>
<%= hubspot_head %>
<%= call_hook :view_layouts_base_html_head %>
<!-- page specific tags -->
<%= yield :header_tags -%>
</head>
<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_attr.total_score).to_f %></span></td></tr>
</table>
</td>
</tr>
</table>
<table style="border-bottom: solid 0px #80a6d2;" width="100%">
<tr>
<%= l(:label_user_score) %> :
<%= format("%.2f" , @user.user_score_attr.total_score).to_f %>
</tr><br>
<tr>
<%= l(:label_user_score_of_collaboration) %> :
<%= format("%.2f" , @user.user_score_attr.collaboration.nil? ? 0:@user.user_score_attr.collaboration).to_f %>
</tr><br>
<tr>
<%= l(:label_user_score_of_influence) %> :
<%= format("%.2f" , @user.user_score_attr.influence.nil? ? 0:@user.user_score_attr.influence).to_f %>
</tr><br>
<tr>
<%= l(:label_user_score_of_skill) %> :
<%= format("%.2f" , @user.user_score_attr.skill.nil? ? 0:@user.user_score_attr.skill).to_f %>
</tr><br>
<tr>
<%= l(:label_user_score_of_active) %>
<%= format("%.2f" , @user.user_score_attr.active.nil? ? 0:@user.user_score_attr.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

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20140626012511) do
ActiveRecord::Schema.define(:version => 20140617013146) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -374,13 +374,12 @@ ActiveRecord::Schema.define(:version => 20140626012511) do
create_table "homework_attaches", :force => true do |t|
t.integer "bid_id"
t.integer "user_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "reward"
t.string "name"
t.string "description"
t.integer "state"
t.integer "project_id", :default => 0
end
create_table "homework_for_courses", :force => true do |t|

View File

@ -11,21 +11,48 @@ namespace :user_score do
puts "loading..."
# collaboration 协同得分
users = {}
grades = {}
# 发帖
Message.includes(:author).where("parent_id IS NULL").all.each do |m|
users[m.author.id] = users[m.author.id].to_i + 2
project = m.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id => m.author.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 2
end
end
puts ":post_message calculate Completed. collaboration users count: #{users.count}"
# 对缺陷的留言
Journal.includes(:user).all.each do |j|
users[j.user.id] = users[j.user.id].to_i + 1
project = j.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 1
end
end
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|
users[j.user.id] = users[j.user.id].to_i + 1
project = j.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 1
end
end
puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}"
@ -38,6 +65,14 @@ namespace :user_score do
# 对帖子的回复
Message.includes(:author).where("parent_id IS NOT NULL").each do |m|
users[m.author.id] = users[m.author.id].to_i + 1
project = m.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>m.author.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 1
end
end
puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
@ -76,24 +111,74 @@ namespace :user_score do
end
target_user = obj.author
level = UserLevels.get_level(pt.user)#pt.user.get_level
project = pt.project
if pt.praise_or_tread == 0
#踩帖
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(pt.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>pt.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i - 2
end
if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i - 2
end
elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i - 4
end
elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i - 6
end
end
elsif pt.praise_or_tread == 1
#顶贴
if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 6
end
elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 8
end
end
end
end
@ -114,6 +199,14 @@ namespace :user_score do
next
end
users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4
project = changeset.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(changeset.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>changeset.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
end
puts ":push_code calculate Completed. active users count: #{users_active.count}"
#提交文档
@ -122,6 +215,14 @@ namespace :user_score do
next
end
users_active[document.user.id] = users_active[document.user.id].to_i + 4
project = document.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(document.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>document.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
end
puts ":push_document calculate Completed. active users count: #{users_active.count}"
#提交附件
@ -134,6 +235,17 @@ namespace :user_score do
next
end
users_active[attachment.author.id] = users_active[attachment.author.id].to_i + 4
if attachment.container.class.to_s == "Project"
project = attachment.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(attachment.author.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>attachment.author.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
end
# end
#end
end
@ -141,11 +253,27 @@ namespace :user_score do
#更新完成度
Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio'").each do |j|
users_active[j.user.id] = users_active[j.user.id].to_i + 2
project = j.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>j.user.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
end
puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}"
#发布缺陷
Issue.includes(:author).all.each do |issue|
users_active[issue.author.id] = users_active[issue.author.id].to_i + 4
project = issue.project
unless project.nil?
user_grade = UserGrade.find_by_user_id_and_project_id(issue.author.id, project.id)
if user_grade.nil?
user_grade = UserGrade.create(:user_id =>issue.author.id, :project_id => project.id)
end
grades[user_grade.id] = grades[user_grade.id].to_i + 4
end
end
puts ":post_issue calculate Completed. active users count: #{users_active.count}"
@ -156,8 +284,14 @@ namespace :user_score do
end
end
puts "=== UserScore#active calculate Completed. active users count: #{users_active.count}"
puts ""
UserGrade.transaction do
grades.each do |grade_id,score|
grade = UserGrade.find(grade_id)
grade.grade = score
grade.save
end
end
puts "=== UserGrid calculate Completed. UserGrids count: #{grades.count}"
end
end