-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorder_dummy.py
More file actions
61 lines (44 loc) · 1.42 KB
/
order_dummy.py
File metadata and controls
61 lines (44 loc) · 1.42 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
from faker import Faker
import pandas as pd
import numpy as np
import random
import config
from sqlalchemy import create_engine
import sqlalchemy as db
fake = Faker('ko_KR') # locale 정보 설정
Faker.seed() # 초기 seed 설정
num = 1000000
# pk
# order_id = [i for i in range(1, num+1)]
order_id = [i for i in range(1, num+1)]
# 주문 수량
order_num = [int(abs(np.random.normal(0,1)*2)+1) for i in range(num)]
# 주문 상태
order_status = ["주문완료"] * num
# 주문일자
order_time = [fake.date_time_between(start_date = '-3y', end_date = 'now') for i in range(num)]
# 상품 번호
productNum = 1000000
product_id = [random.randint(1,productNum) for i in range(num)]
# 유저 번호
userNum = 200000
user_id = [random.randint(1,userNum) for i in range(num)]
df = pd.DataFrame()
df['order_id'] = order_id
df['order_num'] = order_num
df['order_status'] = order_status
df['order_time'] = order_time
df['product_id'] = product_id
df['user_id'] = user_id
records = df.to_dict(orient='records')
port = config.port
username = config.username
password = config.password
host = config.host
dbname = config.dbname
engine = create_engine(f"mysql://{username}:{password}@{host}:{port}/{dbname}?charset=utf8mb4")
with engine.connect() as conn:
metadata = db.MetaData()
table = db.Table('orders', metadata, autoload=True, autoload_with=engine)
query = db.insert(table).values(records)
result_proxy = conn.execute(query)