Last active
December 9, 2015 11:16
-
-
Save airspeed/86e3059299fafeecc234 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 weekly_polapix( start_date, end_date, classes ) | |
results = [] | |
results << "Week from #{ start_date } to #{ end_date }" | |
classes.each do | range | | |
n = Order.where( :state => :printed.to_s, :created_at => start_date .. end_date ).select{ | w | range.include?( w.order_items.map( &:quantity ).sum ) }.count | |
results << "#{ range }: #{ n }" | |
end | |
results | |
end | |
def auto_weekly_polapix( start_date = Date.today.beginning_of_week - 1.week, end_date = Date.today.beginning_of_week ) | |
classes = [ | |
1 .. 3, | |
4 .. 8, | |
9 .. 11, | |
12 .. 16, | |
17 .. 23, | |
24 .. 30, | |
31 .. 36, | |
36 .. 10000 | |
] | |
results = weekly_polapix( start_date, end_date, classes ) | |
puts results | |
end | |
# Usage: | |
# auto_weekly_polapix | |
# Nachholung: | |
# ( 1 .. 4 ).each do | i | | |
# auto_weekly_polapix Date.today.beginning_of_week - i.weeks, Date.today.beginning_of_week - ( i - 1 ).weeks | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment