Last active
January 10, 2018 22:59
-
-
Save airspeed/eaccc2d5b1468929d163 to your computer and use it in GitHub Desktop.
Wie viele Bücher oder Fotos wurden in einem gewissen Monat bestellt?
This file contains hidden or 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
| POLAPIX_PRODUCT_CODES = [ "CLXPXS1F", "CLXPXS2F", "CLXPXS3F" ] | |
| POLAPIX_CALENDAR_PRODUCT_CODES = ["CLXPXK01", "CLXPXK03"] | |
| POLAPIX_INVITATION_SET_PRODUCT_CODE = "CLXPXST1" | |
| POLAPIX_BOX_SET_PRODUCT_CODES = ["CLXPXST2", "CLXPXST3"] | |
| # string product_code - see list under. | |
| # Date start_date - mit in den Report eingeschlossen | |
| # Date end_date - nicht mit in den Report eingeschlossen | |
| # string path - der User muss schreibberechtigt darauf sein | |
| def make_bosch_stats( product_code, timespan, path ) | |
| product_id = ( Product.where( :code => product_code ).first && Product.where( :code => product_code ).first.id ) or return ( "Unknown product code #{ product_code }." ) | |
| os = Order.where( :created_at => timespan, :state => :printed.to_s ).pluck(:id).uniq | |
| is = OrderItem.where( :order_id => os ).select{ |i| i.product_code == product_code if i }.uniq | |
| result = is.sum( &:quantity ) | |
| result += is.count if POLAPIX_PRODUCT_CODES.include?( product_code ) | |
| result *= 13 if POLAPIX_CALENDAR_PRODUCT_CODES.include?( product_code ) | |
| result *= 30 if product_code == POLAPIX_INVITATION_SET_PRODUCT_CODE | |
| result *= 40 if POLAPIX_BOX_SET_PRODUCT_CODES.include?( product_code ) | |
| "#{ product_code } | #{ timespan } | #{result}" | |
| end | |
| # Usage: | |
| # make_bosch_stats( "CLXB5S1F", Date.parse( '2014-10-01' ), Date.parse( '2014-11-01' ), "/Users/fpugl/Downloads/stats.csv" ) | |
| # string start_date - mit in den Report eingeschlossen, bitte MYSQL-Format jjjj-mm-tt einhalten | |
| # string end_date - nicht mit in den Report eingeschlossen, bitte MYSQL-Format jjjj-mm-tt einhalten | |
| # string basepath - der User muss schreibberechtigt darauf sein | |
| def auto_bosch_stats( start_date = Date.today.beginning_of_month - 1.month, end_date = Date.today.beginning_of_month, basepath = "/home/deploy/" ) | |
| start_date = Date.parse( start_date ) unless start_date.is_a? Date | |
| end_date = Date.parse( end_date ) unless end_date.is_a? Date | |
| timespan = start_date .. end_date | |
| gos = Order.where( :created_at => timespan, :state => :printed.to_s ).count | |
| product_code = [ "CLXB5S1F", "CLXB5S2F", "CLXB5S1Q", "CLXB5S2Q", "CLXB6S1F", "CLXB6S2F", | |
| "CLXF3S1F", "CLXF4S1F", "CLXF5S1F", "CLXF6S1F", | |
| "PLBF3S1F", "PLBF4S1F", "PLBF5S1F", "PLBF6S1F", "PLBFXBX1", | |
| "CLXPXS1F", "CLXPXKL1", "CLXPXKB1", "CLXPXKB2", "CLXPXKB3", "CLXPXKB4", "CLXPXKB5", "CLXPXKB6", "CLXPXKB7", "CLXPXHS1", "CLXPXBX1", "CLXPXK01", "CLXPXK02", "CLXPXS2F", "CLXPXS3F", "CLXPXST1", "CLXPXST2", "CLXPXST3", "CLXPXDS1", "CLXPXLN1", | |
| "CLXKP001", "CLXKP002", "CLXKP003", "CLXKP004", "CLXKP005", "CLXKP006", "CLXKDX01", "CLXKDX02", "CLXKDX03", "CLXKDX04", "CLXKDX05", "CLXKDX06", | |
| "CLXPS001", "CLXPS002" ] # Gönn dir verwendet auch Retropix-Codes | |
| results = [] | |
| product_code.each do | c | | |
| results << make_bosch_stats( c, timespan, Pathname.new( basepath ).join( "#{ c }_#{ start_date }_#{ end_date }.csv" ).to_s ) | |
| end | |
| results.each do | r | | |
| puts r | |
| end | |
| puts "Gesamt: #{ gos }." | |
| end | |
| # Usage: | |
| # auto_bosch_stats( '2014-10-01', '2014-11-01', "/Users/fpugl/Downloads/" ) | |
| # auto_bosch_stats |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Zum ausführen auf vps-api oder vps-flexiphoto.