Skip to content

Instantly share code, notes, and snippets.

@tjstebbing
Created December 13, 2013 06:32
Show Gist options
  • Save tjstebbing/7940565 to your computer and use it in GitHub Desktop.
Save tjstebbing/7940565 to your computer and use it in GitHub Desktop.
import csv, StringIO, random, sys
from datetime import date, timedelta as td
try:
count = int(sys.argv[1])
except:
count = 10
def dates(d1, d2):
return [str(d1 + td(days=x)) for x in range((d2-d1).days + 1)]
percentages = [0 for x in range(30)]+range(0,101)+[100 for x in range(30)]
durations = range(5,50)+[random.choice(range(12, 25)) for x in range(30)]
ages = range(18,75)+[random.choice(range(25, 45)) for x in range(30)]
recs = [0,0,0,0,1,1,1,1,1,1,1,1,1]
ratings = [1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5]
attended = [0,1,1,1,1,1,1,1,1,1]
departments = ['HR', 'Research', 'Management', 'Accounting', 'Sales', 'Sales', 'Sales']
rows = [
('userId', 'generator', (x for x in range(0,10000000))),
('Registered', 'choice', dates(date(2013,10,2), date(2013,12,15))),
('Age', 'choice', ages),
('Department', 'choice', departments),
('Disease States - Registered', 'choice', dates(date(2013,11,2),
date(2013,12,15))),
('Disease States - Progress', 'choice', percentages),
('Disease States - Duration (min)', 'choice', durations),
('Disease States - Difficulty Rating', 'choice', ratings),
('Disease States - Overall Rating', 'choice', ratings),
('Disease States - Recommended', 'choice', recs),
('Face to Face Course - Registered', 'choice', dates(date(2013,10,22),
date(2013,11,9))),
('Face to Face Course - attended', 'choice', attended),
('Face to Face Course - Difficulty Rating', 'choice', ratings),
('Face to Face Course - Overall Rating', 'choice', ratings),
('Face to Face Course - Recommended', 'choice', recs),
]
# Get the title row
out = [[r[0] for r in rows]]
# Generate random rows
for i in range(0, count):
line = []
for r in rows:
if(r[1] == 'generator'):
line.append(r[2].next())
elif(r[1] == 'choice'):
line.append(random.choice(r[2]))
out.append(line)
output = StringIO.StringIO()
writer = csv.writer(output)
writer.writerows(out)
print output.getvalue()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment