Add average karma to user profiles

This commit is contained in:
Robert J Samson 2012-09-07 13:25:59 -04:00
parent ea143e6fbb
commit 6554983fd7
2 changed files with 14 additions and 0 deletions

View file

@ -56,6 +56,14 @@ class User < ActiveRecord::Base
Keystore.value_for("user:#{self.id}:karma").to_i
end
def average_karma
if self.karma == 0
0
else
self.karma.to_f / (self.stories_submitted_count + self.comments_posted_count)
end
end
def stories_submitted_count
Keystore.value_for("user:#{self.id}:stories_submitted").to_i
end

View file

@ -25,6 +25,12 @@
</span>
<br>
<label class="required">Average Karma:</label>
<span class="d">
<%= number_with_precision(@showing_user.average_karma, :precision => 2) %>
</span>
<br>
<label class="required">Stories Submitted:</label>
<span class="d">
<a href="/newest/<%= @showing_user.username %>"><%=