Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use 5000 records for sample CSV.

  • Loading branch information...
commit 379d51da20add7f0fa41ca9d847a5f9ca7c29d33 1 parent 2b5daa6
Robert Jackson authored
Showing with 5,023 additions and 1,005 deletions.
  1. +1 −1  Rakefile
  2. +22 −4 demo_csv_builder.rb
  3. +5,000 −1,000 lib/csv/demo.csv
View
2  Rakefile
@@ -34,7 +34,7 @@ namespace :pivot do
desc "Generates demo CSV for pivot.js gh-pages."
task :csv do
- dcsv = DemoCSV.new(1000)
+ dcsv = DemoCSV.new(5000)
dcsv.to_file "./lib/csv/demo.csv"
$stdout.puts "Generate demo CSV successful"
end
View
26 demo_csv_builder.rb
@@ -27,8 +27,8 @@ def generate_csv
CSV.generate do |csv|
csv << header
count.times do |i|
- invoice_date = time_rand(Time.local(2010, 1, 1))
- last_billed_date = time_rand(Time.local(2010, 1, 1), invoice_date)
+ invoice_date = bucket
+ last_billed_date = time_rand(invoice_date)
city = cities[rand(29)]
csv << [ Faker::Name.last_name,
@@ -45,6 +45,24 @@ def generate_csv
end
end
+ def bucket
+ number = rand(0..10)
+ age = case number
+ when 0..4
+ rand(0..30)
+ when 5
+ rand(31..60)
+ when 6
+ rand(61..90)
+ when 7
+ rand(91..120)
+ when 8..10
+ rand(121..600)
+ end
+
+ Time.at(Time.now.to_i - age * 60 * 60 * 24)
+ end
+
def to_s
puts generate_csv
@@ -54,7 +72,7 @@ def to_file(path)
File.open(path,"w") {|f| f.write(generate_csv)}
end
- def time_rand(from=0.0,to=Time.now)
- Time.at(from + rand * (to.to_f - from.to_f))
+ def time_rand(from=0,to=Time.now)
+ Time.at(rand(from.to_i..to.to_i))
end
end
View
6,000 lib/csv/demo.csv
5,000 additions, 1,000 deletions not shown
Please sign in to comment.
Something went wrong with that request. Please try again.