tab/app/controllers/concerns/statistics.rb

34 lines
845 B
Ruby
Raw Normal View History

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
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 * 100.0})
end
end
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
})
end
2015-09-17 18:23:21 +02:00
def creation_counts
User
.joins(:issued_transactions)
.group(:name)
.order("count_all DESC")
.count
.take([shameful_users.count, 4].max)
end
2015-09-11 18:04:45 +02:00
end