2015-09-11 18:04:45 +02:00
|
|
|
|
|
|
|
class Statistics < Rails::Application
|
|
|
|
|
|
|
|
def shameful_users
|
2015-09-14 17:21:53 +02:00
|
|
|
User.humans
|
|
|
|
.where('-balance > :amount', amount: config.shameful_balance)
|
|
|
|
.order(:balance)
|
2015-09-11 23:32:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def total_debt
|
2015-09-14 17:21:53 +02:00
|
|
|
-User.humans.where('balance < 0').sum(:balance)
|
2015-09-11 18:04:45 +02:00
|
|
|
end
|
|
|
|
|
2015-09-12 00:17:43 +02:00
|
|
|
def shamehash
|
2015-09-14 17:21:53 +02:00
|
|
|
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})
|
2015-09-12 00:17:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-12 00:55:23 +02:00
|
|
|
def by_issuer
|
2015-09-14 16:17:01 +02:00
|
|
|
Client.joins(:issued_transactions).group(:name).count.merge({
|
|
|
|
"User created" => Transaction.where(issuer_type: "User").count
|
|
|
|
})
|
2015-09-12 00:55:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def amount_distribution
|
2015-09-14 17:21:53 +02:00
|
|
|
Transaction.group("round(amount / 1000.0, 2)").count.inject(Hash.new) do |hash, (group, count)|
|
2015-09-12 00:55:23 +02:00
|
|
|
hash.merge({10 * group.to_i => count})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 18:04:45 +02:00
|
|
|
private
|
|
|
|
|
|
|
|
def zeus_balance
|
|
|
|
User.zeus.balance
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|