打分的调整

This commit is contained in:
Wen 2014-04-30 13:51:19 +08:00
parent 37304c1232
commit 90b53a7efb
2 changed files with 99 additions and 39 deletions

View File

@ -54,57 +54,111 @@ module UserScoreHelper
watcher_count = Watcher.where("watchable_type = 'principal' AND watchable_id = ?", user.id).count watcher_count = Watcher.where("watchable_type = 'principal' AND watchable_id = ?", user.id).count
end end
def calculate_skill_count(user) def calculate_skill_count(user)
praise_count = 0 praise_count_l0 = 0
tread_count = 0 praise_count_l1 = 0
praise_count_l2 = 0
tread_count_l0 = 0
tread_count_l1 = 0
tread_count_l2 = 0
issues = Issue.where('author_id = ?', user.id) issues = Issue.where('author_id = ?', user.id)
issues.each do |i| issues.each do |i|
ptcs = PraiseTreadCache.where('object_id = ?', i.id) pts = PraiseTread.where('praise_tread_object_id = ?', i.id)
ptcs.each do |p| pts.each do |p|
praise_count = praise_count + p.praise_num.to_i templevel = calculate_level(User.find(p.user_id))
tread_count = tread_count + p.tread_num.to_i
if templevel.to_i == 0
if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1
else
tread_count_l0 = tread_count_l0 + 1
end
end
if templevel.to_i == 1
if p.praise_or_tread == 1
praise_count_l1 = praise_count_l1 + 1
else
tread_count_l1 = tread_count_l1 + 1
end
end
if templevel.to_i == 2
if p.praise_or_tread == 1
praise_count_l2 = praise_count_l2 + 1
else
tread_count_l2 + tread_count_l2 + 1
end
end
end end
end end
bids = Bid.where('author_id = ?', user.id) bids = Bid.where('author_id = ?', user.id)
bids.each do |b| bids.each do |b|
ptcs = PraiseTreadCache.where('object_id = ?', b.id) ptcs = PraiseTread.where('praise_tread_object_id = ?', b.id)
ptcs.each do |p| ptcs.each do |p|
praise_count = praise_count + p.praise_num.to_i templevel = calculate_level(User.find(p.user_id))
tread_count = tread_count + p.tread_num.to_i
if templevel.to_i == 0
if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1
else
tread_count_l0 = tread_count_l0 + 1
end
end
if templevel.to_i == 1
if p.praise_or_tread == 1
praise_count_l1 = praise_count_l1 + 1
else
tread_count_l1 = tread_count_l1 + 1
end
end
if templevel.to_i == 2
if p.praise_or_tread == 1
praise_count_l2 = praise_count_l2 + 1
else
tread_count_l2 + tread_count_l2 + 1
end
end
end end
end end
contests = Contest.where('author_id = ?', user.id) contests = Contest.where('author_id = ?', user.id)
contests.each do |c| contests.each do |c|
ptcs = PraiseTreadCache.where('object_id = ?', c.id) ptcs = PraiseTread.where('praise_tread_object_id = ?', c.id)
ptcs.each do |p| ptcs.each do |p|
praise_count = praise_count + p.praise_num.to_i templevel = calculate_level(User.find(p.user_id))
tread_count = tread_count + p.tread_num.to_i
if templevel.to_i == 0
if p.praise_or_tread == 1
praise_count_l0 = praise_count_l0 + 1
else
tread_count_l0 = tread_count_l0 + 1
end
end
if templevel.to_i == 1
if p.praise_or_tread == 1
praise_count_l1 = praise_count_l1 + 1
else
tread_count_l1 = tread_count_l1 + 1
end
end
if templevel.to_i == 2
if p.praise_or_tread == 1
praise_count_l2 = praise_count_l2 + 1
else
tread_count_l2 + tread_count_l2 + 1
end
end
end end
end end
level = calculate_level(user)
skill_score = 0
if level == 0
skill_score = praise_count - 2.5 * tread_count
end
if level == 1
skill_score = 2 * praise_count - 1.5 * tread_count
end
if level == 2
skill_socre = 3 * praise_count - 2.5 * tread_count
end
if level == 3
skill_socre = 4 * praise_count - 3.5 * tread_count
end
if level == 4
skill_socre = 5 * praise_count - 4.5 * tread_count
end
# case level # case level
# when 0 skill_score = praise_count - 0.5 * tread_count # when 0 skill_score = praise_count - 0.5 * tread_count
@ -114,12 +168,19 @@ module UserScoreHelper
# when 4 skill_socre = 5 * praise_count - 4.5 * tread_count # when 4 skill_socre = 5 * praise_count - 4.5 * tread_count
# end # end
skill_score = 2 * praise_count_l0.to_f + 3 * praise_count_l1.to_f + 4 * praise_count_l2.to_f
- 1 * tread_count_l0.to_f - 1.5 * tread_count_l1.to_f - 2 * tread_count_l2.to_f
tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count tread_user_count = PraiseTread.where('praise_or_tread = ? AND user_id = ?', 0, user.id).count
skill_score = skill_score - 0.5 * tread_user_count skill_score = skill_score.to_f - tread_user_count.to_f
return skill_score return skill_score

View File

@ -12,14 +12,13 @@
<tr> <tr>
<td><%= user.lastname %><%= user.firstname %></td> <td><%= user.lastname %><%= user.firstname %></td>
<!-- <td><%= calculate_collaboration_count(user) %></td> <td><%= calculate_collaboration_count(user) %></td>
<td><%= calculate_influence_count(user) %></td> <td><%= calculate_influence_count(user) %></td>
<td><%= calculate_skill_count(user) %></td> <td><%= calculate_skill_count(user) %></td>
<td><%= calculate_file(user) %></td> <td><%= calculate_file(user) %></td>
<td><%= calculate_issue(user) %></td> <td><%= calculate_issue(user) %></td>
<td><%= calculate_level(user) %></td>--> <td><%= calculate_level(user) %></td>
<td><%= user.changesets.count %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>