Skip to content

Instantly share code, notes, and snippets.

@airspeed
airspeed / 5605.rb
Last active November 17, 2015 16:10
( 1 .. 20 ).each do | i |
Voucher.create :code => "WoodBoard#{i}", :quantity => 151, :value => 10, :discount_type => 'NUMBER', :valid_from => Date.today, :valid_until => Date.
parse('2016-01-31'), :shipping_discount => false, :settings => { :products_limit => [ "clxkp002" ] }
Voucher.last.tap{ | g | g.settings = { :products_limit => ["CLXKP002"] } }.save
end
( 1 .. 15 ).each do | i |
Voucher.create :code => "wood#{i}", :quantity => 500, :value => 25, :discount_type => 'PERCENT', :valid_from => Date.today, :valid_until => Date.
parse('2015-12-31'), :shipping_discount => false, :settings => { :products_limit => [ "all" ] }
end
[
{
"formatId" : "ID_3",
"title" : "formatInfoCompact",
"shoppingCartTitle" : "shoppingcartInfoCompact",
"photoCountText" : "shoppingcartInfo30Pics",
"infoText" : "formatInfo30Pics",
"typeLabelText" : "formatButtonCompact",
"formatImage" : "Format-3",
"price":15.50,
Product.first.tap{ | p | p.price = 15 }.save
@airspeed
airspeed / 5457.rb
Last active October 27, 2015 16:06
q = Source.where( :code => 'telekom_mega_deal' ).last
gs = Voucher.where( :source_id => q.id ) # Deal2015
ios = Order.where( :state => :printed.to_s, :voucher_id => gs, :client_id => 5 ).map( &:total_amount ).sum.to_f
android = Order.where( :state => :printed.to_s, :voucher_id => gs, :client_id => 4 ).map( &:total_amount ).sum.to_f
Order.where( :state => :printed.to_s, :voucher_id => gs, :client_id => 5 ).count
Order.where( :state => :printed.to_s, :voucher_id => gs ).select{ | w | w.user.orders.where( :state => :printed.to_s ).first.id == w.id if w.user
}.select{ | w | w.user.mobile_operator_id == 1 }.count
Order.where( :state => :printed.to_s, :voucher_id => gs ).select{ | w | w.user.orders.where( :state => :printed.to_s ).first.id != w.id if w.user
}.select{ | w | w.user.mobile_operator_id != 1 }.count
@airspeed
airspeed / playboy.rb
Last active October 9, 2015 10:36
#5281 - Playboy + Mailchimp integration
def remove_from_mailchimp( date_from = Date.new, date_to = Date.tomorrow )
c = Devise::Oauth2Providable::Client.where( :name => 'Playboy' ).last
os = Order.where( :client_id => c.id )
ks = os.map( &:user ).uniq
ks_scoped = ks.select{ | k | k.created_at.to_date > date_from && k.created_at.to_date < date_to }
ks_nl = ks_scoped.select{ | k | k.newsletter }
ks_playboy = ks_nl.select{ | k | k.orders.map( &:client_id ).uniq.count == 1 }# playboy orders only
ks_playboy.map{ | k | k.newsletter = false; k.save }
puts ks_playboy.map{ | k | [ k.id, k.email, k.created_at.to_s, k.newsletter ] }
puts "#{ ks_playboy.count } playboy user unsubscribed."
@airspeed
airspeed / 4956.rb
Last active August 29, 2015 14:23
#4956
# 2. Wieviele Polapix wurden im Schnitt bestellt?
# Note that / has higher precedence than |, @see also http://stackoverflow.com/q/21060234
Voucher.all.map{ | g | [ g.code, Order.where( :voucher_id => g.id, :state => :printed.to_s ).map{ | w | w.order_items.map( &:quantity ).sum }.sum / ( Order.where( :voucher_id => g.id, :state => :printed.to_s ).count | 1 ) ] }
# 3. Wieviele Bilder wurden pro Kategorie (gemäß Aufsplittung von Julien - 1-3 bestellte Fotos, 4-6 bestellte Fotos, etc.) bestellt?
def class_voucher_detail( voucher_id, classes )
results = []
classes.each do | range |
n = Order.where( :state => :printed.to_s, :voucher_id => voucher_id ).select{ | w | range.include?( w.order_items.map( &:quantity ).sum ) }.count
results << "#{ range }: #{ n }"
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 )
@airspeed
airspeed / polapix_wins.rb
Last active August 29, 2015 14:20
Eingelöste Polapix
User.group( :referrer_id ).having( "COUNT(*) > 2" ).count.sort_by{ |_key, value | value }.reduce( 0 ){ | memo, element | memo + ( element.second / 3 ).floor.to_i }
@airspeed
airspeed / nachbestellung_lieferung_an_femory.rb
Last active August 29, 2015 14:18
Nachbestellung mit Lieferung an femory.
# Duplicates one order and delivers it to femory.
# @param order_cart_id int
# @return order_cart_id of the duplicate
# @see To be launched on vps-api-*
# 07.11.2013: Feste Rechnungsadresse für alle Nachdrucke.
def duplicate_order( order_cart_id, invoice_address_id = 38486 )
# fotobuch-api-dev: 3, flexiphoto-api: 2388, flexiphoto-dev: 6556
# 1. Datensammlung
o = Order.find( order_cart_id )
@airspeed
airspeed / statistiken_tag.rb
Last active August 29, 2015 14:14
Erstellt die Statistiken über die täglich bestellten Produkte in einem bestimmten Zeitraum.
def make_stats( from_date, to_date = Date.today.to_s, products = [ 'CLXB5S1Q', 'CLXB5S2Q' ] )
stats = []
t0 = Date.parse( from_date )
t1 = Date.parse( to_date )
dt = t0 .. t1
dt.each do | datum |
sdatum = I18n.l( datum, :locale => 'de' )
os = Order.where( :created_at => datum .. datum + 1, :state => :printed.to_s ).map( &:id ) # Alle gedruckten Order im Zeitraum
ois = OrderItem.where( :order_id => os ) # Alle gedruckten OrderItem im Zeitraum
is = ois.where( :product_code => products ) # Alle gedruckten OrderItem mit Squarebüchern im Zeitraum