Add average karma to user profiles
This commit is contained in:
parent
ea143e6fbb
commit
6554983fd7
|
@ -56,6 +56,14 @@ class User < ActiveRecord::Base
|
||||||
Keystore.value_for("user:#{self.id}:karma").to_i
|
Keystore.value_for("user:#{self.id}:karma").to_i
|
||||||
end
|
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
|
def stories_submitted_count
|
||||||
Keystore.value_for("user:#{self.id}:stories_submitted").to_i
|
Keystore.value_for("user:#{self.id}:stories_submitted").to_i
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
</span>
|
</span>
|
||||||
<br>
|
<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>
|
<label class="required">Stories Submitted:</label>
|
||||||
<span class="d">
|
<span class="d">
|
||||||
<a href="/newest/<%= @showing_user.username %>"><%=
|
<a href="/newest/<%= @showing_user.username %>"><%=
|
||||||
|
|
Loading…
Reference in a new issue