Last active
February 1, 2016 15:54
-
-
Save airspeed/00a11ccdf4f3bcbb8782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def classes_user_auto ( classes, from, to ) | |
results = [] | |
classes.each do | range | | |
os = Order.where( :state => :printed.to_s, :created_at => from .. to ).group( :user_id ).having( "count(*) >= #{ range.first } AND count(*) <= #{ range.last }" ) | |
n = os.count.count | |
t = os.sum( :amount_eu ).sum{ | k, v | v }.to_f.round( 2 ) | |
results << [ "#{ from .. to }", "#{ range }", n, t ] | |
end | |
results | |
end | |
classes = [ | |
0 .. 1, | |
2 .. 3, | |
4 .. 6, | |
7 .. 10, | |
10 .. 10000 | |
] | |
from = Date.today.beginning_of_year - 1.year | |
to = Date.today.beginning_of_year | |
# Usage: | |
# classes_user_auto( classes, from, to ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment