-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_data.py
103 lines (83 loc) · 2.54 KB
/
make_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from faker import Factory
from app import db
import models
from werkzeug.security import generate_password_hash
import random
fake = Factory.create()
def create_users(n):
s = 0
e = 0
for x in range(0, n):
user = models.User()
user.email = fake.email()
user.password = generate_password_hash('changeme')
user.tagline = fake.text(100)
user.summary = fake.text(300)
user.name = fake.name()
user.role_id = 1 if random.randrange(0, 100) > 90 else 0
try:
db.session.add(user)
db.session.commit()
resume = generateResume(user.id)
test_id = makeABTest(user.id)
makeRecipes(test_id, resume)
if user.role_id == 1:
makeJobPosting(user.id)
s += 1
except Exception as err_msg:
print 'Error occured: %s' % err_msg
e += 1
db.session.rollback()
msg = str(s) + ' user records created, ' + str(e) + ' errors.'
return msg
#presuming there's more than 15 records existing
def generateResume(user_id):
text = fake.text(300) + '\n' + fake.text(300) + '\n' + fake.text(300)
resume = models.Resume()
resume.user_id = user_id
resume.resume = text
try:
db.session.add(resume)
db.session.commit()
except:
db.session.rollback()
return text
def makeABTest(user_id):
test_name = fake.text(100)
hypothesis = fake.text(100)
test = models.ABTests()
test.test_name = test_name
test.hypothesis = hypothesis
test.user_id = user_id
try:
db.session.add(test)
db.session.commit()
except:
db.session.rollback()
return test.id
def makeRecipes(test_id, resume):
for x in range(1, 3):
test_recipe = 'Control' if x == 1 else 'Recipe B'
recipes = models.Recipes()
recipes.test_id = test_id
recipes.recipe = test_recipe
recipe_b = fake.text(300) + '\n' + fake.text(300) + '\n' + fake.text(300)
version = resume if test_recipe == 'Control' else recipe_b
recipes.version = version
try:
db.session.add(recipes)
db.session.commit()
except:
db.session.rollback()
def makeJobPosting(poster_id):
job = models.Jobs()
job.title = fake.text(50)
job.description = fake.text(500)
job.skills = fake.text(50)
job.url = fake.url()
job.poster_id = poster_id
try:
db.session.add(job)
db.session.commit()
except:
db.session.rollback()