-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_gen.py
79 lines (59 loc) · 1.83 KB
/
data_gen.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
import random
import datetime
import json
quantities = [0, 100, 200, 300] # quantities describe discrete product amounts
def generate_prices(m: int):
l = []
for i in range(m):
l.append(random.randint(5, 29))
return f'"prices": {json.dumps(l)},'
def generate_quantities(m: int):
l = []
for i in range(m):
l.append(quantities[random.randint(0, 3)])
return f'"quantities": {json.dumps(l)},'
def generate_exp_dates(m: int):
l = []
for i in range(m):
l.append(random.randint(1, 6))
return f'"dates": {json.dumps(l)},'
def generate_recipes(n: int, m: int):
l = []
for i in range(n):
nl = []
for j in range(m):
aux = random.randint(-50, 10)
aux = 0 if aux<0 else aux
nl.append(aux)
l.append(nl)
return f'"recipes": {json.dumps(l)},'
def generate_times(n: int):
l = []
for i in range(n):
l.append(random.randint(5, 31))
return f'"times": {json.dumps(l)}'
def save_file(json_obj):
date_for_filename = str(datetime.datetime.utcnow())
date_for_filename = date_for_filename.split(' ')[1]
date_for_filename = date_for_filename.split('.')[0]
date_for_filename = date_for_filename.replace(':', '_')
with open(f'generated_data/{date_for_filename}.json', 'w') as file:
file.write(json_obj)
def generate_model():
random.seed()
n = 500000
m = 100
money = 1000
json_object = '{' \
+ f'"n": {n},' \
+ f'"m": {m},' \
+ f'"money": {money},' \
+ generate_prices(m) \
+ generate_quantities(m) \
+ generate_exp_dates(m) \
+ generate_recipes(n, m) \
+ generate_times(n) \
+ '}'
save_file(json_object)
if __name__ == "__main__":
generate_model()