diff --git a/app/models/user.rb b/app/models/user.rb index 2040e29..2218733 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 8d98567..a47ccbf 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -25,6 +25,12 @@
+ + + <%= number_with_precision(@showing_user.average_karma, :precision => 2) %> + +
+ <%=