Skip to content

Instantly share code, notes, and snippets.

@thadeubrito
Last active September 20, 2017 18:16
Show Gist options
  • Save thadeubrito/078b362bc603cb9037be60bd50009549 to your computer and use it in GitHub Desktop.
Save thadeubrito/078b362bc603cb9037be60bd50009549 to your computer and use it in GitHub Desktop.
require 'date'
require 'time'
cID = '3816'
dIDs = ['59c13d784ea9733a79000005', '59c13cdcd9ce2b5175000008', '59c1389a980e907e1e000001', '59c135ca4ea9735157000000', '59c13754980e907e48000007']
album = 'aV9szjoe' # 2602974
assets = ['1Bbbety', '1Cd5e4yurm', '1DeLUKlfmc', '1DeNDZhlkd', '1EE8FRphfz', '1EEarRoijk', '1GscQ5dqig', '1HGZBstxsn', '1HH0pbjdrx', '1HH5jlqjmo', '1IwaQlnhdb', '1IwImuwmhs',
'1Ix7Apkyex', '1IxgGKamnb', '1Ixk1Njbru', '1NLF6amsit', '1OSSEGbsjw', '1OSsKVixgv', '1OT4I6mlyb', '1OT9Hgyprx', '1OTPARalou', '1OUy8qpdcv', '1OWC4Nesbc', '1PbA4wtycw',
'1PbgWrfmer', '1qcjbSavsc', '1r8UC5ehin', '1r8V3fybag', '1RPK7Nexmb', '1RPMjIelti', '1rYJ2arobc', '1Sfeaulcvo', '1Sff0eujbs', '1Sh5XRhbno', '1UkTtclszx', '1UkVkutpca',
'1VNH1Iclvd', '1VNNdycxud', '1VNWHokysw', '1VOAxZqnxz', '1VOCnjudzm', '1VOEeAzbja', '1VOuCqvhcm', '1wrfsAtpcl', '1wsxEIkblo', '1wsyNvcmjl', '1xhfiibetv', '1yisjbm',
'23zB85onxy', '29sis1dzwr', '29v2z4cwnf', '29wcosjaeu', '29wrsmnvgu', '29wWnApjnr', '29x6Gczmea', '29xdUkeits', '2a3I5Hrunw', '2a3Ke6hofn', '2gVZ8Cetjz', '2h0vCHsdxe',
'2hRm3vkhyt', '2IyL00xzjh', '2Iyowcrhuc', '2IysDmmojy', '2Iyz2kkani', '2Iz2fHwrgb', '2IziTgtnxd', '2QjEe8iftk', '2TBFxCvhwg', '2TBFyKnsay', '2TBFyPfkgy', '2TBFyxeoax',
'2TBFz0ormy', '2xDOjkbwea', '2xDPFpsdhw', '2xDPxwgndy', '2xDQ0Prdxl', '2xFHWagcov', '2xTBebxzgd', '2yNTwboazc', '2yNUARhiue']
# cID = '3817'
# dIDs = ['59c1464ad9ce2b5350000000', '59c145d84ea9736d90000000', '59c14553d9ce2b2ecc000002', '59c144f2d9ce2b518d000008']
# album = 'aV9Nxzyj' # 2602995
# assets = ['1D6MSkgzyf', '1DeUsseufi', '1Dlz2ncrtw', '1Dq00srnfy', '1DrsTblvxs', '1EEmFCriph', '1EPuximfpd', '1HHtm3eamf', '1IxhrIfkju', '1Ixzxhokfv', '1jUjWrsiyw', '1jUk1Mclsy',
# '1jUk8Dmfon', '1jUkgLxneo', '1jUkhKlwnm', '1jUxOKdjhw', '1jUxOLsdjz', '1jUxOMqpsd', '1jUxOOvxcn', '1jUxORjozq', '1jUxP0vura', '1jUxPcnusj', '1jUxPfqjit', '1jUxPgdhiz',
# '1jUxPhworh', '1jUxPiixth', '1jUxPLioqh', '1jUxPMoinz', '1jUxPslorn', '1jUxPSpomw', '1jUxPTigzp', '1jUxPYjpwg', '1jUxPZlrvs', '1lL7xvixvk', '1mybnlloda', '1r9OeHlxgs',
# '1rYOHjinfp', '1VO56Yxmpj', '1VOOkSmrvc', '1VPduuawni', '1xikuPtzmn', '23E2g3tmei', '23zBSvndho', '29xgjmlrsj', '29zLWHckeb', '2hSQWVnvst', '2hTFCjbrfv', '2Ql7Oeqrew',
# '2Qlh5Vsalq', '2QOqHWcgih', '2xUm6Umzai', '2yOd3dgojx', '2zjGtYuyqw', '2zjQCefxig', '2zk4Conosj', '2zk4mblqhw', '3ONYFjejtu', '3ONYNqmsib']
init_date = Date.new(2017, 6, 20)
end_date = Date.new(2017, 9, 20)
assets_per_day = 20 #20
dIDs.each do |dID|
(init_date..end_date).each do |date|
puts "\nSTART A DAY #{date} #{'-'*99}\n"
timestamp = Time.parse(date.to_s).to_s.slice(0..-6)
# -------------------------------------
# INTERACTIONS & ENGAGEMENTS
# -------------------------------------
engagements_rate = rand(1.0..6.0).round(2)
impressions_count = rand(10_000..20_000) # ex: 10_000 per day
engagements_count = ((impressions_count*engagements_rate)/100).round(0) # ex: 100 - 1%
interaction_count = rand(engagements_count..(impressions_count/2)).round(0) # ex: 100..5000
# -------------------------------------
# DISTRIBUTE INTERACTIONS BETWEEN ASSETS
# -------------------------------------
smaller = ((interaction_count / assets_per_day)*80)/100
bigger = ((interaction_count / assets_per_day)*120)/100
interactions_per_asset_array = Array.new(assets_per_day) { rand(smaller..bigger) }
@total_interactions = 0
@total_shares = 0
@total_clickthroughs = 0
assets.sample(assets_per_day).each_with_index do |asset, index|
puts "START A ASSET #{index + 1} #{asset} #{'-'*30}"
interaction_per_asset = interactions_per_asset_array[index]
# -------------------------------------
# CLICKS OF ASSETS
# -------------------------------------
click_lightbox_count = (interaction_per_asset*80)/100 # 80% of interations are click_lightbox
# Event.create(cID: cID, dID: dID, eTp: 'click_lightbox', lID: album, aID: asset, count: click_lightbox_count, timestamp: timestamp)
puts "eTp: click_lightbox - count: #{click_lightbox_count} - album: #{album} - asset: #{asset}" if click_lightbox_count > 0
@total_interactions += click_lightbox_count
# -------------------------------------
# SHARES OF ASSETS
# -------------------------------------
share_count = (interaction_per_asset*10)/100 # 10% of interations are shares
facebook_shares = (share_count*70)/100 # 70% of shares are on facebook
twitter_shares = (share_count*25)/100 # 25% of shares are on twitter
pinterest_shares = (share_count*5)/100 # 5% of shares are on pinterest
# Event.create(cID: cID, dID: dID, eTp: 'share_facebook', lID: album, aID: asset, count: facebook_shares, timestamp: timestamp) if facebook_shares > 0
# Event.create(cID: cID, dID: dID, eTp: 'share_twitter', lID: album, aID: asset, count: twitter_shares, timestamp: timestamp) if twitter_shares > 0
# Event.create(cID: cID, dID: dID, eTp: 'share_pinterest', lID: album, aID: asset, count: pinterest_shares, timestamp: timestamp) if pinterest_shares > 0
puts "eTp: share_facebook - count: #{facebook_shares} - album: #{album} - asset: #{asset}" if facebook_shares > 0
puts "eTp: share_twitter - count: #{twitter_shares} - album: #{album} - asset: #{asset}" if twitter_shares > 0
puts "eTp: share_pinterest - count: #{pinterest_shares} - album: #{album} - asset: #{asset}" if pinterest_shares > 0
@total_interactions += (facebook_shares + twitter_shares + pinterest_shares)
@total_shares += (facebook_shares + twitter_shares + pinterest_shares)
# -------------------------------------
# CLICKTHROUGHS
# -------------------------------------
clickthroughs_count = (interaction_per_asset*10)/100 # 10% of interations are clickthroughs
# Event.create(cID: cID, dID: dID, eTp: 'click_url', count: clickthroughs_count, timestamp: timestamp) if clickthroughs_count > 0
puts "eTp: click_url - count: #{clickthroughs_count} - album: #{album} - asset: #{asset}" if clickthroughs_count > 0
@total_interactions += clickthroughs_count
@total_clickthroughs += clickthroughs_count
end
# -------------------------------------
# SUMMARY
# -------------------------------------
# Summary.create(cID: cID, dID: dID, impressions: impressions_count, engagements: engagements_count, interactions: @total_interactions, clickthroughs: @total_clickthroughs, shares: @total_shares, uniques: 0, timestamp: timestamp, timespent: rand(100..300), serves: 0, dCx: "", oCu: nil, conversions: 0, orders_value: 0)
puts "\nSummary impressions: #{impressions_count} - engagements: #{engagements_count} - interactions: #{@total_interactions} - clickthroughs: #{@total_clickthroughs} - share: #{@total_shares}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment