parent
4de9f959ac
commit
3ba524668f
|
@ -34,11 +34,123 @@ module UserScoreHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_skill_count(user)
|
def calculate_skill_count(user)
|
||||||
0
|
|
||||||
|
praise_count = 0
|
||||||
|
tread_count = 0
|
||||||
|
issues = Issue.where('author_id = ?', user.id)
|
||||||
|
issues.each do |i|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', i.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
praise_count = praise_count + p.praise_num
|
||||||
|
tread_count = tread_count + p.tread_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
bids = Bid.where('author_id = ?', user.id)
|
||||||
|
bids.each do |b|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', b.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
praise_count = praise_count + p.praise_num
|
||||||
|
tread_count = tread_count + p.tread_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
contests = Contest.where('author_id = ?', user.id)
|
||||||
|
contests.each do |c|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', c.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
praise_count = praise_count + p.praise_num
|
||||||
|
tread_count = tread_count + p.tread_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
level = calculate_level(user)
|
||||||
|
|
||||||
|
skill_score = 0
|
||||||
|
|
||||||
|
if level == 0
|
||||||
|
skill_score = praise_count - 0.5 * tread_count
|
||||||
|
elseif level == 1
|
||||||
|
skill_score = 2 * praise_count - 1.5 * tread_count
|
||||||
|
elseif level == 2
|
||||||
|
skill_socre = 3 * praise_count - 2.5 * tread_count
|
||||||
|
elseif level == 3
|
||||||
|
skill_socre = 4 * praise_count - 3.5 * tread_count
|
||||||
|
elseif level == 4
|
||||||
|
skill_socre = 5 * praise_count - 4.5 * tread_count
|
||||||
|
end
|
||||||
|
|
||||||
|
# case level
|
||||||
|
# when 0 skill_score = praise_count - 0.5 * tread_count
|
||||||
|
# when 1 skill_score = 2 * praise_count - 1.5 * tread_count
|
||||||
|
# when 2 skill_socre = 3 * praise_count - 2.5 * tread_count
|
||||||
|
# when 3 skill_socre = 4 * praise_count - 3.5 * tread_count
|
||||||
|
# when 4 skill_socre = 5 * praise_count - 4.5 * tread_count
|
||||||
|
# end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tread_user_count = PraiseTread.where('praise_or_tread = ?, user_id = ?', 0, user.id).count
|
||||||
|
|
||||||
|
skill_score = skill_score - 0.5 * tread_user_count
|
||||||
|
|
||||||
|
return skill_score
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_level(user)
|
def calculate_level(user)
|
||||||
1
|
commit_count = user.changesets.count
|
||||||
|
max_praise_num = 0
|
||||||
|
|
||||||
|
|
||||||
|
issues = Issue.where('author_id = ?', user.id)
|
||||||
|
issues.each do |i|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', i.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
if p.praise_num > max_praise_num
|
||||||
|
max_praise_num = p.praise_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
bids = Bid.where('author_id = ?', user.id)
|
||||||
|
bids.each do |b|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', b.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
if p.praise_num > max_praise_num
|
||||||
|
max_praise_num = p.praise_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
contests = Contest.where('author_id = ?', user.id)
|
||||||
|
contests.each do |c|
|
||||||
|
ptcs = PraiseTreadCache.where('object_id = ?', c.id)
|
||||||
|
ptcs.each do |p|
|
||||||
|
if p.praise_num > max_praise_num
|
||||||
|
max_praise_num = p.praise_num
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
best_answer_num = 0
|
||||||
|
|
||||||
|
level = 0
|
||||||
|
|
||||||
|
if max_praise_num > 4
|
||||||
|
level = 1
|
||||||
|
elseif commit_count > 0 and commit_count < 101
|
||||||
|
level = 1
|
||||||
|
elseif commit_count > 100
|
||||||
|
level = 2
|
||||||
|
end
|
||||||
|
|
||||||
|
return level
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def calculate_activity_count(user)
|
def calculate_activity_count(user)
|
||||||
|
|
|
@ -1,6 +1,13 @@
|
||||||
<h3>test</h3>
|
<h3>test</h3>
|
||||||
<%= debug request %>
|
<% PraiseTreadCache.where('object_id = 47').each do |p| %>
|
||||||
|
<tr>
|
||||||
|
<td><%if p.praise_num < 0 or p.praise_num == 2%>
|
||||||
|
<%= p.praise_num %>
|
||||||
|
<%end%>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<% end %>
|
||||||
<hr/>
|
<hr/>
|
||||||
<%= request.host().class %>
|
|
||||||
<hr/>
|
<hr/>
|
||||||
|
|
26
db/schema.rb
26
db/schema.rb
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140421044830) do
|
ActiveRecord::Schema.define(:version => 20140421091020) do
|
||||||
|
|
||||||
create_table "activities", :force => true do |t|
|
create_table "activities", :force => true do |t|
|
||||||
t.integer "act_id", :null => false
|
t.integer "act_id", :null => false
|
||||||
|
@ -754,6 +754,11 @@ ActiveRecord::Schema.define(:version => 20140421044830) do
|
||||||
add_index "time_entries", ["project_id"], :name => "time_entries_project_id"
|
add_index "time_entries", ["project_id"], :name => "time_entries_project_id"
|
||||||
add_index "time_entries", ["user_id"], :name => "index_time_entries_on_user_id"
|
add_index "time_entries", ["user_id"], :name => "index_time_entries_on_user_id"
|
||||||
|
|
||||||
|
create_table "tmp", :force => true do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.string "part_number"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "tokens", :force => true do |t|
|
create_table "tokens", :force => true do |t|
|
||||||
t.integer "user_id", :default => 0, :null => false
|
t.integer "user_id", :default => 0, :null => false
|
||||||
t.string "action", :limit => 30, :default => "", :null => false
|
t.string "action", :limit => 30, :default => "", :null => false
|
||||||
|
@ -813,6 +818,19 @@ ActiveRecord::Schema.define(:version => 20140421044830) do
|
||||||
|
|
||||||
add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id"
|
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", :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
|
||||||
|
t.integer "level"
|
||||||
|
t.integer "file"
|
||||||
|
t.integer "issue"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "user_statuses", :force => true do |t|
|
create_table "user_statuses", :force => true do |t|
|
||||||
t.integer "changesets_count"
|
t.integer "changesets_count"
|
||||||
t.integer "watchers_count"
|
t.integer "watchers_count"
|
||||||
|
@ -947,4 +965,10 @@ ActiveRecord::Schema.define(:version => 20140421044830) do
|
||||||
add_index "workflows", ["role_id", "tracker_id", "old_status_id"], :name => "wkfs_role_tracker_old_status"
|
add_index "workflows", ["role_id", "tracker_id", "old_status_id"], :name => "wkfs_role_tracker_old_status"
|
||||||
add_index "workflows", ["role_id"], :name => "index_workflows_on_role_id"
|
add_index "workflows", ["role_id"], :name => "index_workflows_on_role_id"
|
||||||
|
|
||||||
|
create_table "yans", :force => true do |t|
|
||||||
|
t.string "name"
|
||||||
|
t.datetime "created_at", :null => false
|
||||||
|
t.datetime "updated_at", :null => false
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue