-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.py
More file actions
125 lines (109 loc) · 3.93 KB
/
generate_data.py
File metadata and controls
125 lines (109 loc) · 3.93 KB
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
import uuid
import random
from faker import Faker
from datetime import datetime, timedelta
fake = Faker()
def uuid_bin():
return uuid.uuid4().bytes
def now():
return datetime.now()
def random_time():
return (datetime.min + timedelta(seconds=random.randint(0, 86400))).time()
def generate_mock_data(count: int):
companies, admins, items, spaces = [], [], [], []
devices, users, usage_histories, rentals, user_auth_codes = [], [], [], [], []
for _ in range(count):
companies.append({
'id': uuid_bin(),
'name': fake.company(),
'created_at': now()
})
for _ in range(count):
admins.append({
'id': uuid_bin(),
'company_id': random.choice(companies)['id'],
'email': fake.email(),
'password': fake.password(),
'phone': fake.numerify('010-####-####'),
'role': random.choice(['ROLE_ADMIN', 'ROLE_DEVICE']),
'status': random.choice(['AVAILABLE', 'NEED_COMPANY_APPROVE'])
})
for _ in range(count):
total_qty = random.randint(5, 20)
items.append({
'id': uuid_bin(),
'company_id': random.choice(companies)['id'],
'name': fake.word()[:10],
'total_quantity': total_qty,
'available_quantity': random.randint(0, total_qty),
'status': random.choice(['AVAILABLE', 'NOT_AVAILABLE'])
})
for _ in range(count):
spaces.append({
'id': uuid_bin(),
'company_id': random.choice(companies)['id'],
'name': fake.word()[:50],
'start_at': random_time(),
'end_at': random_time()
})
for _ in range(count):
unique_space_ids = random.sample([s['id'] for s in spaces], k=min(count, len(spaces)))
devices = []
for space_id in unique_space_ids:
devices.append({
'id': uuid_bin(),
'company_id': random.choice(companies)['id'],
'role': random.choice(['ROLE_ADMIN', 'ROLE_DEVICE']),
'created_at': now()
})
for _ in range(count):
users.append({
'id': uuid_bin(),
'company_id': random.choice(companies)['id'],
'name': fake.first_name()[:20],
'phone': fake.numerify('010-####-####'),
'created_at': now(),
'updated_at': now(),
'age': random.choice(['ADULT', 'ELEMENTARY', 'HIGH', 'MIDDLE', 'OUT_OF_SCHOOL_YOUTH']),
'sex': random.choice(['FEMALE', 'MALE'])
})
for _ in range(count):
usage_histories.append({
'id': uuid_bin(),
'user_id': random.choice(users)['id'],
'space_id': random.choice(spaces)['id'],
'start_at': now(),
'end_at': now() + timedelta(hours=random.randint(1, 3))
})
for _ in range(count):
usage = random.choice(usage_histories)
item = random.choice(items)
qty = random.randint(1, item['total_quantity'])
rentals.append({
'id': uuid_bin(),
'item_id': item['id'],
'usage_id': usage['id'],
'quantity': qty,
'returned_quantity': random.randint(0, qty),
'borrowed_at': usage['start_at'],
'returned_at': usage['end_at'] if random.random() > 0.3 else None
})
for _ in range(count):
user_auth_codes.append({
'id': uuid_bin(),
'auth_code': f"{random.randint(100000, 999999)}",
'created_at': now(),
'expired_at': now() + timedelta(minutes=5),
'phone': fake.numerify('010-####-####')
})
return {
'company': companies,
'admin': admins,
'item': items,
'space': spaces,
'device': devices,
'user': users,
'usage_history': usage_histories,
'rental': rentals,
'user_auth_code': user_auth_codes
}