From 24f8050ac95db260959014cd52344370d53542dd Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Fri, 11 Sep 2015 23:32:38 +0200 Subject: [PATCH] implement simple wall of shame --- app/controllers/concerns/statistics.rb | 6 +++++- app/views/pages/landing.html.haml | 14 +++++++++++--- config/application.rb | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/statistics.rb b/app/controllers/concerns/statistics.rb index 1d571c0..166dddb 100644 --- a/app/controllers/concerns/statistics.rb +++ b/app/controllers/concerns/statistics.rb @@ -3,7 +3,11 @@ class Statistics < Rails::Application def shameful_users User.where('balance > :amount', amount: config.shameful_balance) - .order(:balance) + .order(balance: :desc) + end + + def total_debt + User.where.not(id: User.zeus).where('balance > 0').sum(:balance) end private diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 4f4fcb0..7a78101 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -8,6 +8,14 @@ %h2 Cute Little Statistics %p None here yet. %h2 Wall of Shame -%ul - - @statistics.shameful_users.each do |user| - %li="Shame on #{user.name}!" +%table + %thead + %th People who should be ashamed + %th Part of total debt to Zeus + %tbody + - @statistics.shameful_users.each do |user| + %tr + %td= "Shame on #{user.name}" + // Won't divide by zero because there won't be any users with + // a shameful debt if the total debt is zero. + %td= "#{100 * user.balance / @statistics.total_debt}%" diff --git a/config/application.rb b/config/application.rb index c611175..5525edd 100644 --- a/config/application.rb +++ b/config/application.rb @@ -24,6 +24,6 @@ module Tab config.active_record.raise_in_transactional_callbacks = true # Which is the lowest balance you should be ashamed of. - config.shameful_balance = 50 + config.shameful_balance = 50 # In eurocents! end end