add shamepie -- the big slices are really gross!

This commit is contained in:
Felix Van der Jeugt 2015-09-12 00:17:43 +02:00
parent eb2c85aa9f
commit c9010f59ee
4 changed files with 27 additions and 11 deletions

View File

@ -35,6 +35,8 @@ gem 'jquery-datatables-rails'
# Use Select2 for selecting users
gem 'select2-rails'
# Chartkick for fancy graphs
gem 'chartkick'
# Use jquery as the JavaScript library
gem 'jquery-rails'

View File

@ -70,6 +70,7 @@ GEM
capistrano-rbenv (2.0.3)
capistrano (~> 3.1)
sshkit (~> 1.3)
chartkick (1.3.2)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
@ -296,6 +297,7 @@ DEPENDENCIES
capistrano-passenger
capistrano-rails (~> 1.1)
capistrano-rbenv
chartkick
coffee-rails (~> 4.1.0)
coveralls
devise

View File

@ -10,6 +10,13 @@ class Statistics < Rails::Application
User.where.not(id: User.zeus).where('balance > 0').sum(:balance)
end
def shamehash
none_shaming = shameful_users.sum(:balance)
shameful_users.inject({'None-shameful users' => none_shaming}) do |h, u|
h.merge({u.name => u.balance})
end
end
private
def zeus_balance

View File

@ -8,14 +8,19 @@
%h2 Cute Little Statistics
%p None here yet.
%h2 Wall of Shame
%table.pure-table
%thead
%th Shame on
%th Contribution to Zeus' lack of money
%tbody
- @statistics.shameful_users.each do |user|
%tr
%td.shameful-person= 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.shame-percentage= "#{100 * user.balance / @statistics.total_debt}%"
.pure-g
.pure-u-1-2
%table.pure-table
%thead
%th Shame on
%th Contribution to Zeus' lack of money
%tbody
- @statistics.shameful_users.each do |user|
%tr
%td.shameful-person= 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.shame-percentage= "#{100 * user.balance / @statistics.total_debt}%"
.pure-u-1-2
= javascript_include_tag "//www.google.com/jsapi", "chartkick"
= pie_chart @statistics.shamehash