39 lines
905 B
Ruby
39 lines
905 B
Ruby
|
|
class Statistics < Rails::Application
|
|
|
|
def shameful_users
|
|
User.humans
|
|
.where('-balance > :amount', amount: config.shameful_balance)
|
|
.order(:balance)
|
|
end
|
|
|
|
def total_debt
|
|
-User.humans.where('balance < 0').sum(:balance)
|
|
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|
|
|
h.merge({u.name => - u.balance.to_f / total_debt})
|
|
end
|
|
end
|
|
|
|
def by_issuer
|
|
Client.joins(:issued_transactions).group(:name).count.merge({
|
|
"User created" => Transaction.where(issuer_type: "User").count
|
|
})
|
|
end
|
|
|
|
def amount_distribution
|
|
Transaction.group("round(amount / 1000.0, 2)").count.inject(Hash.new) do |hash, (group, count)|
|
|
hash.merge({10 * group.to_i => count})
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def zeus_balance
|
|
User.zeus.balance
|
|
end
|
|
|
|
end
|