Skip to content

Instantly share code, notes, and snippets.

final class Content {
var value: Int
init(value: Int) { self.value = value }
var debug: String { return String(describing: value) }
}
struct Wrapper {
private var _content: Content
var content: Content {
mutating get {
=begin
Hey Francesco,
wir würden gerne für den Muttertag ein kleines Reporting machen.
Hättest du Montag oder Anfang nächster Woche ein wenig Zeit dafür.
Uns würde interessieren wie viele Orders waren Neukunden/Erstbestellung und wie viele Wiederkäufer
Einmal zu den Vouchern und einmal gesamt über den Zeitraum alle Fotobuch Orders vom 21.04.2017 - 14.05.2017
Voucher
Fine
def alex( t0 = Date.yesterday, t1 = Date.tomorrow, limit = 12 )
dt = t0 .. t1
median = []
Order.where( :state => :printed.to_s, :created_at => dt ).find_each do | w |
qty = w.order_items.select{ | i | i.product_code == "CLXPXS1F" }.map( &:quantity ).sum
median << qty
end
# puts median
a1 = median.select{ | i | i < limit }.count
# Median
require "nokogiri"
def nokogiri_edit( handle, opts )
doc = Nokogiri::XML( handle )
# address update
if opts[ :address ] # start address
updated_address = opts[ :address ]
address = doc.xpath(
require "nokogiri"
def nokogiri_edit( handle, opts )
builder = Nokogiri::XML::Builder.new( :encoding => 'UTF-8' ) do | xml |
party = false
party_id = false
party_id_system = false
party_id_match = false
party_role = false
# vps-api
ANDROID_CLIENT_ID = 4
IOS_CLIENT_ID = 5
TELEKOM_CAMPAIGN_APRIL_2016_CAMPAIGN_ID = 4
################################################################################
# orders from April 18 to May 10 2016:
################################################################################
os = Order.where( :state => :printed.to_s, :created_at => Date.parse('2016-04-18') .. Date.parse('2016-05-11') )
@airspeed
airspeed / CS-16.rb
Last active February 25, 2016 14:56
def cs16
result = []
ps = [ 'PLBF6S1F', 'PLBF5S1F', 'PLBF4S1F', 'PLBF3S1F', 'PLBFXBX1']
is = OrderItem.where( :product_code => ps )
uids = is.map( &:user_id ).uniq
iids = is.map( &:id ).uniq # eigentlich unnötig, aber schadet ja nicht
oids = is.map( &:order_id ).uniq
result << [ 'User ID', 'User Email', 'Anzahl Bestellungen', 'Gesamtbestellwert', 'Bestellte Produkte' ]
uids.each do | uid |
u = User.where( :id => uid ).last or next
# !#crm
def make_stats
emails = Set.new
stats = []
Customer.find_each do | k |
emails.add?( k.email ) or next # customer already reported
all_cs = Customer.where( :email => k.email )
all_os = all_cs.map( &:order_carts )
all_os.select{ | order_list | order_list.count > 0 }.count > 1 or next # this customer is NOT a rebuyer -> skip
first_order_id = all_os.map{ | w | w.select(" MIN( id ) AS first_order_id ").group( :app_id ).map( &:first_order_id ) }.map( &:first ).min
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
# Vgl. #5711
# date_from - date range start
# date_until - date range end
# custom_search - flag freeze search dates
def vouchers_report( date_from = Date.yesterday , date_until = Date.today, custom_search = false )
date_from = Date.today - 3.days if Date.today.wday == 1 && !custom_search # Montags alle Wochenendebestellungen mit reinbeziehen.
product_codes = [ 'CLXPXV01', 'CLXPXV02', 'CLXPXV03', 'CLXPXV04' ]
Order.where( :state => :printed.to_s, :created_at => date_from .. date_until ).select{ | w | w.order_items.any?{ | i | product_codes.include?( i.product_code ) } }.map{ | w | [ w.id, ( w.user.email if w.user ), w.created_at.to_date.to_s ] }
end
# vouchers_report Date.today.beginning_of_month - 1.month, Date.today.beginning_of_month, true