<commit_before>require "rubygems"
require "sinatra"
require "intercom"
require "faker"

num_of_companies = 10
num_of_users = 60

get '/' do
  erb :index
end


get '/populate' do
  erb :populate
end

post '/seed' do
	pat = params[:pat]
	@intercom = Intercom::Client.new(token: pat)

	@user_id = []
	num_of_users.times do
		@user_id << rand(300)
	end

	company_id = []
	num_of_companies.times do
		company_id << rand(100..500)
	end

	company_name = []
	num_of_companies.times do
	  company_name << Faker::App.name
	end

	monthly_spend = []
	num_of_companies.times do
		monthly_spend << rand(600..2000)
	end


	def user_and_company_generator(company_id, company_name, monthly_spend)

		@user_id.count do
			@intercom.users.submit_bulk_job(
				create_items: [
					{
						user_id: @user_id.pop,
						email: "#{<EMAIL>",
						name: "#{Faker::Superhero.name}",
						last_seen_ip: "#{Faker::Internet.public_ip_v4_address}",
						phone: "#{Faker::PhoneNumber.cell_phone}",
						signed_up_at: Time.now.to_i,
						custom_attributes: {
							superpower: "#{Faker::Superhero.power}",
					    favorite_beer: "#{Faker::Beer.name}",
							last_caught_pokemon: "#{Faker::Pokemon.name}",
							money_in_bank: "#{Faker::Number.decimal(2)}"
				    },
					  companies: [
					  	{
					  		:company_id => company_id,
					  		:name => "#{company_name}",
					  		:monthly_spend => monthly_spend
					  	}
					  ]
				  }
				]
			)

		end
	end

	def lead_generator
		@user_id.count.times do
			@intercom.contacts.create(:email => "#{Faker::Internet.email}")
		end
	end

	puts "Populating your lovely test app with some fake users and companies. Hang tight! :)"
	70.times do
		print '•'
	end
	user_and_company_generator(company_id[0], company_name[0], monthly_spend[0])
	user_and_company_generator(company_id[1], company_name[1], monthly_spend[1])
	user_and_company_generator(company_id[2], company_name[2], monthly_spend[2])
	# lead_generator
	puts
	puts "All done! Now either add conversations by running 'ruby convo_seed.rb' or go play with your new users!"

	erb :completed
end

post '/conversations' do
    #Determine Which CSV To Use
    puts "You selected #{params[:role]}"

    # Open Spreadsheet
    csv_text = File.read("#{params[:role]}.csv")
    # Create array of questions
    questions = []
      csv_text.each_line {|line|
       questions << line
     }

    # Goes through  each user, grabs their ID and populates the inbox with questions
    def populate(questions)
      pat = params[:pat]
      @intercom = Intercom::Client.new(token: pat)

    	index = 0
    	intercom_id = []

    	@intercom.users.all.each do |user|
    		intercom_id << user.id
    		@intercom.messages.create(
    		  :from => {
    		    :type => "user",
    		    :id => user.id
    		  },<commit_msg>adding CSV to remote location. Heroku don't like local CSVs<commit_after>require "rubygems"
require "sinatra"
require "intercom"
require "faker"

num_of_companies = 10
num_of_users = 60

get '/' do
  erb :index
end


get '/populate' do
  erb :populate
end

post '/seed' do
	pat = params[:pat]
	@intercom = Intercom::Client.new(token: pat)

	@user_id = []
	num_of_users.times do
		@user_id << rand(300)
	end

	company_id = []
	num_of_companies.times do
		company_id << rand(100..500)
	end

	company_name = []
	num_of_companies.times do
	  company_name << Faker::App.name
	end

	monthly_spend = []
	num_of_companies.times do
		monthly_spend << rand(600..2000)
	end


	def user_and_company_generator(company_id, company_name, monthly_spend)

		@user_id.count do
			@intercom.users.submit_bulk_job(
				create_items: [
					{
						user_id: @user_id.pop,
						email: "#{<EMAIL>",
						name: "#{Faker::Superhero.name}",
						last_seen_ip: "#{Faker::Internet.public_ip_v4_address}",
						phone: "#{Faker::PhoneNumber.cell_phone}",
						signed_up_at: Time.now.to_i,
						custom_attributes: {
							superpower: "#{Faker::Superhero.power}",
					    favorite_beer: "#{Faker::Beer.name}",
							last_caught_pokemon: "#{Faker::Pokemon.name}",
							money_in_bank: "#{Faker::Number.decimal(2)}"
				    },
					  companies: [
					  	{
					  		:company_id => company_id,
					  		:name => "#{company_name}",
					  		:monthly_spend => monthly_spend
					  	}
					  ]
				  }
				]
			)

		end
	end

	def lead_generator
		@user_id.count.times do
			@intercom.contacts.create(:email => "#{Faker::Internet.email}")
		end
	end

	puts "Populating your lovely test app with some fake users and companies. Hang tight! :)"
	70.times do
		print '•'
	end
	user_and_company_generator(company_id[0], company_name[0], monthly_spend[0])
	user_and_company_generator(company_id[1], company_name[1], monthly_spend[1])
	user_and_company_generator(company_id[2], company_name[2], monthly_spend[2])
	# lead_generator
	puts
	puts "All done! Now either add conversations by running 'ruby convo_seed.rb' or go play with your new users!"

	erb :completed
end

post '/conversations' do
    #Determine Which CSV To Use
    puts "You selected #{params[:role]}"

    # Open Spreadsheet
    # csv_text = File.read("#{params[:role]}.csv")
    csv_text = File.read("https://downloads.intercomcdn.com/i/o/70860534/03ae111c3d2f2edf036e451f/csl.csv")
    # Create array of questions
    questions = []
      csv_text.each_line {|line|
       questions << line
     }

    # Goes through  each user, grabs their ID and populates the inbox with questions
    def populate(questions)
      pat = params[:pat]
      @intercom = Intercom::Client.new(token: pat)

    	index = 0
    	intercom_id = []

    	@intercom.users.all.each do |user|
    		intercom_id << user.id
    		@intercom.messages.create(
    		  :from => {
    		    :type => "user",
    		    :id => user.id
    		  },
{'fraction_non_alphanumeric': 0.12805303558967202, 'fraction_numerical': 0.0157013258897418, 'mean_word_length': 3.1724890829694323, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2660775', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2074, 'n_words': 433}