Skip to content

Commit

Permalink
Better statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
redfast00 committed Jun 17, 2019
1 parent be466bb commit d271842
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/concerns/statistics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ def total_debt
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
Expand Down

0 comments on commit d271842

Please sign in to comment.