Skip to content

Instantly share code, notes, and snippets.

@larrywright
Created June 10, 2009 03:08
Show Gist options
  • Save larrywright/126989 to your computer and use it in GitHub Desktop.
Save larrywright/126989 to your computer and use it in GitHub Desktop.
namespace :utils do
desc "Populate the database with random data"
task(:generate_data => :environment) do
puts "Deleting all of the existing data"
Campaign.delete_all
client_names = %w{Acme Danger MegaCorp}
scores = %w{High Medium Low}
volumes = (8000..10000).to_a
letter_types = %w{1 2 3}
dates = ((DateTime.now-40.days)..DateTime.now).to_a
response_rates = (2..9).to_a
variances = (-4..4).to_a
1000.times do
c = Campaign.new
c.client_name = client_names.rand
c.score_band = scores.rand
c.letter_type = letter_types.rand
c.order_date = dates.rand
c.mail_date = c.order_date + 1.days
c.in_home = c.order_date + 3.days
c.number_mailed = volumes.rand
c.estimated_response = responses.rand
c.revised_response = c.estimated_response - (variances.rand.to_f/10)
c.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment