Created
March 1, 2018 23:06
-
-
Save marinhero/d03d8081c89bb59d2934f1e331297f5c to your computer and use it in GitHub Desktop.
custom_samplings_generator.rb
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
# | |
# Open rails console | |
# type: load 'custom_samplings_generator.rb' | |
# type: seed('NPS-YourToken') | |
# Go to /account_sampling_rules.json?account_token=NPS-YourToken in Survey Server | |
# | |
RULES = %w( | |
on_click | |
on_login | |
on_logout | |
on_purchase | |
on_checkout | |
account_delete | |
new_account | |
) | |
def create_params(account_id) | |
{ | |
account_id: account_id, | |
rule_name: "#{RULES.sample}_#{rand(1..1000)}", | |
rule_type: 'event', | |
survey_throttle_days: rand(1..30), | |
response_throttle_days: rand(1..100), | |
decline_throttle_days: rand(1..50), | |
modal_delay_seconds: rand(1..10), | |
daily_response_cap: rand(1..100), | |
registered_user_sample_percentage: rand(50..100), | |
visitor_user_sample_percentage: rand(50..100), | |
context_name: nil | |
} | |
end | |
def seed(token) | |
account_id = Account.where(account_token: token).pluck(:id)[0] | |
puts '[+] Creating CustomSampling rules' | |
rand(1..5).times do | |
CustomSampling.create(create_params(account_id)) | |
end | |
puts '[+] Done' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment