Skip to content

Commit

Permalink
Add average karma to user profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsamson committed Sep 7, 2012
1 parent ea143e6 commit 6554983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def karma
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
Expand Down
6 changes: 6 additions & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>"><%=
Expand Down

0 comments on commit 6554983

Please sign in to comment.