Merge pull request #15 from rjsamson/avg-karma
show average karma in user profile
This commit is contained in:
commit
ec7389d9a0
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Reference in a new issue