diff --git a/app/controllers/concerns/statistics.rb b/app/controllers/concerns/statistics.rb index facec4a..d2c835a 100644 --- a/app/controllers/concerns/statistics.rb +++ b/app/controllers/concerns/statistics.rb @@ -17,6 +17,18 @@ class Statistics < Rails::Application end end + def by_issuer + Transaction.group(:issuer_id).count.inject(Hash.new) do |hash, (id, count)| + hash.merge({User.find(id).name => count}) + end + end + + def amount_distribution + Transaction.group("round(amount / 10)").count.inject(Hash.new) do |hash, (group, count)| + hash.merge({10 * group.to_i => count}) + end + end + private def zeus_balance diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 1b5f7d5..765edb7 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -6,10 +6,10 @@ Log een keer in! %p= link_to "Log in met Zeus WPI", user_omniauth_authorize_path(:zeuswpi) %h2 Cute Little Statistics -%p None here yet. -%h2 Wall of Shame += javascript_include_tag "//www.google.com/jsapi", "chartkick" .pure-g .pure-u-1-2 + %h3 Table of Shame %table.pure-table %thead %th Shame on @@ -22,5 +22,12 @@ // 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" + %h3 Pie of Shame = pie_chart @statistics.shamehash +.pure-g + .pure-u-1-2 + %h3 Distribution of Debt Sources + = pie_chart @statistics.by_issuer + .pure-u-1-2 + %h3 Distribution of Transaction Amounts + = column_chart @statistics.amount_distribution