Better statistics

This commit is contained in:
redfast00 2019-06-17 16:15:29 +02:00
parent be466bb4bb
commit d271842529
No known key found for this signature in database
GPG key ID: 5946E0E34FD0553C

View file

@ -10,10 +10,16 @@ class Statistics < Rails::Application
end
def shamehash
none_shaming = total_debt + shameful_users.sum(:balance)
shameful_users.inject({'Reputable users' => none_shaming.to_f / total_debt}) do |h, u|
debt_users = shameful_users.inject({}) do |h, u|
h.merge({u.name => - u.balance.to_f / total_debt * 100.0})
end
.select { |key, value| value > 2 }
.transform_values! { |value| value.floor }
total_displayed_debt_pct = debt_users.values.inject(0) {|a,b| a+b}
debt_users["Other users"] = 100 - total_displayed_debt_pct
debt_users
end
def by_issuer