Skip to content
This repository
Browse code

Merge branch 'master' into gh-pages

  • Loading branch information...
commit 236faad5933728554f4f1ea4e1b48b0300484c03 2 parents bfffab7 + 379d51d
Robert Jackson authored April 13, 2012
2  Rakefile
@@ -34,7 +34,7 @@ namespace :pivot do
34 34
 
35 35
   desc "Generates demo CSV for pivot.js gh-pages."
36 36
   task :csv do
37  
-    dcsv = DemoCSV.new(1000)
  37
+    dcsv = DemoCSV.new(5000)
38 38
     dcsv.to_file "./lib/csv/demo.csv"
39 39
     $stdout.puts "Generate demo CSV successful"
40 40
   end
26  demo_csv_builder.rb
@@ -27,8 +27,8 @@ def generate_csv
27 27
     CSV.generate do |csv|
28 28
       csv << header
29 29
       count.times do |i|
30  
-        invoice_date     = time_rand(Time.local(2010, 1, 1))
31  
-        last_billed_date = time_rand(Time.local(2010, 1, 1), invoice_date)
  30
+        invoice_date     = bucket
  31
+        last_billed_date = time_rand(invoice_date)
32 32
         city             = cities[rand(29)]
33 33
 
34 34
         csv << [ Faker::Name.last_name,
@@ -45,6 +45,24 @@ def generate_csv
45 45
     end
46 46
   end
47 47
 
  48
+  def bucket
  49
+    number = rand(0..10)
  50
+    age = case number
  51
+          when 0..4
  52
+            rand(0..30)
  53
+          when 5
  54
+            rand(31..60)
  55
+          when 6
  56
+            rand(61..90)
  57
+          when 7
  58
+            rand(91..120)
  59
+          when 8..10
  60
+            rand(121..600)
  61
+          end
  62
+
  63
+    Time.at(Time.now.to_i - age * 60 * 60 * 24)
  64
+  end
  65
+
48 66
 
49 67
   def to_s
50 68
     puts generate_csv
@@ -54,7 +72,7 @@ def to_file(path)
54 72
     File.open(path,"w") {|f| f.write(generate_csv)}
55 73
   end
56 74
 
57  
-  def time_rand(from=0.0,to=Time.now)
58  
-    Time.at(from + rand * (to.to_f - from.to_f))
  75
+  def time_rand(from=0,to=Time.now)
  76
+    Time.at(rand(from.to_i..to.to_i))
59 77
   end
60 78
 end
6,000  lib/csv/demo.csv
5000 additions, 1000 deletions not shown

0 notes on commit 236faad

Please sign in to comment.
Something went wrong with that request. Please try again.