-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-generator-csv.py
142 lines (119 loc) · 4.97 KB
/
data-generator-csv.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import random
import json
import time
from datetime import datetime
from faker import Faker
rep_count = 16
class DataGeneratorFactory(object):
def factory(type_str):
if type_str == 'customer':
return CustomerDataGenerator()
elif type_str == 'part_dashboard':
return ManufacturingDataGenerator()
elif type_str == 'transactions':
return POSDataGenerator()
elif type_str == 'transactions_customer':
return POSCustomerDataGenerator()
elif type_str == 'rep':
return SalesRepDataGenerator()
factory = staticmethod(factory)
class DataGenerator(object):
def __init__(self):
pass
def gen_row(self):
pass
class CustomerDataGenerator(DataGenerator):
fake = None
def __init__(self):
self.fake = Faker()
def gen_row(self):
row = {}
row['cust_contact_name'] = self.fake.name()
row['cust_ssn'] = self.fake.ssn().replace('-','')
row['cust_date_reg'] = str(self.fake
.date_this_decade(before_today=True, after_today=False))
row['cust_is_active'] = 1 if random.random() > .2 else 0
row['cust_address'] = self.fake.address().replace('\n',', ')
row['cust_company_name'] = self.fake.company()
return row
class SalesRepDataGenerator(DataGenerator):
fake = None
reps_left = rep_count
def __init__(self):
self.fake = Faker()
def gen_row(self):
row = {}
row['id'] = self.reps_left
self.reps_left -= 1
if self.reps_left == -1:
return None
row['name'] = self.fake.name()
row['address'] = self.fake.address().replace('\n',', ')
row['salary'] = random.randrange(5,11)*10000
row['quota'] = random.randrange(5,11)*100000
row['start_date'] = str(self.fake
.date_this_decade(before_today=True, after_today=False))
return row
class POSDataGenerator(DataGenerator):
discounts = [5,10,15,20,25]
def gen_row(self):
row = {}
row['trxn_time'] = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
row['cust_id'] = random.randrange(1101)%1000+1
row['trxn_amt'] = random.randrange(201)+round(random.random(), 2)
row['discount_amt'] = self.discounts[random.randrange(5)]
row['store_id'] = random.randrange(101)
row['rep_id'] = random.randrange(rep_count)
row['part_sku'] = chr(random.randint(65,91))+'-'+str(random.randint(800,1001))
row['qty'] = random.randrange(11)
time.sleep(1)
return row
class POSCustomerDataGenerator(POSDataGenerator):
cust_gen = CustomerDataGenerator()
def gen_row(self):
row = self.cust_gen.gen_row()
row.update(super(POSCustomerDataGenerator, self).gen_row())
row.pop('cust_id')
return row
class ManufacturingDataGenerator(DataGenerator):
name_to_notes = [
{'name':'rearbumper','notes':'Rear bumper, bent on edges'},
{'name':'frontleftdoor','notes':'driver door'},
{'name':'frontrightdoor','notes':'passenger door'},
{'name':'backleftdoor','notes':'rear driver side door'},
{'name':'backrightdoor','notes':'rear passenger side door'},
{'name':'hood','notes':'covering for the engine'},
{'name':'controlarm','notes':'support for wheel'},
{'name':'headgasket','notes':'sensitive part, needs extensive testing'},
{'name':'piston','notes':'dynamic part'},
{'name':'exhaustpipe','notes':'need to test additionally for corrosion from exhaust'},
{'name':'catalyticconverter','notes':'compliance requirements'}
]
def __init__(self):
for item in self.name_to_notes:
item['vibr_dist_center'] = random.uniform(.75, .95)
item['heat_dist_center'] = random.uniform(.75, .95)
item['vibr_thrs'] = random.uniform(0.1,0.2)
item['heat_thrs'] = random.uniform(0.05,0.15)
def gen_row(self):
DataGenerator.gen_row(self)
row = {}
name_obj = self.name_to_notes[random.randrange(len(self.name_to_notes))]
row['shortname'] = name_obj['name']
row['time'] = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
row['notes'] = name_obj['notes']
row['part_loc'] = random.randrange(1,10)
row['vibr_tolr_pct'] = random.gauss(name_obj['vibr_dist_center'], name_obj['vibr_thrs']*1.5)
row['vibr_tolr_thrs'] = name_obj['vibr_dist_center']-name_obj['vibr_thrs']
row['heat_tolr_pct'] = random.gauss(name_obj['heat_dist_center'], name_obj['heat_thrs']*1.5)
row['heat_tolr_thrs'] = name_obj['heat_dist_center']-name_obj['heat_thrs']
row['qty'] = random.randrange(1,5)
return row
z = 0
if __name__ == '__main__':
d = POSDataGenerator()
with open ('data.json','w') as outfile:
for i in range(1,200000):
record = d.gen_row()
json.dumps(record)
print(record)