add distributions of debt sources and transaction amounts

This commit is contained in:
Felix Van der Jeugt 2015-09-12 00:55:23 +02:00
parent c9010f59ee
commit 9302c3533b
2 changed files with 22 additions and 3 deletions

View file

@ -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

View file

@ -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