Merge pull request #15 from rjsamson/avg-karma

show average karma in user profile
This commit is contained in:
joshua stein 2012-09-07 11:06:26 -07:00
commit ec7389d9a0
2 changed files with 9 additions and 1 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

@ -21,7 +21,7 @@
<label class="required">Karma:</label>
<span class="d">
<%= @showing_user.karma %>
<%= @showing_user.karma %> (average <%= number_with_precision(@showing_user.average_karma, :precision => 2) %>)
</span>
<br>