Skip to content

Instantly share code, notes, and snippets.

@khoan
Created May 3, 2013 01:56
Show Gist options
  • Save khoan/5506733 to your computer and use it in GitHub Desktop.
Save khoan/5506733 to your computer and use it in GitHub Desktop.
class SimulateTraffic
def initialize
@dates = (first_date_of_last_month..Date.today).to_a
@types = [:pageviews, :subscriptions, :shares, :clicks]
end
def first_date_of_last_month
prev_month = Date.today.prev_month
Date.new(prev_month.year, prev_month.month, 1)
end
def fake_daily
hourly_count = 24.times.map{rand(1000)}
DailyStat.create edition_id: Edition.first.id, date: @dates.sample, hourly_count: hourly_count, type: @types.sample, total: hourly_count.sum
end
end
simulator = SimulateTraffic.new
100.times do
simulator.fake_daily
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment