Created
April 11, 2013 03:48
-
-
Save zorn/5360589 to your computer and use it in GitHub Desktop.
Short ruby script to generate a random expenses csv file for demo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
# Our sample categories | |
categories = [] | |
categories << 'Advertising' | |
categories << 'Bank Fees' | |
categories << 'Computer Hardware' | |
categories << 'Computer Software' | |
categories << 'Conferences' | |
categories << 'Hosting' | |
categories << 'Legal and Prof. Services' | |
categories << 'Licenses' | |
categories << 'Mags/Pubs/Manuals' | |
categories << 'Office Space' | |
categories << 'Office Supplies' | |
categories << 'Phone' | |
categories << 'Travel' | |
# To help with random time | |
def time_rand from = 0.0, to = Time.now | |
Time.at(from + rand * (to.to_f - from.to_f)) | |
end | |
# generate random expenses csv file | |
CSV.open("random-expenses.csv", "w") do |csv| | |
csv << ["Date","Cost", "Category"] | |
100.times do | |
random_category = categories.sample | |
random_date = time_rand Time.local(2012, 1, 1), Time.local(2012, 12, 31) | |
random_date_string = random_date.strftime "%Y-%m-%d" | |
random_cost = 1 + rand(10000) | |
csv << [random_date_string, random_cost.to_f/100, random_category] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment